DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>, stable@dpdk.org
Subject: [dpdk-dev] [PATCH 1/2] examples/performance-thread: fix FreeBSD compilation
Date: Thu, 20 Apr 2017 17:32:49 +0100	[thread overview]
Message-ID: <20170420163250.1373-2-bruce.richardson@intel.com> (raw)
In-Reply-To: <20170420163250.1373-1-bruce.richardson@intel.com>

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 <bruce.richardson@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

  reply	other threads:[~2017-04-20 16:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-20 16:32 [dpdk-dev] [PATCH 0/2] fixes for " Bruce Richardson
2017-04-20 16:32 ` Bruce Richardson [this message]
2017-04-20 17:33   ` [dpdk-dev] [dpdk-stable] [PATCH 1/2] examples/performance-thread: fix " Thomas Monjalon
2017-04-20 16:32 ` [dpdk-dev] [PATCH 2/2] net/ark: " Bruce Richardson
2017-04-20 17:23   ` john miller
2017-04-21 13:50 ` [dpdk-dev] [PATCH v2 0/4] Fixes for BSD compilation Bruce Richardson
2017-04-21 13:50   ` [dpdk-dev] [PATCH v2 1/4] net/ark: fix FreeBSD compilation Bruce Richardson
2017-04-21 13:50   ` [dpdk-dev] [PATCH v2 2/4] examples: fix examples_clean build target on FreeBSD Bruce Richardson
2017-04-21 13:50   ` [dpdk-dev] [PATCH v2 3/4] examples/performance-thread: fix FreeBSD compilation Bruce Richardson
2017-04-21 13:50   ` [dpdk-dev] [PATCH v2 4/4] examples/performance-thread: use a single build output dir Bruce Richardson
2017-04-21 14:12   ` [dpdk-dev] [PATCH v2 0/4] Fixes for BSD compilation Thomas Monjalon

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=20170420163250.1373-2-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=stable@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).