DPDK patches and discussions
 help / color / mirror / Atom feed
From: Duncan Bellamy <dunk@denkimushi.com>
To: dev@dpdk.org
Cc: Duncan Bellamy <dunk@denkimushi.com>
Subject: [PATCH v7] eal/ppc: fix compilation for musl
Date: Sat, 14 May 2022 08:14:35 +0100	[thread overview]
Message-ID: <20220514071435.3024492-1-dunk@denkimushi.com> (raw)
In-Reply-To: <20220502142615.3705639-1-dunk@denkimushi.com>

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
+
 }
-- 
2.34.1


  parent reply	other threads:[~2022-05-14  7:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220502115228.3AAAB1242D4@dpdk.org>
2022-05-02 14:26 ` [PATCH v2] lib/eal/ppc " Duncan Bellamy
2022-05-02 17:41   ` David Marchand
2022-05-02 20:18     ` Dunk
2022-05-02 17:42   ` David Christensen
2022-05-02 20:20     ` Dunk
2022-05-07  9:47   ` [PATCH v3] " Duncan Bellamy
2022-05-07 19:43   ` [PATCH v4] " Duncan Bellamy
2022-05-07 21:03   ` [PATCH v5] " Duncan Bellamy
2022-05-07 21:15   ` [PATCH v6] " Duncan Bellamy
2022-05-09 12:06     ` David Marchand
2022-05-09 22:39       ` Dunk
2022-05-14  7:14   ` Duncan Bellamy [this message]
2022-05-19 16:18     ` [PATCH v7] eal/ppc: " David Marchand
2022-05-31 17:24     ` David Christensen
2022-06-01 15:06       ` David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220514071435.3024492-1-dunk@denkimushi.com \
    --to=dunk@denkimushi.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).