From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <bruce.richardson@intel.com>
Received: from mga11.intel.com (mga11.intel.com [192.55.52.93])
 by dpdk.org (Postfix) with ESMTP id 1CFF037B0;
 Thu, 20 Apr 2017 18:33:06 +0200 (CEST)
Received: from fmsmga003.fm.intel.com ([10.253.24.29])
 by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;
 20 Apr 2017 09:33:06 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.37,225,1488873600"; d="scan'208";a="848078566"
Received: from sivswdev01.ir.intel.com ([10.237.217.45])
 by FMSMGA003.fm.intel.com with ESMTP; 20 Apr 2017 09:33:04 -0700
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>,
	stable@dpdk.org
Date: Thu, 20 Apr 2017 17:32:49 +0100
Message-Id: <20170420163250.1373-2-bruce.richardson@intel.com>
X-Mailer: git-send-email 2.8.4
In-Reply-To: <20170420163250.1373-1-bruce.richardson@intel.com>
References: <20170420163250.1373-1-bruce.richardson@intel.com>
Subject: [dpdk-stable] [PATCH 1/2] examples/performance-thread: fix FreeBSD
	compilation
X-BeenThere: stable@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches for DPDK stable branches <stable.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/stable>,
 <mailto:stable-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/stable/>
List-Post: <mailto:stable@dpdk.org>
List-Help: <mailto:stable-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/stable>,
 <mailto:stable-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Thu, 20 Apr 2017 16:33:07 -0000

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