ppc64le: fix build without glibc and using Clang

Message ID 20210517004621.64357-1-pkubaj@FreeBSD.org (mailing list archive)
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers
Series ppc64le: fix build without glibc and using Clang |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Functional fail Functional Testing issues

Commit Message

Piotr Kubaj May 17, 2021, 12:46 a.m. UTC
  __ppc_get_timebase() is only present when glibc is used.

Signed-off-by: Piotr Kubaj <pkubaj@FreeBSD.org>
---
 lib/eal/ppc/include/rte_altivec.h |  3 +++
 lib/eal/ppc/include/rte_cycles.h  | 12 ++++++++++++
 lib/eal/ppc/rte_cycles.c          | 16 ++++++++++++++++
 3 files changed, 31 insertions(+)
  

Comments

David Christensen May 18, 2021, 8:42 p.m. UTC | #1
On 5/16/21 5:46 PM, Piotr Kubaj wrote:
> __ppc_get_timebase() is only present when glibc is used.
> 
> Signed-off-by: Piotr Kubaj <pkubaj@FreeBSD.org>
> ---
>   lib/eal/ppc/include/rte_altivec.h |  3 +++
>   lib/eal/ppc/include/rte_cycles.h  | 12 ++++++++++++
>   lib/eal/ppc/rte_cycles.c          | 16 ++++++++++++++++
>   3 files changed, 31 insertions(+)
> 
> diff --git a/lib/eal/ppc/include/rte_altivec.h b/lib/eal/ppc/include/rte_altivec.h
> index 1551a94544..3fcc819c11 100644
> --- a/lib/eal/ppc/include/rte_altivec.h
> +++ b/lib/eal/ppc/include/rte_altivec.h
> @@ -7,6 +7,9 @@
>   #define _RTE_ALTIVEC_H_
> 
>   /* To include altivec.h, GCC version must be >= 4.8 */
> +#ifdef __clang__
> +#define vector __vector
> +#endif
>   #include <altivec.h>
> 
>   /*
> diff --git a/lib/eal/ppc/include/rte_cycles.h b/lib/eal/ppc/include/rte_cycles.h
> index 5585f9273c..a8307ceaff 100644
> --- a/lib/eal/ppc/include/rte_cycles.h
> +++ b/lib/eal/ppc/include/rte_cycles.h
> @@ -10,7 +10,13 @@
>   extern "C" {
>   #endif
> 
> +#ifdef linux
> +#include <features.h>
> +#endif
> +
> +#ifdef __GLIBC__
>   #include <sys/platform/ppc.h>
> +#endif
> 
>   #include "generic/rte_cycles.h"
> 
> @@ -26,7 +32,13 @@ extern "C" {
>   static inline uint64_t
>   rte_rdtsc(void)
>   {
> +#ifdef __GLIBC__
>   	return __ppc_get_timebase();
> +#else
> +	uint64_t __tb;
> +	__asm__ volatile ("mfspr %0, 268" : "=r" (__tb));
> +	return __tb;
> +#endif
>   }
> 
>   static inline uint64_t
> diff --git a/lib/eal/ppc/rte_cycles.c b/lib/eal/ppc/rte_cycles.c
> index 3180adb0ff..48545c4d67 100644
> --- a/lib/eal/ppc/rte_cycles.c
> +++ b/lib/eal/ppc/rte_cycles.c
> @@ -2,12 +2,28 @@
>    * Copyright (C) IBM Corporation 2019.
>    */
> 
> +#ifdef linux
> +#include <features.h>
> +#elif defined(__FreeBSD__)
> +#include <sys/types.h>
> +#include <sys/sysctl.h>
> +#endif
> +
> +#ifdef __GLIBC__
>   #include <sys/platform/ppc.h>
> +#endif
> 
>   #include "eal_private.h"
> 
>   uint64_t
>   get_tsc_freq_arch(void)
>   {
> +#ifdef __GLIBC__
>   	return __ppc_get_timebase_freq();
> +#elif defined(__FreeBSD__)
> +	uint64_t freq;
> +	size_t length = sizeof(freq);
> +	sysctlbyname("kern.timecounter.tc.timebase.frequency", &freq, &length, NULL, 0);
> +	return freq;
> +#endif
>   }
> 

Reviewed-by: David Christensen <drc@linux.vnet.ibm.com>
  
Thomas Monjalon May 19, 2021, 7:53 a.m. UTC | #2
18/05/2021 22:42, David Christensen:
> On 5/16/21 5:46 PM, Piotr Kubaj wrote:
> > __ppc_get_timebase() is only present when glibc is used.
> > 
> > Signed-off-by: Piotr Kubaj <pkubaj@FreeBSD.org>
> > ---
> >   lib/eal/ppc/include/rte_altivec.h |  3 +++
> >   lib/eal/ppc/include/rte_cycles.h  | 12 ++++++++++++
> >   lib/eal/ppc/rte_cycles.c          | 16 ++++++++++++++++
> >   3 files changed, 31 insertions(+)
> 
> Reviewed-by: David Christensen <drc@linux.vnet.ibm.com>

This patch does a lot more than what is described.
It seems adding support for FreeBSD.
For testing OS, please use #ifdef RTE_EXEC_ENV_*
  
Piotr Kubaj May 19, 2021, 9:57 a.m. UTC | #3
Well, isn't FreeBSD already supported?

Even https://www.dpdk.org/ mentions supporting FreeBSD.

On 21-05-19 09:53:16, Thomas Monjalon wrote:
> 18/05/2021 22:42, David Christensen:
> > On 5/16/21 5:46 PM, Piotr Kubaj wrote:
> > > __ppc_get_timebase() is only present when glibc is used.
> > > 
> > > Signed-off-by: Piotr Kubaj <pkubaj@FreeBSD.org>
> > > ---
> > >   lib/eal/ppc/include/rte_altivec.h |  3 +++
> > >   lib/eal/ppc/include/rte_cycles.h  | 12 ++++++++++++
> > >   lib/eal/ppc/rte_cycles.c          | 16 ++++++++++++++++
> > >   3 files changed, 31 insertions(+)
> > 
> > Reviewed-by: David Christensen <drc@linux.vnet.ibm.com>
> 
> This patch does a lot more than what is described.
> It seems adding support for FreeBSD.
> For testing OS, please use #ifdef RTE_EXEC_ENV_*
> 
>
  
Thomas Monjalon May 19, 2021, 9:59 a.m. UTC | #4
19/05/2021 11:57, Piotr Kubaj:
> Well, isn't FreeBSD already supported?
> 
> Even https://www.dpdk.org/ mentions supporting FreeBSD.

Yes it is supposed to be supported.
But why are you adding all this code for PPC?
It doesn't seem to be all related to clang only.

PS: please do not top-post.


> On 21-05-19 09:53:16, Thomas Monjalon wrote:
> > 18/05/2021 22:42, David Christensen:
> > > On 5/16/21 5:46 PM, Piotr Kubaj wrote:
> > > > __ppc_get_timebase() is only present when glibc is used.
> > > > 
> > > > Signed-off-by: Piotr Kubaj <pkubaj@FreeBSD.org>
> > > > ---
> > > >   lib/eal/ppc/include/rte_altivec.h |  3 +++
> > > >   lib/eal/ppc/include/rte_cycles.h  | 12 ++++++++++++
> > > >   lib/eal/ppc/rte_cycles.c          | 16 ++++++++++++++++
> > > >   3 files changed, 31 insertions(+)
> > > 
> > > Reviewed-by: David Christensen <drc@linux.vnet.ibm.com>
> > 
> > This patch does a lot more than what is described.
> > It seems adding support for FreeBSD.
> > For testing OS, please use #ifdef RTE_EXEC_ENV_*
  
Piotr Kubaj May 19, 2021, 12:07 p.m. UTC | #5
On 21-05-19 11:59:35, Thomas Monjalon wrote:
> 19/05/2021 11:57, Piotr Kubaj:
> > Well, isn't FreeBSD already supported?
> > 
> > Even https://www.dpdk.org/ mentions supporting FreeBSD.
> 
> Yes it is supposed to be supported.
> But why are you adding all this code for PPC?
> It doesn't seem to be all related to clang only.
> 
> PS: please do not top-post.
> 
> 
> > On 21-05-19 09:53:16, Thomas Monjalon wrote:
> > > 18/05/2021 22:42, David Christensen:
> > > > On 5/16/21 5:46 PM, Piotr Kubaj wrote:
> > > > > __ppc_get_timebase() is only present when glibc is used.
> > > > > 
> > > > > Signed-off-by: Piotr Kubaj <pkubaj@FreeBSD.org>
> > > > > ---
> > > > >   lib/eal/ppc/include/rte_altivec.h |  3 +++
> > > > >   lib/eal/ppc/include/rte_cycles.h  | 12 ++++++++++++
> > > > >   lib/eal/ppc/rte_cycles.c          | 16 ++++++++++++++++
> > > > >   3 files changed, 31 insertions(+)
> > > > 
> > > > Reviewed-by: David Christensen <drc@linux.vnet.ibm.com>
> > > 
> > > This patch does a lot more than what is described.
> > > It seems adding support for FreeBSD.
> > > For testing OS, please use #ifdef RTE_EXEC_ENV_*
> 
> 
> 
> 

Well, I'm adding this code for PPC, because there are build issues on powerpc64le machines running FreeBSD.
  

Patch

diff --git a/lib/eal/ppc/include/rte_altivec.h b/lib/eal/ppc/include/rte_altivec.h
index 1551a94544..3fcc819c11 100644
--- a/lib/eal/ppc/include/rte_altivec.h
+++ b/lib/eal/ppc/include/rte_altivec.h
@@ -7,6 +7,9 @@ 
 #define _RTE_ALTIVEC_H_
 
 /* To include altivec.h, GCC version must be >= 4.8 */
+#ifdef __clang__
+#define vector __vector
+#endif
 #include <altivec.h>
 
 /*
diff --git a/lib/eal/ppc/include/rte_cycles.h b/lib/eal/ppc/include/rte_cycles.h
index 5585f9273c..a8307ceaff 100644
--- a/lib/eal/ppc/include/rte_cycles.h
+++ b/lib/eal/ppc/include/rte_cycles.h
@@ -10,7 +10,13 @@ 
 extern "C" {
 #endif
 
+#ifdef linux
+#include <features.h>
+#endif
+
+#ifdef __GLIBC__
 #include <sys/platform/ppc.h>
+#endif
 
 #include "generic/rte_cycles.h"
 
@@ -26,7 +32,13 @@  extern "C" {
 static inline uint64_t
 rte_rdtsc(void)
 {
+#ifdef __GLIBC__
 	return __ppc_get_timebase();
+#else
+	uint64_t __tb;
+	__asm__ volatile ("mfspr %0, 268" : "=r" (__tb));
+	return __tb;
+#endif
 }
 
 static inline uint64_t
diff --git a/lib/eal/ppc/rte_cycles.c b/lib/eal/ppc/rte_cycles.c
index 3180adb0ff..48545c4d67 100644
--- a/lib/eal/ppc/rte_cycles.c
+++ b/lib/eal/ppc/rte_cycles.c
@@ -2,12 +2,28 @@ 
  * Copyright (C) IBM Corporation 2019.
  */
 
+#ifdef linux
+#include <features.h>
+#elif defined(__FreeBSD__)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
+
+#ifdef __GLIBC__
 #include <sys/platform/ppc.h>
+#endif
 
 #include "eal_private.h"
 
 uint64_t
 get_tsc_freq_arch(void)
 {
+#ifdef __GLIBC__
 	return __ppc_get_timebase_freq();
+#elif defined(__FreeBSD__)
+	uint64_t freq;
+	size_t length = sizeof(freq);
+	sysctlbyname("kern.timecounter.tc.timebase.frequency", &freq, &length, NULL, 0);
+	return freq;
+#endif
 }