[v2] lib/eal/ppc fix compilation for musl

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

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build fail github build: failed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional 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/iol-abi-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS

Commit Message

Duncan Bellamy May 2, 2022, 2:26 p.m. UTC
  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(+)
  

Comments

David Marchand May 2, 2022, 5:41 p.m. UTC | #1
On Mon, May 2, 2022 at 4:26 PM Duncan Bellamy <dunk@denkimushi.com> wrote:
>
> 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..98ffbd2592 100644
> --- a/lib/eal/ppc/include/rte_cycles.h
> +++ b/lib/eal/ppc/include/rte_cycles.h
> @@ -10,7 +10,9 @@
>  extern "C" {
>  #endif
>
> +#if defined(__GLIBC__)

features.h should be included before looking for __GLIBC__.
  
David Christensen May 2, 2022, 5:42 p.m. UTC | #2
On 5/2/22 7:26 AM, Duncan Bellamy wrote:
> 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..98ffbd2592 100644
> --- a/lib/eal/ppc/include/rte_cycles.h
> +++ b/lib/eal/ppc/include/rte_cycles.h
> @@ -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
> diff --git a/lib/eal/ppc/rte_cycles.c b/lib/eal/ppc/rte_cycles.c
> index 3180adb0ff..154eba722c 100644
> --- a/lib/eal/ppc/rte_cycles.c
> +++ b/lib/eal/ppc/rte_cycles.c
> @@ -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");

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
  
Duncan Bellamy May 2, 2022, 8:18 p.m. UTC | #3
> On 2 May 2022, at 18:42, David Marchand <david.marchand@redhat.com> wrote:
> 
> On Mon, May 2, 2022 at 4:26 PM Duncan Bellamy <dunk@denkimushi.com> wrote:
>> 
>> 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..98ffbd2592 100644
>> --- a/lib/eal/ppc/include/rte_cycles.h
>> +++ b/lib/eal/ppc/include/rte_cycles.h
>> @@ -10,7 +10,9 @@
>> extern "C" {
>> #endif
>> 
>> +#if defined(__GLIBC__)
> 
> features.h should be included before looking for __GLIBC__.
> 
> 
> -- 
> David Marchand
> 

Okay, wondered why it wasn’t working
  
Duncan Bellamy May 2, 2022, 8:20 p.m. UTC | #4
> On 2 May 2022, at 18:43, David Christensen <drc@linux.vnet.ibm.com> wrote:
> 
> 
> 
>> On 5/2/22 7:26 AM, Duncan Bellamy wrote:
>> 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..98ffbd2592 100644
>> --- a/lib/eal/ppc/include/rte_cycles.h
>> +++ b/lib/eal/ppc/include/rte_cycles.h
>> @@ -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
>> diff --git a/lib/eal/ppc/rte_cycles.c b/lib/eal/ppc/rte_cycles.c
>> index 3180adb0ff..154eba722c 100644
>> --- a/lib/eal/ppc/rte_cycles.c
>> +++ b/lib/eal/ppc/rte_cycles.c
>> @@ -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");
> 
> 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
  

Patch

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