[dpdk-stable] [PATCH 1/2] examples/performance-thread: fix FreeBSD compilation
Bruce Richardson
bruce.richardson at intel.com
Thu Apr 20 18:32:49 CEST 2017
This set of sample apps did not compile on FreeBSD due to use of a number
of Linux/glibc-specific APIs, or APIs which existed in different headers
on FreeBSD. Specifically, the following APIs has problems:
* sched_getcpu() is a glibc extension
* pthread_yield() returns int on Linux, but void on FreeBSD
* APIs for managing cpu affinity are in pthread_np.h on FreeBSD, rather
than in pthread.h
* the type for managing cpu sets is cpuset_t on FreeBSD rather than
cpu_set_t as on Linux.
Fixes: 433ba6228f9a ("examples/performance-thread: add pthread_shim app")
Fixes: d48415e1fee3 ("examples/performance-thread: add l3fwd-thread app")
CC: stable at dpdk.org
Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
---
examples/performance-thread/l3fwd-thread/main.c | 4 ++++
examples/performance-thread/pthread_shim/main.c | 4 ++++
examples/performance-thread/pthread_shim/pthread_shim.c | 15 +++++++++++++--
examples/performance-thread/pthread_shim/pthread_shim.h | 9 +++++++++
4 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/examples/performance-thread/l3fwd-thread/main.c b/examples/performance-thread/l3fwd-thread/main.c
index f6154ac2a..2d98473eb 100644
--- a/examples/performance-thread/l3fwd-thread/main.c
+++ b/examples/performance-thread/l3fwd-thread/main.c
@@ -90,6 +90,10 @@
#define APP_LOOKUP_METHOD APP_LOOKUP_LPM
#endif
+#ifndef __GLIBC__ /* sched_getcpu() is glibc specific */
+#define sched_getcpu() rte_lcore_id()
+#endif
+
static int
check_ptype(int portid)
{
diff --git a/examples/performance-thread/pthread_shim/main.c b/examples/performance-thread/pthread_shim/main.c
index f03572181..f7074006e 100644
--- a/examples/performance-thread/pthread_shim/main.c
+++ b/examples/performance-thread/pthread_shim/main.c
@@ -59,6 +59,10 @@
#define DEBUG_APP 0
#define HELLOW_WORLD_MAX_LTHREADS 10
+#ifndef __GLIBC__ /* sched_getcpu() is glibc-specific */
+#define sched_getcpu() rte_lcore_id()
+#endif
+
__thread int print_count;
__thread pthread_mutex_t print_lock;
diff --git a/examples/performance-thread/pthread_shim/pthread_shim.c b/examples/performance-thread/pthread_shim/pthread_shim.c
index 0d6100c90..1b2e1de03 100644
--- a/examples/performance-thread/pthread_shim/pthread_shim.c
+++ b/examples/performance-thread/pthread_shim/pthread_shim.c
@@ -576,15 +576,26 @@ int pthread_rwlock_wrlock(pthread_rwlock_t *a)
return _sys_pthread_funcs.f_pthread_rwlock_wrlock(a);
}
-int pthread_yield(void)
+#ifdef RTE_EXEC_ENV_LINUXAPP
+int
+pthread_yield(void)
{
if (override) {
lthread_yield();
return 0;
}
return _sys_pthread_funcs.f_pthread_yield();
-
}
+#else
+void
+pthread_yield(void)
+{
+ if (override)
+ lthread_yield();
+ else
+ _sys_pthread_funcs.f_pthread_yield();
+}
+#endif
pthread_t pthread_self(void)
{
diff --git a/examples/performance-thread/pthread_shim/pthread_shim.h b/examples/performance-thread/pthread_shim/pthread_shim.h
index 78bbb5ac0..527640bd6 100644
--- a/examples/performance-thread/pthread_shim/pthread_shim.h
+++ b/examples/performance-thread/pthread_shim/pthread_shim.h
@@ -36,6 +36,15 @@
#include <pthread.h>
/*
+ * on BSD, the non-std calls are in pthread_np.h,
+ * and cpuset_t has only one "_" rather than two.
+ */
+#ifdef RTE_EXEC_ENV_BSDAPP
+#include <pthread_np.h>
+#define cpu_set_t cpuset_t
+#endif
+
+/*
* This pthread shim is an example that demonstrates how legacy code
* that makes use of POSIX pthread services can make use of lthreads
* with reduced porting effort.
--
2.11.0
More information about the stable
mailing list