Message ID | 20220514071435.3024492-1-dunk@denkimushi.com (mailing list archive) |
---|---|
State | New |
Delegated to: | David Marchand |
Headers | show |
Series | [v7] eal/ppc: fix compilation for musl | expand |
Context | Check | Description |
---|---|---|
ci/intel-Testing | success | Testing PASS |
ci/Intel-compilation | success | Compilation OK |
ci/iol-x86_64-unit-testing | success | Testing PASS |
ci/iol-aarch64-compile-testing | success | Testing PASS |
ci/iol-aarch64-unit-testing | success | Testing PASS |
ci/iol-x86_64-compile-testing | success | Testing PASS |
ci/github-robot: build | success | github build: passed |
ci/iol-abi-testing | success | Testing PASS |
ci/iol-intel-Functional | success | Functional Testing PASS |
ci/iol-intel-Performance | success | Performance Testing PASS |
ci/checkpatch | success | coding style OK |
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.
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 + }
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(+)