> From: Thomas Monjalon [mailto:tho...@monjalon.net]
> Sent: Thursday, 12 October 2023 01.44
> 
> 04/09/2023 10:43, Morten Brørup:
> >  /** Force minimum cache line alignment. */
> >  #define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE)
> >
> > +#define _RTE_CACHE_GUARD_HELPER2(unique) \
> > +           char cache_guard_ ## unique[RTE_CACHE_LINE_SIZE *
> RTE_CACHE_GUARD_LINES] \
> > +           __rte_cache_aligned
> > +#define _RTE_CACHE_GUARD_HELPER1(unique) _RTE_CACHE_GUARD_HELPER2(unique)
> 
> What is the reason for this intermediate helper macro?
> 
> > +/**
> > + * Empty cache lines, to guard against false sharing-like effects
> > + * on systems with a next-N-lines hardware prefetcher.
> > + *
> > + * Use as spacing between data accessed by different lcores,
> > + * to prevent cache thrashing on hardware with speculative prefetching.
> > + */
> > +#define RTE_CACHE_GUARD _RTE_CACHE_GUARD_HELPER1(__COUNTER__)

HELPER1 is required to convert __COUNTER__ to a number before HELPER2 
concatenates it to cache_guard_.

If using HELPER2 directly,

#define RTE_CACHE_GUARD _RTE_CACHE_GUARD_HELPER2(__COUNTER__)

would expand to:

char cache_guard_ ## __COUNTER__ [RTE_CACHE_LINE_SIZE * RTE_CACHE_GUARD_LINES]
        __rte_cache_aligned

Which is not unique, and would prevent using RTE_CACHE_GUARD multiple times in 
the same structure.

Reply via email to