From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bruce Richardson Subject: [PATCH 1/2] examples/performance-thread: fix FreeBSD compilation Date: Thu, 20 Apr 2017 17:32:49 +0100 Message-ID: <20170420163250.1373-2-bruce.richardson@intel.com> References: <20170420163250.1373-1-bruce.richardson@intel.com> Cc: Bruce Richardson , stable@dpdk.org To: dev@dpdk.org Return-path: In-Reply-To: <20170420163250.1373-1-bruce.richardson@intel.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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@dpdk.org Signed-off-by: Bruce Richardson --- 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 /* + * 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 +#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