]> git.droids-corp.org - dpdk.git/commitdiff
eal/ppc: fix compilation for musl
authorDuncan Bellamy <dunk@denkimushi.com>
Sat, 14 May 2022 07:14:35 +0000 (08:14 +0100)
committerDavid Marchand <david.marchand@redhat.com>
Tue, 7 Jun 2022 11:33:14 +0000 (13:33 +0200)
musl lacks __ppc_get_timebase() but has __builtin_ppc_get_timebase()

Signed-off-by: Duncan Bellamy <dunk@denkimushi.com>
Reviewed-by: David Christensen <drc@linux.vnet.ibm.com>
lib/eal/ppc/include/rte_cycles.h
lib/eal/ppc/rte_cycles.c

index 5585f9273c78b5e9633dc7f407c10ec18ae5251d..666fc9b0bf7ee6162c4b24646d46b2d61522abd0 100644 (file)
 extern "C" {
 #endif
 
+#include <features.h>
+#ifdef __GLIBC__
 #include <sys/platform/ppc.h>
+#endif
 
 #include "generic/rte_cycles.h"
 
@@ -26,7 +29,11 @@ extern "C" {
 static inline uint64_t
 rte_rdtsc(void)
 {
+#ifdef __GLIBC__
        return __ppc_get_timebase();
+#else
+       return __builtin_ppc_get_timebase();
+#endif
 }
 
 static inline uint64_t
index 3180adb0ff2531c36b9bbdcff6c746e49e6017de..cd4bdff8b8b123c14804b1522538602126c8cddb 100644 (file)
@@ -2,12 +2,51 @@
  * Copyright (C) IBM Corporation 2019.
  */
 
+#include <features.h>
+#ifdef __GLIBC__
 #include <sys/platform/ppc.h>
+#elif RTE_EXEC_ENV_LINUX
+#include <string.h>
+#include <stdio.h>
+#endif
 
 #include "eal_private.h"
 
 uint64_t
 get_tsc_freq_arch(void)
 {
+#ifdef __GLIBC__
        return __ppc_get_timebase_freq();
+#elif RTE_EXEC_ENV_LINUX
+       static unsigned long base;
+       char buf[512];
+       ssize_t nr;
+       FILE *f;
+
+       if (base != 0)
+               goto out;
+
+       f = fopen("/proc/cpuinfo", "rb");
+       if (f == NULL)
+               goto out;
+
+       while (fgets(buf, sizeof(buf), f) != NULL) {
+               char *ret = strstr(buf, "timebase");
+
+               if (ret == NULL)
+                       continue;
+               ret += sizeof("timebase") - 1;
+               ret = strchr(ret, ':');
+               if (ret == NULL)
+                       continue;
+               base = strtoul(ret + 1, NULL, 10);
+               break;
+       }
+       fclose(f);
+out:
+       return (uint64_t) base;
+#else
+       return 0;
+#endif
+
 }