DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] lib/eal/ppc fix compilation for musl
@ 2022-05-02 11:51 Duncan Bellamy
  0 siblings, 0 replies; only message in thread
From: Duncan Bellamy @ 2022-05-02 11:51 UTC (permalink / raw)
  To: dev; +Cc: Duncan Bellamy

musl lacks __ppc_get_timebase() but has __builtin_ppc_get_timebase()

the __ppc_get_timebase_freq() is taken from:
https://git.alpinelinux.org/aports/commit/?id=06b03f70fb94972286c0c9f6278df89e53903833

Signed-off-by: Duncan Bellamy <dunk@denkimushi.com>
---
 lib/eal/ppc/include/rte_cycles.h |  6 ++++++
 lib/eal/ppc/rte_cycles.c         | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/lib/eal/ppc/include/rte_cycles.h b/lib/eal/ppc/include/rte_cycles.h
index 5585f9273c..ac67ed142c 100644
--- a/lib/eal/ppc/include/rte_cycles.h
+++ b/lib/eal/ppc/include/rte_cycles.h
@@ -10,7 +10,9 @@
 extern "C" {
 #endif
 
+#ifdef __GLIBC__
 #include <sys/platform/ppc.h>
+#endif
 
 #include "generic/rte_cycles.h"
 
@@ -26,7 +28,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
diff --git a/lib/eal/ppc/rte_cycles.c b/lib/eal/ppc/rte_cycles.c
index 3180adb0ff..06aab9a0d4 100644
--- a/lib/eal/ppc/rte_cycles.c
+++ b/lib/eal/ppc/rte_cycles.c
@@ -2,12 +2,44 @@
  * Copyright (C) IBM Corporation 2019.
  */
 
+#ifdef __GLIBC__
 #include <sys/platform/ppc.h>
+#else
+#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();
+#else
+	static uint64_t base;
+	if (!base) {
+		FILE *f = fopen("/proc/cpuinfo", "rb");
+		if (f) {
+			ssize_t nr;
+			/* virtually always big enough to hold the line */
+			char buf[512];
+			while (fgets(buf, sizeof(buf), f)) {
+				char *ret = strstr(buf, "timebase");
+				if (!ret) {
+					continue;
+				}
+				ret += sizeof("timebase") - 1;
+				ret = strchr(ret, ':');
+				if (!ret) {
+					continue;
+				}
+				base = strtoul(ret + 1, 0, 10);
+				break;
+			}
+			fclose(f);
+		}
+	}
+	return base;;
+#endif
 }
-- 
2.32.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-02 11:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-02 11:51 [PATCH] lib/eal/ppc fix compilation for musl Duncan Bellamy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).