[dpdk-dev] [PATCH v2] eal/ppc64: improve rte_rdtsc with ppc_get_timebase

David Marchand david.marchand at redhat.com
Wed Feb 5 22:29:22 CET 2020

On Fri, Jan 31, 2020 at 11:04 PM Thinh Tran <thinhtr at linux.vnet.ibm.com> wrote:
>   __ppc_get_timebase() is GNU extension and is more efficient

The commit title and log are quite short and give little idea on what
this is about.

I had a look at this glibc helper:

/* Read the Time Base Register.   */
static __inline__ uint64_t
__ppc_get_timebase (void)
#if __GNUC_PREREQ (4, 8)
  return __builtin_ppc_get_timebase ();
# ifdef __powerpc64__
  uint64_t __tb;
  /* "volatile" is necessary here, because the user expects this assembly
     isn't moved after an optimization.  */
  __asm__ volatile ("mfspr %0, 268" : "=r" (__tb));
  return __tb;
# else  /* not __powerpc64__ */
  uint32_t __tbu, __tbl, __tmp; \
  __asm__ volatile ("0:\n\t"
                    "mftbu %0\n\t"
                    "mftbl %1\n\t"
                    "mftbu %2\n\t"
                    "cmpw %0, %2\n\t"
                    "bne- 0b"
                    : "=r" (__tbu), "=r" (__tbl), "=r" (__tmp));
  return (((uint64_t) __tbu << 32) | __tbl);
# endif  /* not __powerpc64__ */

The last block is exactly the code we had in dpdk.
So I suppose we are trying to use mfspr for register 268 which seems
linked to timebase (looking at the linux kernel sources).

Please, confirm this is an enhancement (and how this improves current
ppc support).

David Marchand

More information about the dev mailing list