[v7] eal/ppc: fix compilation for musl
Checks
Commit Message
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
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.
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>
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.
@@ -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
@@ -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
+
}