Skip to contentSkip to conversation

lib/eal/ppc fix compilation for musl

PATCH Superseded Duncan Bellamy 3 participants 15 messages May 2, 2022 – Jun 1, 2022 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 1/1 lib/eal/ppc fix compilation for musl

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

---
 lib/eal/ppc/include/rte_cycles.h |  6 ++++++
 lib/eal/ppc/rte_cycles.c         | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)
lib/eal/ppc/include/rte_cycles.h +6 -0
index 5585f9273c..98ffbd2592 100644
@@ -10,7 +10,9 @@
 extern "C" {
 #endif
 
+#if defined(__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)
 {
+#if defined(__GLIBC__)
 	return __ppc_get_timebase();
+#else
+	return __builtin_ppc_get_timebase();
+#endif
 }
 
 static inline uint64_t
lib/eal/ppc/rte_cycles.c +32 -0
index 3180adb0ff..154eba722c 100644
@@ -2,12 +2,44 @@
  * Copyright (C) IBM Corporation 2019.
  */
 
+#if defined(__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)
 {
+#if defined(__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
 }
Signature · 1 line
2.32.0
#2 lore raw
Quoted 17 lines · 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

---
 lib/eal/ppc/include/rte_cycles.h |  6 ++++++
 lib/eal/ppc/rte_cycles.c         | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)
lib/eal/ppc/include/rte_cycles.h +0 -0
index 5585f9273c..98ffbd2592 100644

lib/eal/ppc/include/rte_cycles.h line 13

Quoted 4 lines
lib/eal/ppc/include/rte_cycles.h +1 -0
@@ -10,7 +10,9 @@
 extern "C" {
 #endif
 
+#if defined(__GLIBC__)

features.h should be included before looking for __GLIBC__.

Signature · 1 line
David Marchand
author
#3 lore raw
Quoted 25 lines · David Marchand
Quoted 20 lines · 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

---
lib/eal/ppc/include/rte_cycles.h | 6 ++++++
lib/eal/ppc/rte_cycles.c | 32 ++++++++++++++++++++++++++++++++

2 files changed, 38 insertions(+)
lib/eal/ppc/include/rte_cycles.h +0 -0
index 5585f9273c..98ffbd2592 100644
@@ -10,7 +10,9 @@
 extern "C" {
 #endif
 
Quoted 8 lines

lib/eal/ppc/include/rte_cycles.h line 13

Quoted 1 line
lib/eal/ppc/include/rte_cycles.h +1 -0
+#if defined(__GLIBC__)

features.h should be included before looking for __GLIBC__.

Signature · 1 line
David Marchand

Okay, wondered why it wasn’t working

#4 lore raw
In reply to Duncan Bellamy
Quoted 53 lines · 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

---
  lib/eal/ppc/include/rte_cycles.h |  6 ++++++
  lib/eal/ppc/rte_cycles.c         | 32 ++++++++++++++++++++++++++++++++
  2 files changed, 38 insertions(+)
lib/eal/ppc/include/rte_cycles.h +6 -0
index 5585f9273c..98ffbd2592 100644
@@ -10,7 +10,9 @@
  extern "C" {
  #endif
 
+#if defined(__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)
  {
+#if defined(__GLIBC__)
  	return __ppc_get_timebase();
+#else
+	return __builtin_ppc_get_timebase();
+#endif
  }
 
  static inline uint64_t
lib/eal/ppc/rte_cycles.c +5 -0
index 3180adb0ff..154eba722c 100644
@@ -2,12 +2,44 @@
   * Copyright (C) IBM Corporation 2019.
   */
 
+#if defined(__GLIBC__)
  #include <sys/platform/ppc.h>
+#else
+#include <string.h>
+#include <stdio.h>
+#endif
 
  #include "eal_private.h"

lib/eal/ppc/rte_cycles.c line 22

Quoted 10 lines
lib/eal/ppc/rte_cycles.c +5 -0
 
  uint64_t
  get_tsc_freq_arch(void)
  {
+#if defined(__GLIBC__)
  	return __ppc_get_timebase_freq();
+#else
+	static uint64_t base;
+	if (!base) {
+		FILE *f = fopen("/proc/cpuinfo", "rb");

Code is valid but Linux specific. Access to /proc/cpuinfo needs to live in lib/eal/linux/eal_timer.c, surrounded by '#ifndef RTE_ARCH_PPC_64/#endif', with stubs for FreeBSD/Windows.

Dave

author
#5 lore raw
Quoted 55 lines · David Christensen



Quoted 49 lines · 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

---
 lib/eal/ppc/include/rte_cycles.h |  6 ++++++
 lib/eal/ppc/rte_cycles.c         | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)
lib/eal/ppc/include/rte_cycles.h +6 -0
index 5585f9273c..98ffbd2592 100644
@@ -10,7 +10,9 @@
 extern "C" {
 #endif
+#if defined(__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)
 {
+#if defined(__GLIBC__)
     return __ppc_get_timebase();
+#else
+    return __builtin_ppc_get_timebase();
+#endif
 }
 static inline uint64_t
lib/eal/ppc/rte_cycles.c +6 -0
index 3180adb0ff..154eba722c 100644
@@ -2,12 +2,44 @@
  * Copyright (C) IBM Corporation 2019.
  */
+#if defined(__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)
 {
+#if defined(__GLIBC__)
Quoted 8 lines

lib/eal/ppc/rte_cycles.c line 22

Quoted 5 lines
lib/eal/ppc/rte_cycles.c +4 -0
     return __ppc_get_timebase_freq();
+#else
+    static uint64_t base;
+    if (!base) {
+        FILE *f = fopen("/proc/cpuinfo", "rb");

Code is valid but Linux specific. Access to /proc/cpuinfo needs to live in lib/eal/linux/eal_timer.c, surrounded by '#ifndef RTE_ARCH_PPC_64/#endif', with stubs for FreeBSD/Windows. Dave

Okay will move, will change glibc check back to ifdef as well.

Duncan

#6 lore raw

PATCH v3 1/1 lib/eal/ppc fix compilation for musl

In reply to 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

---
 lib/eal/common/eal_private.h     |  7 ++++++
 lib/eal/linux/eal_timer.c        | 39 ++++++++++++++++++++++++++++++++
 lib/eal/ppc/include/rte_cycles.h |  7 ++++++
 lib/eal/ppc/rte_cycles.c         | 10 ++++++++
 4 files changed, 63 insertions(+)
lib/eal/common/eal_private.h +7 -0
index 44d14241f0..9ac1949e1c 100644
@@ -743,4 +743,11 @@ int eal_asprintf(char **buffer, const char *format, ...);
 		eal_asprintf(buffer, format, ##__VA_ARGS__)
 #endif
 
+/**
+ * Function for systems with no __ppc_get_timebase_freq function.
+ */
+#ifndef RTE_ARCH_PPC_64
+uint64_t no_ppc_get_timebase_freq(void);
+#endif
+
 #endif /* _EAL_PRIVATE_H_ */
lib/eal/linux/eal_timer.c +39 -0
index 620baf038d..23e06d92c1 100644
@@ -5,6 +5,8 @@
 
 #include <stdio.h>
 #include <stdint.h>
+#include <string.h>
+#include <features.h>
 
 #include <rte_common.h>
 #include <rte_cycles.h>
@@ -222,3 +224,40 @@ rte_eal_timer_init(void)
 	set_tsc_freq();
 	return 0;
 }
+
+#ifndef RTE_ARCH_PPC_64
+uint64_t
+no_ppc_get_timebase_freq(void)
+{
+	static uint64_t base;
+	#if defined(__LINUX__)
+	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);
+		}
+	}
+	#elif defined(_WIN32) || defined(_WIN64)
+	// windows code here
+	#elif defined(RTE_EXEC_ENV_FREEBSD)
+	// freebsd code here
+	#endif
+	return base;
+}
+#endif
lib/eal/ppc/include/rte_cycles.h +7 -0
index 5585f9273c..666fc9b0bf 100644
@@ -10,7 +10,10 @@
 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
lib/eal/ppc/rte_cycles.c +10 -0
index 3180adb0ff..b69fc701a6 100644
@@ -2,12 +2,22 @@
  * Copyright (C) IBM Corporation 2019.
  */
 
+#include <features.h>
+#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
+	return no_ppc_get_timebase_freq();
+#endif
 }
Signature · 1 line
2.32.0
#7 lore raw

PATCH v4 1/1 lib/eal/ppc fix compilation for musl

In reply to 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

---
 lib/eal/common/eal_private.h     |  7 ++++++
 lib/eal/linux/eal_timer.c        | 39 ++++++++++++++++++++++++++++++++
 lib/eal/ppc/include/rte_cycles.h |  7 ++++++
 lib/eal/ppc/rte_cycles.c         | 10 ++++++++
 4 files changed, 63 insertions(+)
lib/eal/common/eal_private.h +7 -0
index 44d14241f0..9ac1949e1c 100644
@@ -743,4 +743,11 @@ int eal_asprintf(char **buffer, const char *format, ...);
 		eal_asprintf(buffer, format, ##__VA_ARGS__)
 #endif
 
+/**
+ * Function for systems with no __ppc_get_timebase_freq function.
+ */
+#ifndef RTE_ARCH_PPC_64
+uint64_t no_ppc_get_timebase_freq(void);
+#endif
+
 #endif /* _EAL_PRIVATE_H_ */
lib/eal/linux/eal_timer.c +39 -0
index 620baf038d..89cadb9cfb 100644
@@ -5,6 +5,8 @@
 
 #include <stdio.h>
 #include <stdint.h>
+#include <string.h>
+#include <features.h>
 
 #include <rte_common.h>
 #include <rte_cycles.h>
@@ -222,3 +224,40 @@ rte_eal_timer_init(void)
 	set_tsc_freq();
 	return 0;
 }
+
+#ifndef RTE_ARCH_PPC_64
+uint64_t
+no_ppc_get_timebase_freq(void)
+{
+	static uint64_t base;
+	#if defined(__LINUX__)
+	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);
+		}
+	}
+	#elif defined(_WIN32) || defined(_WIN64)
+	/* windows code here */
+	#elif defined(RTE_EXEC_ENV_FREEBSD)
+	/* freebsd code here */
+	#endif
+	return base;
+}
+#endif
lib/eal/ppc/include/rte_cycles.h +7 -0
index 5585f9273c..666fc9b0bf 100644
@@ -10,7 +10,10 @@
 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
lib/eal/ppc/rte_cycles.c +10 -0
index 3180adb0ff..b69fc701a6 100644
@@ -2,12 +2,22 @@
  * Copyright (C) IBM Corporation 2019.
  */
 
+#include <features.h>
+#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
+	return no_ppc_get_timebase_freq();
+#endif
 }
Signature · 1 line
2.32.0
#8 lore raw

PATCH v5 1/1 lib/eal/ppc fix compilation for musl

In reply to 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

---
 lib/eal/common/eal_private.h     |  7 +++++++
 lib/eal/linux/eal_timer.c        | 35 ++++++++++++++++++++++++++++++++
 lib/eal/ppc/include/rte_cycles.h |  7 +++++++
 lib/eal/ppc/rte_cycles.c         | 10 +++++++++
 4 files changed, 59 insertions(+)
lib/eal/common/eal_private.h +7 -0
index 44d14241f0..9ac1949e1c 100644
@@ -743,4 +743,11 @@ int eal_asprintf(char **buffer, const char *format, ...);
 		eal_asprintf(buffer, format, ##__VA_ARGS__)
 #endif
 
+/**
+ * Function for systems with no __ppc_get_timebase_freq function.
+ */
+#ifndef RTE_ARCH_PPC_64
+uint64_t no_ppc_get_timebase_freq(void);
+#endif
+
 #endif /* _EAL_PRIVATE_H_ */
lib/eal/linux/eal_timer.c +35 -0
index 620baf038d..c5436ed1c5 100644
@@ -5,6 +5,8 @@
 
 #include <stdio.h>
 #include <stdint.h>
+#include <string.h>
+#include <features.h>
 
 #include <rte_common.h>
 #include <rte_cycles.h>
@@ -222,3 +224,36 @@ rte_eal_timer_init(void)
 	set_tsc_freq();
 	return 0;
 }
+
+#ifndef RTE_ARCH_PPC_64
+uint64_t
+no_ppc_get_timebase_freq(void)
+{
+	static uint64_t base;
+	#if defined(__LINUX__)
+	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);
+		}
+	}
+	#elif defined(_WIN32) || defined(_WIN64)
+	/* windows code here */
+	#elif defined(RTE_EXEC_ENV_FREEBSD)
+	/* freebsd code here */
+	#endif
+	return base;
+}
+#endif
lib/eal/ppc/include/rte_cycles.h +7 -0
index 5585f9273c..666fc9b0bf 100644
@@ -10,7 +10,10 @@
 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
lib/eal/ppc/rte_cycles.c +10 -0
index 3180adb0ff..b69fc701a6 100644
@@ -2,12 +2,22 @@
  * Copyright (C) IBM Corporation 2019.
  */
 
+#include <features.h>
+#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
+	return no_ppc_get_timebase_freq();
+#endif
 }
Signature · 1 line
2.32.0
#9 lore raw

PATCH v6 1/1 lib/eal/ppc fix compilation for musl

In reply to 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

---
 lib/eal/common/eal_private.h     |  7 ++++++
 lib/eal/linux/eal_timer.c        | 37 ++++++++++++++++++++++++++++++++
 lib/eal/ppc/include/rte_cycles.h |  7 ++++++
 lib/eal/ppc/rte_cycles.c         | 10 +++++++++
 4 files changed, 61 insertions(+)
lib/eal/common/eal_private.h +7 -0
index 44d14241f0..9ac1949e1c 100644
@@ -743,4 +743,11 @@ int eal_asprintf(char **buffer, const char *format, ...);
 		eal_asprintf(buffer, format, ##__VA_ARGS__)
 #endif
 
+/**
+ * Function for systems with no __ppc_get_timebase_freq function.
+ */
+#ifndef RTE_ARCH_PPC_64
+uint64_t no_ppc_get_timebase_freq(void);
+#endif
+
 #endif /* _EAL_PRIVATE_H_ */
lib/eal/linux/eal_timer.c +37 -0
index 620baf038d..4f46f5411d 100644
@@ -5,6 +5,8 @@
 
 #include <stdio.h>
 #include <stdint.h>
+#include <string.h>
+#include <features.h>
 
 #include <rte_common.h>
 #include <rte_cycles.h>
@@ -222,3 +224,38 @@ rte_eal_timer_init(void)
 	set_tsc_freq();
 	return 0;
 }
+
+#ifndef RTE_ARCH_PPC_64
+uint64_t
+no_ppc_get_timebase_freq(void)
+{
+	static uint64_t base;
+	#if defined(__LINUX__)
+	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);
+		}
+	}
+	#elif defined(_WIN32) || defined(_WIN64)
+	/* windows code here */
+	#elif defined(RTE_EXEC_ENV_FREEBSD)
+	/* freebsd code here */
+	#endif
+	return base;
+}
+#endif
lib/eal/ppc/include/rte_cycles.h +7 -0
index 5585f9273c..666fc9b0bf 100644
@@ -10,7 +10,10 @@
 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
lib/eal/ppc/rte_cycles.c +10 -0
index 3180adb0ff..b69fc701a6 100644
@@ -2,12 +2,22 @@
  * Copyright (C) IBM Corporation 2019.
  */
 
+#include <features.h>
+#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
+	return no_ppc_get_timebase_freq();
+#endif
 }
Signature · 1 line
2.32.0
#10 lore raw
Quoted 7 lines · 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

- A patch title does not need lib/ prefix.
Here, "eal/ppc: " is enough.

- Code in lib/eal/linux won't be used for FreeBSD/Windows. On the other hand, arch-specific code (here, lib/eal/ppc/) can be used for the various OS.
Besides, as far as I can see in the Linux kernel sources, powerpc is the only architecture that exports a "timebase" entry in /proc/cpuinfo.
So, I see no reason to put any code out of lib/eal/ppc.

- In the end, unless I missed some point, the patch could probably look like (untested):

lib/eal/ppc/include/rte_cycles.h +7 -0
index 5585f9273c..666fc9b0bf 100644
@@ -10,7 +10,10 @@
 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
lib/eal/ppc/rte_cycles.c +38 -0
index 3180adb0ff..99d36b2f7e 100644
@@ -2,12 +2,50 @@
  * 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
 }
Signature · 1 line
David Marchand
author
#11 lore raw
Quoted 110 lines · David Marchand
Quoted 7 lines · 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

- A patch title does not need lib/ prefix.
Here, "eal/ppc: " is enough.

- Code in lib/eal/linux won't be used for FreeBSD/Windows. On the other hand, arch-specific code (here, lib/eal/ppc/) can be used for the various OS.
Besides, as far as I can see in the Linux kernel sources, powerpc is the only architecture that exports a "timebase" entry in /proc/cpuinfo.
So, I see no reason to put any code out of lib/eal/ppc.

- In the end, unless I missed some point, the patch could probably look like (untested):

lib/eal/ppc/include/rte_cycles.h +3 -0
index 5585f9273c..666fc9b0bf 100644
@@ -10,7 +10,10 @@
 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)
{

lib/eal/ppc/include/rte_cycles.h +4 -0
+#ifdef __GLIBC__
       return __ppc_get_timebase();
+#else
+       return __builtin_ppc_get_timebase();
+#endif

}

static inline uint64_t

lib/eal/ppc/rte_cycles.c +6 -0
index 3180adb0ff..99d36b2f7e 100644
@@ -2,12 +2,50 @@
 * 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)
{

lib/eal/ppc/rte_cycles.c +32 -0
+#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
Quoted 6 lines

}

Signature · 1 line
David Marchand

Thanks, that looks the same thing. Will run through alpine CI and change commit title

#12 lore raw

PATCH v7 1/1 eal/ppc: fix compilation for musl

In reply to Duncan Bellamy

musl lacks __ppc_get_timebase() but has __builtin_ppc_get_timebase()

---
 lib/eal/ppc/include/rte_cycles.h |  7 ++++++
 lib/eal/ppc/rte_cycles.c         | 39 ++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
lib/eal/ppc/include/rte_cycles.h +7 -0
index 5585f9273c..666fc9b0bf 100644
@@ -10,7 +10,10 @@
 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
lib/eal/ppc/rte_cycles.c +39 -0
index 3180adb0ff..cd4bdff8b8 100644
@@ -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
+
 }
Signature · 1 line
2.34.1
#13 lore raw

Re: [PATCH v7] eal/ppc: fix compilation for musl

Quoted 4 lines · Duncan Bellamy

musl lacks __ppc_get_timebase() but has __builtin_ppc_get_timebase()

Cc maintainer.
Signature · 1 line
David Marchand
Reviewed-by on v7 1/1
#14 lore raw

Re: [PATCH v7] eal/ppc: fix compilation for musl

In reply to Duncan Bellamy
Quoted 81 lines · Duncan Bellamy

musl lacks __ppc_get_timebase() but has __builtin_ppc_get_timebase()

---
  lib/eal/ppc/include/rte_cycles.h |  7 ++++++
  lib/eal/ppc/rte_cycles.c         | 39 ++++++++++++++++++++++++++++++++
  2 files changed, 46 insertions(+)
lib/eal/ppc/include/rte_cycles.h +7 -0
index 5585f9273c..666fc9b0bf 100644
@@ -10,7 +10,10 @@
  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
lib/eal/ppc/rte_cycles.c +30 -0
index 3180adb0ff..cd4bdff8b8 100644
@@ -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);

lib/eal/ppc/rte_cycles.c line 52

Quoted 10 lines
lib/eal/ppc/rte_cycles.c +9 -0
+		break;
+	}
+	fclose(f);
+out:
+	return (uint64_t) base;
+#else
+	return 0;
+#endif
+
  }