[dpdk-dev] [PATCH v5 2/4] examples: add lthread subsystem for performance-thread
Betts, Ian
ian.betts at intel.com
Thu Dec 3 18:15:53 CET 2015
On Thu, Dec 03, 2015 at 08:31:39AM -0800, Stephen Hemminger wrote:
> On Thu, 3 Dec 2015 09:28:23 +0000
> ibetts <ian.betts at intel.com> wrote:
>
> > +/*
> > + * Atomically set a value and return the old value */ static
> > +inline uint64_t atomic64_xchg(uint64_t *ptr, uint64_t val)
> > +__attribute__ ((always_inline)); static inline uint64_t
> > +atomic64_xchg(uint64_t *ptr, uint64_t val)
>
> You don't need a forward declaration for this.
> Instead do:
>
> static inline uint64_t __attribute__((always_inline))
> atomic_xchg64(uint64_t *ptr, uint64_t val)
>
> Really should be in rte_atomic.h as a primitive and the assembly macro
> is missing change to ptr so Gcc might optmize it away.
>
> Something like this mayb?
>
> static inline uint64_t __attribute__ ((always_inline));
> rte_atomic64_xchg(uint64_t *ptr, uint64_t val) {
> asm volatile (
> MPLOCKED
> "xchgq %[ptr],%[val];"
> : [val] "=r" (val)
> [ptr] "=m" (*ptr)
> : [ptr] "m" (*ptr),
> "a" (val)
> : "memory");
>
> return val;
> }
>-----Original Message-----
>From: Richardson, Bruce
>Sent: Thursday, December 3, 2015 4:46 PM
>To: Stephen Hemminger
>Cc: Betts, Ian; dev at dpdk.org
>Subject: Re: [dpdk-dev] [PATCH v5 2/4] examples: add lthread subsystem for performance-thread
>Rather than using assembly, I believe the gcc builtin __sync_lock_test_and_set is actually an xchg op, so can be used here.
Thanks for the suggestion Bruce, I had looked for a builin I must have missed it.
I just tested it and its fine.
/Bruce
More information about the dev
mailing list