aboutsummaryrefslogtreecommitdiff
path: root/helper
diff options
context:
space:
mode:
authorPetri Savolainen <petri.savolainen@linaro.org>2017-02-03 13:23:59 +0200
committerMaxim Uvarov <maxim.uvarov@linaro.org>2017-02-16 23:30:27 +0300
commitaf5205809e3921ea0c4db5771ea1da5d2f0eaaf5 (patch)
tree792e274bcd065b57a31c67ce455f16c96640ee4d /helper
parent32b94edb4961a3ac1a2e5c90f65ee3f118852151 (diff)
helper: linux: renamed threads_extn to linux helpers
There's no platform specific helpers. Helpers may depend on Linux and make it easier to do common series of Linux system calls. These kind of helpers are grouped into helper/linux directory. Use --enable-helper-linux configuration option to enable support for Linux helpers. Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org> Reviewed-by: Mike Holmes <mike.holmes@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'helper')
-rw-r--r--helper/Makefile.am18
-rw-r--r--helper/include/odp/helper/linux/process.h (renamed from helper/include/odp/helper/platform/linux-generic/threads_extn.h)44
-rw-r--r--helper/include/odp/helper/linux/pthread.h66
-rw-r--r--helper/linux/thread.c (renamed from helper/platform/linux-generic/thread.c)78
-rw-r--r--helper/m4/configure.m48
-rw-r--r--helper/test/.gitignore1
-rw-r--r--helper/test/Makefile.am9
-rw-r--r--helper/test/linux-generic/Makefile.am5
-rw-r--r--helper/test/linux/Makefile.am5
-rw-r--r--helper/test/linux/process.c (renamed from helper/test/linux-generic/process.c)3
-rw-r--r--helper/test/linux/pthread.c (renamed from helper/test/linux-generic/thread.c)2
11 files changed, 103 insertions, 136 deletions
diff --git a/helper/Makefile.am b/helper/Makefile.am
index 6b65eb1c3..5757c7c81 100644
--- a/helper/Makefile.am
+++ b/helper/Makefile.am
@@ -31,16 +31,18 @@ helperinclude_HEADERS = \
$(srcdir)/include/odp/helper/threads.h \
$(srcdir)/include/odp/helper/udp.h
-if helper_extn
-helperinclude_HEADERS += \
- $(srcdir)/include/odp/helper/platform/@with_helper_platform@/threads_extn.h
+if helper_linux
+helperlinuxincludedir = $(includedir)/odp/helper/linux
+helperlinuxinclude_HEADERS = \
+ $(srcdir)/include/odp/helper/linux/pthread.h \
+ $(srcdir)/include/odp/helper/linux/process.h
endif
noinst_HEADERS = \
$(srcdir)/odph_debug.h \
$(srcdir)/odph_list_internal.h
-__LIB__libodphelper_@with_platform@_la_SOURCES = \
+__LIB__libodphelper_la_SOURCES = \
eth.c \
ip.c \
chksum.c \
@@ -50,9 +52,9 @@ __LIB__libodphelper_@with_platform@_la_SOURCES = \
iplookuptable.c \
threads.c
-if helper_extn
-__LIB__libodphelper_@with_platform@_la_SOURCES += \
- platform/@with_helper_platform@/thread.c
+if helper_linux
+__LIB__libodphelper_la_SOURCES += \
+ linux/thread.c
endif
-lib_LTLIBRARIES = $(LIB)/libodphelper-@with_platform@.la
+lib_LTLIBRARIES = $(LIB)/libodphelper.la
diff --git a/helper/include/odp/helper/platform/linux-generic/threads_extn.h b/helper/include/odp/helper/linux/process.h
index 1d4036db7..9d74146b0 100644
--- a/helper/include/odp/helper/platform/linux-generic/threads_extn.h
+++ b/helper/include/odp/helper/linux/process.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2016, Linaro Limited
+/* Copyright (c) 2017, Linaro Limited
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
@@ -7,15 +7,15 @@
/**
* @file
*
- * ODP Linux helper extension API
+ * ODP Linux helper for processes
*
- * This file is an optional helper to odp.h APIs. These functions are provided
- * to ease common setups in a Linux system. User is free to implement the same
- * setups in otherways (not via this API).
+ * This file is not part of ODP APIs, but can be optionally used to ease common
+ * setups in a Linux system. User is free to implement the same setups in
+ * otherways (not via this file).
*/
-#ifndef ODPH_LINUX_EXT_H_
-#define ODPH_LINUX_EXT_H_
+#ifndef ODPH_LINUX_PROCESS_H_
+#define ODPH_LINUX_PROCESS_H_
#include <odp/helper/threads.h>
@@ -23,39 +23,11 @@
extern "C" {
#endif
-/** @addtogroup odph_linux ODPH LINUX
+/** @ingroup odph_linux
* @{
*/
/**
- * Creates and launches pthreads
- *
- * Creates, pins and launches threads to separate CPU's based on the cpumask.
- *
- * @param[out] pthread_tbl Table of pthread state information records. Table
- * must have at least as many entries as there are
- * CPUs in the CPU mask.
- * @param mask CPU mask
- * @param thr_params Linux helper thread parameters
- *
- * @return Number of threads created
- */
-int odph_linux_pthread_create(odph_linux_pthread_t *pthread_tbl,
- const odp_cpumask_t *mask,
- const odph_linux_thr_params_t *thr_params);
-
-/**
- * Waits pthreads to exit
- *
- * Returns when all threads have been exit.
- *
- * @param thread_tbl Thread table
- * @param num Number of threads to create
- *
- */
-void odph_linux_pthread_join(odph_linux_pthread_t *thread_tbl, int num);
-
-/**
* Fork a process
*
* Forks and sets CPU affinity for the child process. Ignores 'start' and 'arg'
diff --git a/helper/include/odp/helper/linux/pthread.h b/helper/include/odp/helper/linux/pthread.h
new file mode 100644
index 000000000..feeda5e28
--- /dev/null
+++ b/helper/include/odp/helper/linux/pthread.h
@@ -0,0 +1,66 @@
+/* Copyright (c) 2017, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/**
+ * @file
+ *
+ * ODP Linux helper for pthreads
+ *
+ * This file is not part of ODP APIs, but can be optionally used to ease common
+ * setups in a Linux system. User is free to implement the same setups in
+ * otherways (not via this file).
+ */
+
+#ifndef ODPH_LINUX_PTHREAD_H_
+#define ODPH_LINUX_PTHREAD_H_
+
+#include <odp/helper/threads.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @ingroup odph_linux
+ * @{
+ */
+
+/**
+ * Creates and launches pthreads
+ *
+ * Creates, pins and launches threads to separate CPU's based on the cpumask.
+ *
+ * @param[out] pthread_tbl Table of pthread state information records. Table
+ * must have at least as many entries as there are
+ * CPUs in the CPU mask.
+ * @param mask CPU mask
+ * @param thr_params Linux helper thread parameters
+ *
+ * @return Number of threads created
+ */
+int odph_linux_pthread_create(odph_linux_pthread_t *pthread_tbl,
+ const odp_cpumask_t *mask,
+ const odph_linux_thr_params_t *thr_params);
+
+/**
+ * Waits pthreads to exit
+ *
+ * Returns when all threads have been exit.
+ *
+ * @param thread_tbl Thread table
+ * @param num Number of threads to create
+ *
+ */
+void odph_linux_pthread_join(odph_linux_pthread_t *thread_tbl, int num);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/helper/platform/linux-generic/thread.c b/helper/linux/thread.c
index 90fa42ab3..52d4efc5e 100644
--- a/helper/platform/linux-generic/thread.c
+++ b/helper/linux/thread.c
@@ -20,7 +20,8 @@
#include <stdbool.h>
#include <odp_api.h>
-#include <odp/helper/platform/linux-generic/threads_extn.h>
+#include <odp/helper/linux/pthread.h>
+#include <odp/helper/linux/process.h>
#include "odph_debug.h"
static void *_odph_run_start_routine(void *arg)
@@ -42,45 +43,6 @@ static void *_odph_run_start_routine(void *arg)
return ret_ptr;
}
-static void *_odph_thread_run_start_routine(void *arg)
-{
- int status;
- int ret;
- odph_odpthread_params_t *thr_params;
-
- odph_odpthread_start_args_t *start_args = arg;
-
- thr_params = &start_args->thr_params;
-
- /* ODP thread local init */
- if (odp_init_local(thr_params->instance, thr_params->thr_type)) {
- ODPH_ERR("Local init failed\n");
- if (start_args->linuxtype == ODPTHREAD_PROCESS)
- _exit(EXIT_FAILURE);
- return (void *)-1;
- }
-
- ODPH_DBG("helper: ODP %s thread started as linux %s. (pid=%d)\n",
- thr_params->thr_type == ODP_THREAD_WORKER ?
- "worker" : "control",
- (start_args->linuxtype == ODPTHREAD_PTHREAD) ?
- "pthread" : "process",
- (int)getpid());
-
- status = thr_params->start(thr_params->arg);
- ret = odp_term_local();
-
- if (ret < 0)
- ODPH_ERR("Local term failed\n");
-
- /* for process implementation of odp threads, just return status... */
- if (start_args->linuxtype == ODPTHREAD_PROCESS)
- _exit(status);
-
- /* threads implementation return void* pointers: cast status to that. */
- return (void *)(intptr_t)status;
-}
-
int odph_linux_pthread_create(odph_linux_pthread_t *pthread_tbl,
const odp_cpumask_t *mask,
const odph_linux_thr_params_t *thr_params)
@@ -275,39 +237,3 @@ int odph_linux_process_wait_n(odph_linux_process_t *proc_tbl, int num)
return 0;
}
-
-/*
- * Create a single ODPthread as a linux thread
- */
-static int odph_linux_thread_create(odph_odpthread_t *thread_tbl,
- int cpu,
- const odph_odpthread_params_t *thr_params)
-{
- int ret;
- cpu_set_t cpu_set;
-
- CPU_ZERO(&cpu_set);
- CPU_SET(cpu, &cpu_set);
-
- pthread_attr_init(&thread_tbl->thread.attr);
-
- thread_tbl->cpu = cpu;
-
- pthread_attr_setaffinity_np(&thread_tbl->thread.attr,
- sizeof(cpu_set_t), &cpu_set);
-
- thread_tbl->start_args.thr_params = *thr_params; /* copy */
- thread_tbl->start_args.linuxtype = ODPTHREAD_PTHREAD;
-
- ret = pthread_create(&thread_tbl->thread.thread_id,
- &thread_tbl->thread.attr,
- _odph_thread_run_start_routine,
- &thread_tbl->start_args);
- if (ret != 0) {
- ODPH_ERR("Failed to start thread on cpu #%d\n", cpu);
- thread_tbl->start_args.linuxtype = ODPTHREAD_NOT_STARTED;
- return ret;
- }
-
- return 0;
-}
diff --git a/helper/m4/configure.m4 b/helper/m4/configure.m4
index 38c95d976..343f5e3cf 100644
--- a/helper/m4/configure.m4
+++ b/helper/m4/configure.m4
@@ -12,11 +12,11 @@ AC_ARG_ENABLE([test-helper],
# Enable/disable helper-ext
# platform specific non portable extensions
##########################################################################
-helper_extn=no
-AC_ARG_ENABLE([helper-extn],
- [ --enable-helper-extn build helper platform extensions (not portable)],
+helper_linux=no
+AC_ARG_ENABLE([helper-linux],
+ [ --enable-helper-linux build helper platform extensions (not portable)],
[if test "x$enableval" = "xyes"; then
- helper_extn=yes
+ helper_linux=yes
fi])
AC_CONFIG_FILES([helper/Makefile
diff --git a/helper/test/.gitignore b/helper/test/.gitignore
index e5b6a0f21..1a81e0047 100644
--- a/helper/test/.gitignore
+++ b/helper/test/.gitignore
@@ -8,3 +8,4 @@ parse
process
table
thread
+pthread
diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am
index 1337657f5..beef91913 100644
--- a/helper/test/Makefile.am
+++ b/helper/test/Makefile.am
@@ -5,12 +5,11 @@ LIB = $(top_builddir)/lib
#in the following line, the libs using the symbols should come before
#the libs containing them! The includer is given a chance to add things
#before libodp by setting PRE_LDADD before the inclusion.
-LDADD = $(PRE_LDADD) $(LIB)/libodphelper-@with_helper_platform@.la $(LIB)/libodp-linux.la
+LDADD = $(PRE_LDADD) $(LIB)/libodphelper.la $(LIB)/libodp-linux.la
INCFLAGS = \
-I$(top_builddir)/platform/@with_platform@/include \
-I$(top_srcdir)/helper/include \
- -I$(top_srcdir)/helper/platform/@with_helper_platform@/include \
-I$(top_srcdir)/include \
-I$(top_srcdir)/include/odp/arch/@ARCH_ABI@ \
-I$(top_srcdir)/platform/@with_platform@/include \
@@ -32,9 +31,9 @@ EXECUTABLES = chksum$(EXEEXT) \
#They are a convenience to app writers who have chosen to
#restrict their application to Linux.
-if helper_extn
-EXECUTABLES += @with_helper_platform@/thread$(EXEEXT) \
- @with_helper_platform@/process$(EXEEXT)
+if helper_linux
+EXECUTABLES += linux/pthread$(EXEEXT) \
+ linux/process$(EXEEXT)
endif
COMPILE_ONLY = odpthreads
diff --git a/helper/test/linux-generic/Makefile.am b/helper/test/linux-generic/Makefile.am
deleted file mode 100644
index 28d54a8be..000000000
--- a/helper/test/linux-generic/Makefile.am
+++ /dev/null
@@ -1,5 +0,0 @@
-
-thread_LDADD = $(LIB)/libodphelper-@with_helper_platform@.la $(LIB)/libodp-linux.la
-dist_thread_SOURCES = thread.c
-dist_process_SOURCES = process.c
-process_LDADD = $(LIB)/libodphelper-@with_helper_platform@.la $(LIB)/libodp-linux.la
diff --git a/helper/test/linux/Makefile.am b/helper/test/linux/Makefile.am
new file mode 100644
index 000000000..f95e04d51
--- /dev/null
+++ b/helper/test/linux/Makefile.am
@@ -0,0 +1,5 @@
+
+thread_LDADD = $(LIB)/libodphelper.la $(LIB)/libodp-linux.la
+dist_thread_SOURCES = pthread.c
+dist_process_SOURCES = process.c
+process_LDADD = $(LIB)/libodphelper.la $(LIB)/libodp-linux.la
diff --git a/helper/test/linux-generic/process.c b/helper/test/linux/process.c
index f9bdc3e82..e08ef8686 100644
--- a/helper/test/linux-generic/process.c
+++ b/helper/test/linux/process.c
@@ -6,7 +6,8 @@
#include <odph_debug.h>
#include <odp_api.h>
-#include <odp/helper/platform/linux-generic/threads_extn.h>
+#include <odp/helper/linux/pthread.h>
+#include <odp/helper/linux/process.h>
#define NUMBER_WORKERS 16 /* 0 = max */
diff --git a/helper/test/linux-generic/thread.c b/helper/test/linux/pthread.c
index 919f00eab..2bec0d178 100644
--- a/helper/test/linux-generic/thread.c
+++ b/helper/test/linux/pthread.c
@@ -6,7 +6,7 @@
#include <odph_debug.h>
#include <odp_api.h>
-#include <odp/helper/platform/linux-generic/threads_extn.h>
+#include <odp/helper/linux/pthread.h>
#define NUMBER_WORKERS 16
static void *worker_fn(void *arg ODPH_UNUSED)