[v7] eal/ppc: fix compilation for musl

Message ID 20220514071435.3024492-1-dunk@denkimushi.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series [v7] eal/ppc: fix compilation for musl |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-abi-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

Duncan Bellamy May 14, 2022, 7:14 a.m. UTC
  musl lacks __ppc_get_timebase() but has __builtin_ppc_get_timebase()

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

Comments

David Marchand May 19, 2022, 4:18 p.m. UTC | #1
On Sat, May 14, 2022 at 9:15 AM Duncan Bellamy <dunk@denkimushi.com> wrote:
>
> musl lacks __ppc_get_timebase() but has __builtin_ppc_get_timebase()
>
> Signed-off-by: Duncan Bellamy <dunk@denkimushi.com>

Cc: maintainer.
  
David Christensen May 31, 2022, 5:24 p.m. UTC | #2
On 5/14/22 12:14 AM, Duncan Bellamy wrote:
> musl lacks __ppc_get_timebase() but has __builtin_ppc_get_timebase()
> 
> Signed-off-by: Duncan Bellamy <dunk@denkimushi.com>
> ---
>   lib/eal/ppc/include/rte_cycles.h |  7 ++++++
>   lib/eal/ppc/rte_cycles.c         | 39 ++++++++++++++++++++++++++++++++
>   2 files changed, 46 insertions(+)
> 
> diff --git a/lib/eal/ppc/include/rte_cycles.h b/lib/eal/ppc/include/rte_cycles.h
> index 5585f9273c..666fc9b0bf 100644
> --- a/lib/eal/ppc/include/rte_cycles.h
> +++ b/lib/eal/ppc/include/rte_cycles.h
> @@ -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
> diff --git a/lib/eal/ppc/rte_cycles.c b/lib/eal/ppc/rte_cycles.c
> index 3180adb0ff..cd4bdff8b8 100644
> --- a/lib/eal/ppc/rte_cycles.c
> +++ b/lib/eal/ppc/rte_cycles.c
> @@ -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
> +
>   }

Reviewed-by: David Christensen <drc@linux.vnet.ibm.com>
  
David Marchand June 1, 2022, 3:06 p.m. UTC | #3
On Tue, May 31, 2022 at 7:26 PM David Christensen
<drc@linux.vnet.ibm.com> wrote:
> On 5/14/22 12:14 AM, Duncan Bellamy wrote:
> > 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>

Applied, thanks.
  

Patch

diff --git a/lib/eal/ppc/include/rte_cycles.h b/lib/eal/ppc/include/rte_cycles.h
index 5585f9273c..666fc9b0bf 100644
--- a/lib/eal/ppc/include/rte_cycles.h
+++ b/lib/eal/ppc/include/rte_cycles.h
@@ -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
diff --git a/lib/eal/ppc/rte_cycles.c b/lib/eal/ppc/rte_cycles.c
index 3180adb0ff..cd4bdff8b8 100644
--- a/lib/eal/ppc/rte_cycles.c
+++ b/lib/eal/ppc/rte_cycles.c
@@ -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
+
 }