Message ID | 20161212145230.11412-3-mike.holmes@linaro.org |
---|---|
State | New |
Headers | show |
did you use -M option to format-patch? Maxim. On 12/12/16 17:52, Mike Holmes wrote: > Signed-off-by: Mike Holmes <mike.holmes@linaro.org> > --- > helper/Makefile.am | 2 +- > helper/include/odp/helper/threads.h | 83 +------------- > helper/test/Makefile.am | 6 - > helper/test/process.c | 92 --------------- > helper/test/thread.c | 87 --------------- > helper/{linux.c => thread.c} | 216 ------------------------------------ > 6 files changed, 5 insertions(+), 481 deletions(-) > delete mode 100644 helper/test/process.c > delete mode 100644 helper/test/thread.c > rename helper/{linux.c => thread.c} (70%) > > diff --git a/helper/Makefile.am b/helper/Makefile.am > index 2153d70..942dd60 100644 > --- a/helper/Makefile.am > +++ b/helper/Makefile.am > @@ -35,7 +35,7 @@ __LIB__libodphelper_linux_la_SOURCES = \ > eth.c \ > ip.c \ > chksum.c \ > - linux.c \ > + thread.c \ > hashtable.c \ > lineartable.c > > diff --git a/helper/include/odp/helper/threads.h b/helper/include/odp/helper/threads.h > index 238bcf8..7c4b68a 100644 > --- a/helper/include/odp/helper/threads.h > +++ b/helper/include/odp/helper/threads.h > @@ -8,15 +8,15 @@ > /** > * @file > * > - * ODP Linux helper API > + * ODP thread helper API > * > * 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). > */ > > -#ifndef ODPH_LINUX_H_ > -#define ODPH_LINUX_H_ > +#ifndef ODPH_THREAD_H_ > +#define ODPH_THREAD_H_ > > #ifdef __cplusplus > extern "C" { > @@ -28,7 +28,7 @@ extern "C" { > #include <getopt.h> > #include <sys/types.h> > > -/** @addtogroup odph_linux ODPH LINUX > +/** @addtogroup odph_linux ODPH THREAD > * @{ > */ > > @@ -94,81 +94,6 @@ typedef struct { > }; > } odph_odpthread_t; > > -/** > - * 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' > - * thread parameters. > - * > - * @param[out] proc Pointer to process state info (for output) > - * @param cpu Destination CPU for the child process > - * @param thr_params Linux helper thread parameters > - * > - * @return On success: 1 for the parent, 0 for the child > - * On failure: -1 for the parent, -2 for the child > - */ > -int odph_linux_process_fork(odph_linux_process_t *proc, int cpu, > - const odph_linux_thr_params_t *thr_params); > - > - > -/** > - * Fork a number of processes > - * > - * Forks and sets CPU affinity for child processes. Ignores 'start' and 'arg' > - * thread parameters. > - * > - * @param[out] proc_tbl Process state info table (for output) > - * @param mask CPU mask of processes to create > - * @param thr_params Linux helper thread parameters > - * > - * @return On success: 1 for the parent, 0 for the child > - * On failure: -1 for the parent, -2 for the child > - */ > -int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl, > - const odp_cpumask_t *mask, > - const odph_linux_thr_params_t *thr_params); > - > - > -/** > - * Wait for a number of processes > - * > - * Waits for a number of child processes to terminate. Records process state > - * change status into the process state info structure. > - * > - * @param proc_tbl Process state info table (previously filled by fork) > - * @param num Number of processes to wait > - * > - * @return 0 on success, -1 on failure > - */ > -int odph_linux_process_wait_n(odph_linux_process_t *proc_tbl, int num); > > /** > * Creates and launches odpthreads (as linux threads or processes) > diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am > index 545db73..361e45d 100644 > --- a/helper/test/Makefile.am > +++ b/helper/test/Makefile.am > @@ -6,9 +6,7 @@ AM_LDFLAGS += -static > TESTS_ENVIRONMENT += TEST_DIR=${builddir} > > EXECUTABLES = chksum$(EXEEXT) \ > - thread$(EXEEXT) \ > parse$(EXEEXT)\ > - process$(EXEEXT)\ > table$(EXEEXT) > > COMPILE_ONLY = odpthreads > @@ -29,9 +27,5 @@ EXTRA_DIST = odpthreads_as_processes odpthreads_as_pthreads > dist_chksum_SOURCES = chksum.c > dist_odpthreads_SOURCES = odpthreads.c > odpthreads_LDADD = $(LIB)/libodphelper-linux.la $(LIB)/libodp-linux.la > -dist_thread_SOURCES = thread.c > -thread_LDADD = $(LIB)/libodphelper-linux.la $(LIB)/libodp-linux.la > -dist_process_SOURCES = process.c > dist_parse_SOURCES = parse.c > -process_LDADD = $(LIB)/libodphelper-linux.la $(LIB)/libodp-linux.la > dist_table_SOURCES = table.c > diff --git a/helper/test/process.c b/helper/test/process.c > deleted file mode 100644 > index 0e04224..0000000 > --- a/helper/test/process.c > +++ /dev/null > @@ -1,92 +0,0 @@ > -/* Copyright (c) 2015, Linaro Limited > - * All rights reserved. > - * > - * SPDX-License-Identifier: BSD-3-Clause > - */ > - > -#include <test_debug.h> > -#include <odp_api.h> > -#include <odp/helper/linux.h> > - > -#define NUMBER_WORKERS 16 /* 0 = max */ > - > -static void *worker_fn(void *arg TEST_UNUSED) > -{ > - /* depend on the odp helper to call odp_init_local */ > - printf("Worker thread on CPU %d\n", odp_cpu_id()); > - > - return 0; > -} > - > -/* Create additional dataplane processes */ > -int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) > -{ > - odp_cpumask_t cpu_mask; > - int num_workers; > - int cpu; > - char cpumaskstr[ODP_CPUMASK_STR_SIZE]; > - int ret; > - odph_linux_process_t proc[NUMBER_WORKERS]; > - odp_instance_t instance; > - odph_linux_thr_params_t thr_params; > - > - if (odp_init_global(&instance, NULL, NULL)) { > - LOG_ERR("Error: ODP global init failed.\n"); > - exit(EXIT_FAILURE); > - } > - > - if (odp_init_local(instance, ODP_THREAD_CONTROL)) { > - LOG_ERR("Error: ODP local init failed.\n"); > - exit(EXIT_FAILURE); > - } > - > - /* discover how many processes this system can support */ > - num_workers = odp_cpumask_default_worker(&cpu_mask, NUMBER_WORKERS); > - if (num_workers < NUMBER_WORKERS) { > - printf("System can only support %d processes and not the %d requested\n", > - num_workers, NUMBER_WORKERS); > - } > - > - /* generate a summary for the user */ > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, sizeof(cpumaskstr)); > - printf("default cpu mask: %s\n", cpumaskstr); > - printf("default num worker processes: %i\n", num_workers); > - > - cpu = odp_cpumask_first(&cpu_mask); > - printf("the first CPU: %i\n", cpu); > - > - /* reserve cpu 0 for the control plane so remove it from > - * the default mask */ > - odp_cpumask_clr(&cpu_mask, 0); > - num_workers = odp_cpumask_count(&cpu_mask); > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, sizeof(cpumaskstr)); > - printf("new cpu mask: %s\n", cpumaskstr); > - printf("new num worker processes: %i\n\n", num_workers); > - > - memset(&thr_params, 0, sizeof(thr_params)); > - thr_params.thr_type = ODP_THREAD_WORKER; > - thr_params.instance = instance; > - > - /* Fork worker processes */ > - ret = odph_linux_process_fork_n(proc, &cpu_mask, &thr_params); > - > - if (ret < 0) { > - LOG_ERR("Fork workers failed %i\n", ret); > - return -1; > - } > - > - if (ret == 0) { > - /* Child process */ > - worker_fn(NULL); > - } else { > - /* Parent process */ > - odph_linux_process_wait_n(proc, num_workers); > - > - if (odp_term_global(instance)) { > - LOG_ERR("Error: ODP global term failed.\n"); > - exit(EXIT_FAILURE); > - } > - } > - > - return 0; > -} > diff --git a/helper/test/thread.c b/helper/test/thread.c > deleted file mode 100644 > index 8268d9f..0000000 > --- a/helper/test/thread.c > +++ /dev/null > @@ -1,87 +0,0 @@ > -/* Copyright (c) 2015, Linaro Limited > - * All rights reserved. > - * > - * SPDX-License-Identifier: BSD-3-Clause > - */ > - > -#include <test_debug.h> > -#include <odp_api.h> > -#include <odp/helper/linux.h> > - > -#define NUMBER_WORKERS 16 > -static void *worker_fn(void *arg TEST_UNUSED) > -{ > - /* depend on the odp helper to call odp_init_local */ > - > - printf("Worker thread on CPU %d\n", odp_cpu_id()); > - > - /* depend on the odp helper to call odp_term_local */ > - > - return NULL; > -} > - > -/* Create additional dataplane threads */ > -int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) > -{ > - odph_linux_pthread_t thread_tbl[NUMBER_WORKERS]; > - odp_cpumask_t cpu_mask; > - int num_workers; > - int cpu; > - char cpumaskstr[ODP_CPUMASK_STR_SIZE]; > - odp_instance_t instance; > - odph_linux_thr_params_t thr_params; > - > - if (odp_init_global(&instance, NULL, NULL)) { > - LOG_ERR("Error: ODP global init failed.\n"); > - exit(EXIT_FAILURE); > - } > - > - if (odp_init_local(instance, ODP_THREAD_CONTROL)) { > - LOG_ERR("Error: ODP local init failed.\n"); > - exit(EXIT_FAILURE); > - } > - > - /* discover how many threads this system can support */ > - num_workers = odp_cpumask_default_worker(&cpu_mask, NUMBER_WORKERS); > - if (num_workers < NUMBER_WORKERS) { > - printf("System can only support %d threads and not the %d requested\n", > - num_workers, NUMBER_WORKERS); > - } > - > - /* generate a summary for the user */ > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, sizeof(cpumaskstr)); > - printf("default cpu mask: %s\n", cpumaskstr); > - printf("default num worker threads: %i\n", num_workers); > - > - cpu = odp_cpumask_first(&cpu_mask); > - printf("the first CPU: %i\n", cpu); > - > - /* reserve cpu 0 for the control plane so remove it from > - * the default mask */ > - odp_cpumask_clr(&cpu_mask, 0); > - num_workers = odp_cpumask_count(&cpu_mask); > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, sizeof(cpumaskstr)); > - printf("new cpu mask: %s\n", cpumaskstr); > - printf("new num worker threads: %i\n\n", num_workers); > - > - memset(&thr_params, 0, sizeof(thr_params)); > - thr_params.start = worker_fn; > - thr_params.arg = NULL; > - thr_params.thr_type = ODP_THREAD_WORKER; > - thr_params.instance = instance; > - > - odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, &thr_params); > - odph_linux_pthread_join(thread_tbl, num_workers); > - > - if (odp_term_local()) { > - LOG_ERR("Error: ODP local term failed.\n"); > - exit(EXIT_FAILURE); > - } > - > - if (odp_term_global(instance)) { > - LOG_ERR("Error: ODP global term failed.\n"); > - exit(EXIT_FAILURE); > - } > - > - return 0; > -} > diff --git a/helper/linux.c b/helper/thread.c > similarity index 70% > rename from helper/linux.c > rename to helper/thread.c > index d5215c2..f946f5a 100644 > --- a/helper/linux.c > +++ b/helper/thread.c > @@ -27,222 +27,6 @@ static struct { > int proc; /* true when process mode is required, false otherwise */ > } helper_options; > > -static void *odp_run_start_routine(void *arg) > -{ > - odph_linux_thr_params_t *thr_params = arg; > - > - /* ODP thread local init */ > - if (odp_init_local(thr_params->instance, thr_params->thr_type)) { > - ODPH_ERR("Local init failed\n"); > - return NULL; > - } > - > - void *ret_ptr = thr_params->start(thr_params->arg); > - int ret = odp_term_local(); > - > - if (ret < 0) > - ODPH_ERR("Local term failed\n"); > - else if (ret == 0 && odp_term_global(thr_params->instance)) > - ODPH_ERR("Global term failed\n"); > - > - return ret_ptr; > -} > - > -int odph_linux_pthread_create(odph_linux_pthread_t *pthread_tbl, > - const odp_cpumask_t *mask, > - const odph_linux_thr_params_t *thr_params) > -{ > - int i; > - int num; > - int cpu_count; > - int cpu; > - int ret; > - > - num = odp_cpumask_count(mask); > - > - memset(pthread_tbl, 0, num * sizeof(odph_linux_pthread_t)); > - > - cpu_count = odp_cpu_count(); > - > - if (num < 1 || num > cpu_count) { > - ODPH_ERR("Invalid number of threads:%d (%d cores available)\n", > - num, cpu_count); > - return 0; > - } > - > - cpu = odp_cpumask_first(mask); > - for (i = 0; i < num; i++) { > - cpu_set_t cpu_set; > - > - CPU_ZERO(&cpu_set); > - CPU_SET(cpu, &cpu_set); > - > - pthread_attr_init(&pthread_tbl[i].attr); > - > - pthread_tbl[i].cpu = cpu; > - > - pthread_attr_setaffinity_np(&pthread_tbl[i].attr, > - sizeof(cpu_set_t), &cpu_set); > - > - pthread_tbl[i].thr_params.start = thr_params->start; > - pthread_tbl[i].thr_params.arg = thr_params->arg; > - pthread_tbl[i].thr_params.thr_type = thr_params->thr_type; > - pthread_tbl[i].thr_params.instance = thr_params->instance; > - > - ret = pthread_create(&pthread_tbl[i].thread, > - &pthread_tbl[i].attr, > - odp_run_start_routine, > - &pthread_tbl[i].thr_params); > - if (ret != 0) { > - ODPH_ERR("Failed to start thread on cpu #%d\n", cpu); > - break; > - } > - > - cpu = odp_cpumask_next(mask, cpu); > - } > - > - return i; > -} > - > -void odph_linux_pthread_join(odph_linux_pthread_t *thread_tbl, int num) > -{ > - int i; > - int ret; > - > - for (i = 0; i < num; i++) { > - /* Wait thread to exit */ > - ret = pthread_join(thread_tbl[i].thread, NULL); > - if (ret != 0) { > - ODPH_ERR("Failed to join thread from cpu #%d\n", > - thread_tbl[i].cpu); > - } > - pthread_attr_destroy(&thread_tbl[i].attr); > - } > -} > - > -int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl, > - const odp_cpumask_t *mask, > - const odph_linux_thr_params_t *thr_params) > -{ > - pid_t pid; > - int num; > - int cpu_count; > - int cpu; > - int i; > - > - num = odp_cpumask_count(mask); > - > - memset(proc_tbl, 0, num * sizeof(odph_linux_process_t)); > - > - cpu_count = odp_cpu_count(); > - > - if (num < 1 || num > cpu_count) { > - ODPH_ERR("Bad num\n"); > - return -1; > - } > - > - cpu = odp_cpumask_first(mask); > - for (i = 0; i < num; i++) { > - cpu_set_t cpu_set; > - > - CPU_ZERO(&cpu_set); > - CPU_SET(cpu, &cpu_set); > - > - pid = fork(); > - > - if (pid < 0) { > - ODPH_ERR("fork() failed\n"); > - return -1; > - } > - > - /* Parent continues to fork */ > - if (pid > 0) { > - proc_tbl[i].pid = pid; > - proc_tbl[i].cpu = cpu; > - > - cpu = odp_cpumask_next(mask, cpu); > - continue; > - } > - > - /* Child process */ > - > - /* Request SIGTERM if parent dies */ > - prctl(PR_SET_PDEATHSIG, SIGTERM); > - /* Parent died already? */ > - if (getppid() == 1) > - kill(getpid(), SIGTERM); > - > - if (sched_setaffinity(0, sizeof(cpu_set_t), &cpu_set)) { > - ODPH_ERR("sched_setaffinity() failed\n"); > - return -2; > - } > - > - if (odp_init_local(thr_params->instance, > - thr_params->thr_type)) { > - ODPH_ERR("Local init failed\n"); > - return -2; > - } > - > - return 0; > - } > - > - return 1; > -} > - > -int odph_linux_process_fork(odph_linux_process_t *proc, int cpu, > - const odph_linux_thr_params_t *thr_params) > -{ > - odp_cpumask_t mask; > - > - odp_cpumask_zero(&mask); > - odp_cpumask_set(&mask, cpu); > - return odph_linux_process_fork_n(proc, &mask, thr_params); > -} > - > -int odph_linux_process_wait_n(odph_linux_process_t *proc_tbl, int num) > -{ > - pid_t pid; > - int i, j; > - int status = 0; > - > - for (i = 0; i < num; i++) { > - pid = wait(&status); > - > - if (pid < 0) { > - ODPH_ERR("wait() failed\n"); > - return -1; > - } > - > - for (j = 0; j < num; j++) { > - if (proc_tbl[j].pid == pid) { > - proc_tbl[j].status = status; > - break; > - } > - } > - > - if (j == num) { > - ODPH_ERR("Bad pid:%d\n", (int)pid); > - return -1; > - } > - > - /* Examine the child process' termination status */ > - if (WIFEXITED(status) && WEXITSTATUS(status) != EXIT_SUCCESS) { > - ODPH_ERR("Child exit status:%d (pid:%d)\n", > - WEXITSTATUS(status), (int)pid); > - return -1; > - } > - if (WIFSIGNALED(status)) { > - int signo = WTERMSIG(status); > - > - ODPH_ERR("Child term signo:%d - %s (pid:%d)\n", > - signo, strsignal(signo), (int)pid); > - return -1; > - } > - } > - > - return 0; > -} > - > /* > * wrapper for odpthreads, either implemented as linux threads or processes. > * (in process mode, if start_routine returns NULL, the process return FAILURE). >
On 12 December 2016 at 12:04, Maxim Uvarov <maxim.uvarov@linaro.org> wrote: > did you use -M option to format-patch? > I intended to - my history looks like I did 2047 git format-patch origin/master --cover-letter 2048 git format-patch origin/master --cover-letter -M 2049 history > > Maxim. > > On 12/12/16 17:52, Mike Holmes wrote: > > Signed-off-by: Mike Holmes <mike.holmes@linaro.org> > > --- > > helper/Makefile.am | 2 +- > > helper/include/odp/helper/threads.h | 83 +------------- > > helper/test/Makefile.am | 6 - > > helper/test/process.c | 92 --------------- > > helper/test/thread.c | 87 --------------- > > helper/{linux.c => thread.c} | 216 ------------------------------ > ------ > > 6 files changed, 5 insertions(+), 481 deletions(-) > > delete mode 100644 helper/test/process.c > > delete mode 100644 helper/test/thread.c > > rename helper/{linux.c => thread.c} (70%) > > > > diff --git a/helper/Makefile.am b/helper/Makefile.am > > index 2153d70..942dd60 100644 > > --- a/helper/Makefile.am > > +++ b/helper/Makefile.am > > @@ -35,7 +35,7 @@ __LIB__libodphelper_linux_la_SOURCES = \ > > eth.c \ > > ip.c \ > > chksum.c \ > > - linux.c \ > > + thread.c \ > > hashtable.c \ > > lineartable.c > > > > diff --git a/helper/include/odp/helper/threads.h > b/helper/include/odp/helper/threads.h > > index 238bcf8..7c4b68a 100644 > > --- a/helper/include/odp/helper/threads.h > > +++ b/helper/include/odp/helper/threads.h > > @@ -8,15 +8,15 @@ > > /** > > * @file > > * > > - * ODP Linux helper API > > + * ODP thread helper API > > * > > * 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). > > */ > > > > -#ifndef ODPH_LINUX_H_ > > -#define ODPH_LINUX_H_ > > +#ifndef ODPH_THREAD_H_ > > +#define ODPH_THREAD_H_ > > > > #ifdef __cplusplus > > extern "C" { > > @@ -28,7 +28,7 @@ extern "C" { > > #include <getopt.h> > > #include <sys/types.h> > > > > -/** @addtogroup odph_linux ODPH LINUX > > +/** @addtogroup odph_linux ODPH THREAD > > * @{ > > */ > > > > @@ -94,81 +94,6 @@ typedef struct { > > }; > > } odph_odpthread_t; > > > > -/** > > - * 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' > > - * thread parameters. > > - * > > - * @param[out] proc Pointer to process state info (for output) > > - * @param cpu Destination CPU for the child process > > - * @param thr_params Linux helper thread parameters > > - * > > - * @return On success: 1 for the parent, 0 for the child > > - * On failure: -1 for the parent, -2 for the child > > - */ > > -int odph_linux_process_fork(odph_linux_process_t *proc, int cpu, > > - const odph_linux_thr_params_t *thr_params); > > - > > - > > -/** > > - * Fork a number of processes > > - * > > - * Forks and sets CPU affinity for child processes. Ignores 'start' and > 'arg' > > - * thread parameters. > > - * > > - * @param[out] proc_tbl Process state info table (for output) > > - * @param mask CPU mask of processes to create > > - * @param thr_params Linux helper thread parameters > > - * > > - * @return On success: 1 for the parent, 0 for the child > > - * On failure: -1 for the parent, -2 for the child > > - */ > > -int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl, > > - const odp_cpumask_t *mask, > > - const odph_linux_thr_params_t *thr_params); > > - > > - > > -/** > > - * Wait for a number of processes > > - * > > - * Waits for a number of child processes to terminate. Records process > state > > - * change status into the process state info structure. > > - * > > - * @param proc_tbl Process state info table (previously filled by > fork) > > - * @param num Number of processes to wait > > - * > > - * @return 0 on success, -1 on failure > > - */ > > -int odph_linux_process_wait_n(odph_linux_process_t *proc_tbl, int num); > > > > /** > > * Creates and launches odpthreads (as linux threads or processes) > > diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am > > index 545db73..361e45d 100644 > > --- a/helper/test/Makefile.am > > +++ b/helper/test/Makefile.am > > @@ -6,9 +6,7 @@ AM_LDFLAGS += -static > > TESTS_ENVIRONMENT += TEST_DIR=${builddir} > > > > EXECUTABLES = chksum$(EXEEXT) \ > > - thread$(EXEEXT) \ > > parse$(EXEEXT)\ > > - process$(EXEEXT)\ > > table$(EXEEXT) > > > > COMPILE_ONLY = odpthreads > > @@ -29,9 +27,5 @@ EXTRA_DIST = odpthreads_as_processes > odpthreads_as_pthreads > > dist_chksum_SOURCES = chksum.c > > dist_odpthreads_SOURCES = odpthreads.c > > odpthreads_LDADD = $(LIB)/libodphelper-linux.la $(LIB)/libodp-linux.la > > -dist_thread_SOURCES = thread.c > > -thread_LDADD = $(LIB)/libodphelper-linux.la $(LIB)/libodp-linux.la > > -dist_process_SOURCES = process.c > > dist_parse_SOURCES = parse.c > > -process_LDADD = $(LIB)/libodphelper-linux.la $(LIB)/libodp-linux.la > > dist_table_SOURCES = table.c > > diff --git a/helper/test/process.c b/helper/test/process.c > > deleted file mode 100644 > > index 0e04224..0000000 > > --- a/helper/test/process.c > > +++ /dev/null > > @@ -1,92 +0,0 @@ > > -/* Copyright (c) 2015, Linaro Limited > > - * All rights reserved. > > - * > > - * SPDX-License-Identifier: BSD-3-Clause > > - */ > > - > > -#include <test_debug.h> > > -#include <odp_api.h> > > -#include <odp/helper/linux.h> > > - > > -#define NUMBER_WORKERS 16 /* 0 = max */ > > - > > -static void *worker_fn(void *arg TEST_UNUSED) > > -{ > > - /* depend on the odp helper to call odp_init_local */ > > - printf("Worker thread on CPU %d\n", odp_cpu_id()); > > - > > - return 0; > > -} > > - > > -/* Create additional dataplane processes */ > > -int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) > > -{ > > - odp_cpumask_t cpu_mask; > > - int num_workers; > > - int cpu; > > - char cpumaskstr[ODP_CPUMASK_STR_SIZE]; > > - int ret; > > - odph_linux_process_t proc[NUMBER_WORKERS]; > > - odp_instance_t instance; > > - odph_linux_thr_params_t thr_params; > > - > > - if (odp_init_global(&instance, NULL, NULL)) { > > - LOG_ERR("Error: ODP global init failed.\n"); > > - exit(EXIT_FAILURE); > > - } > > - > > - if (odp_init_local(instance, ODP_THREAD_CONTROL)) { > > - LOG_ERR("Error: ODP local init failed.\n"); > > - exit(EXIT_FAILURE); > > - } > > - > > - /* discover how many processes this system can support */ > > - num_workers = odp_cpumask_default_worker(&cpu_mask, > NUMBER_WORKERS); > > - if (num_workers < NUMBER_WORKERS) { > > - printf("System can only support %d processes and not the > %d requested\n", > > - num_workers, NUMBER_WORKERS); > > - } > > - > > - /* generate a summary for the user */ > > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, > sizeof(cpumaskstr)); > > - printf("default cpu mask: %s\n", cpumaskstr); > > - printf("default num worker processes: %i\n", num_workers); > > - > > - cpu = odp_cpumask_first(&cpu_mask); > > - printf("the first CPU: %i\n", cpu); > > - > > - /* reserve cpu 0 for the control plane so remove it from > > - * the default mask */ > > - odp_cpumask_clr(&cpu_mask, 0); > > - num_workers = odp_cpumask_count(&cpu_mask); > > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, > sizeof(cpumaskstr)); > > - printf("new cpu mask: %s\n", cpumaskstr); > > - printf("new num worker processes: %i\n\n", num_workers); > > - > > - memset(&thr_params, 0, sizeof(thr_params)); > > - thr_params.thr_type = ODP_THREAD_WORKER; > > - thr_params.instance = instance; > > - > > - /* Fork worker processes */ > > - ret = odph_linux_process_fork_n(proc, &cpu_mask, &thr_params); > > - > > - if (ret < 0) { > > - LOG_ERR("Fork workers failed %i\n", ret); > > - return -1; > > - } > > - > > - if (ret == 0) { > > - /* Child process */ > > - worker_fn(NULL); > > - } else { > > - /* Parent process */ > > - odph_linux_process_wait_n(proc, num_workers); > > - > > - if (odp_term_global(instance)) { > > - LOG_ERR("Error: ODP global term failed.\n"); > > - exit(EXIT_FAILURE); > > - } > > - } > > - > > - return 0; > > -} > > diff --git a/helper/test/thread.c b/helper/test/thread.c > > deleted file mode 100644 > > index 8268d9f..0000000 > > --- a/helper/test/thread.c > > +++ /dev/null > > @@ -1,87 +0,0 @@ > > -/* Copyright (c) 2015, Linaro Limited > > - * All rights reserved. > > - * > > - * SPDX-License-Identifier: BSD-3-Clause > > - */ > > - > > -#include <test_debug.h> > > -#include <odp_api.h> > > -#include <odp/helper/linux.h> > > - > > -#define NUMBER_WORKERS 16 > > -static void *worker_fn(void *arg TEST_UNUSED) > > -{ > > - /* depend on the odp helper to call odp_init_local */ > > - > > - printf("Worker thread on CPU %d\n", odp_cpu_id()); > > - > > - /* depend on the odp helper to call odp_term_local */ > > - > > - return NULL; > > -} > > - > > -/* Create additional dataplane threads */ > > -int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) > > -{ > > - odph_linux_pthread_t thread_tbl[NUMBER_WORKERS]; > > - odp_cpumask_t cpu_mask; > > - int num_workers; > > - int cpu; > > - char cpumaskstr[ODP_CPUMASK_STR_SIZE]; > > - odp_instance_t instance; > > - odph_linux_thr_params_t thr_params; > > - > > - if (odp_init_global(&instance, NULL, NULL)) { > > - LOG_ERR("Error: ODP global init failed.\n"); > > - exit(EXIT_FAILURE); > > - } > > - > > - if (odp_init_local(instance, ODP_THREAD_CONTROL)) { > > - LOG_ERR("Error: ODP local init failed.\n"); > > - exit(EXIT_FAILURE); > > - } > > - > > - /* discover how many threads this system can support */ > > - num_workers = odp_cpumask_default_worker(&cpu_mask, > NUMBER_WORKERS); > > - if (num_workers < NUMBER_WORKERS) { > > - printf("System can only support %d threads and not the %d > requested\n", > > - num_workers, NUMBER_WORKERS); > > - } > > - > > - /* generate a summary for the user */ > > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, > sizeof(cpumaskstr)); > > - printf("default cpu mask: %s\n", cpumaskstr); > > - printf("default num worker threads: %i\n", num_workers); > > - > > - cpu = odp_cpumask_first(&cpu_mask); > > - printf("the first CPU: %i\n", cpu); > > - > > - /* reserve cpu 0 for the control plane so remove it from > > - * the default mask */ > > - odp_cpumask_clr(&cpu_mask, 0); > > - num_workers = odp_cpumask_count(&cpu_mask); > > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, > sizeof(cpumaskstr)); > > - printf("new cpu mask: %s\n", cpumaskstr); > > - printf("new num worker threads: %i\n\n", num_workers); > > - > > - memset(&thr_params, 0, sizeof(thr_params)); > > - thr_params.start = worker_fn; > > - thr_params.arg = NULL; > > - thr_params.thr_type = ODP_THREAD_WORKER; > > - thr_params.instance = instance; > > - > > - odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, &thr_params); > > - odph_linux_pthread_join(thread_tbl, num_workers); > > - > > - if (odp_term_local()) { > > - LOG_ERR("Error: ODP local term failed.\n"); > > - exit(EXIT_FAILURE); > > - } > > - > > - if (odp_term_global(instance)) { > > - LOG_ERR("Error: ODP global term failed.\n"); > > - exit(EXIT_FAILURE); > > - } > > - > > - return 0; > > -} > > diff --git a/helper/linux.c b/helper/thread.c > > similarity index 70% > > rename from helper/linux.c > > rename to helper/thread.c > > index d5215c2..f946f5a 100644 > > --- a/helper/linux.c > > +++ b/helper/thread.c > > @@ -27,222 +27,6 @@ static struct { > > int proc; /* true when process mode is required, false otherwise */ > > } helper_options; > > > > -static void *odp_run_start_routine(void *arg) > > -{ > > - odph_linux_thr_params_t *thr_params = arg; > > - > > - /* ODP thread local init */ > > - if (odp_init_local(thr_params->instance, thr_params->thr_type)) { > > - ODPH_ERR("Local init failed\n"); > > - return NULL; > > - } > > - > > - void *ret_ptr = thr_params->start(thr_params->arg); > > - int ret = odp_term_local(); > > - > > - if (ret < 0) > > - ODPH_ERR("Local term failed\n"); > > - else if (ret == 0 && odp_term_global(thr_params->instance)) > > - ODPH_ERR("Global term failed\n"); > > - > > - return ret_ptr; > > -} > > - > > -int odph_linux_pthread_create(odph_linux_pthread_t *pthread_tbl, > > - const odp_cpumask_t *mask, > > - const odph_linux_thr_params_t *thr_params) > > -{ > > - int i; > > - int num; > > - int cpu_count; > > - int cpu; > > - int ret; > > - > > - num = odp_cpumask_count(mask); > > - > > - memset(pthread_tbl, 0, num * sizeof(odph_linux_pthread_t)); > > - > > - cpu_count = odp_cpu_count(); > > - > > - if (num < 1 || num > cpu_count) { > > - ODPH_ERR("Invalid number of threads:%d (%d cores > available)\n", > > - num, cpu_count); > > - return 0; > > - } > > - > > - cpu = odp_cpumask_first(mask); > > - for (i = 0; i < num; i++) { > > - cpu_set_t cpu_set; > > - > > - CPU_ZERO(&cpu_set); > > - CPU_SET(cpu, &cpu_set); > > - > > - pthread_attr_init(&pthread_tbl[i].attr); > > - > > - pthread_tbl[i].cpu = cpu; > > - > > - pthread_attr_setaffinity_np(&pthread_tbl[i].attr, > > - sizeof(cpu_set_t), &cpu_set); > > - > > - pthread_tbl[i].thr_params.start = thr_params->start; > > - pthread_tbl[i].thr_params.arg = thr_params->arg; > > - pthread_tbl[i].thr_params.thr_type = thr_params->thr_type; > > - pthread_tbl[i].thr_params.instance = thr_params->instance; > > - > > - ret = pthread_create(&pthread_tbl[i].thread, > > - &pthread_tbl[i].attr, > > - odp_run_start_routine, > > - &pthread_tbl[i].thr_params); > > - if (ret != 0) { > > - ODPH_ERR("Failed to start thread on cpu #%d\n", > cpu); > > - break; > > - } > > - > > - cpu = odp_cpumask_next(mask, cpu); > > - } > > - > > - return i; > > -} > > - > > -void odph_linux_pthread_join(odph_linux_pthread_t *thread_tbl, int num) > > -{ > > - int i; > > - int ret; > > - > > - for (i = 0; i < num; i++) { > > - /* Wait thread to exit */ > > - ret = pthread_join(thread_tbl[i].thread, NULL); > > - if (ret != 0) { > > - ODPH_ERR("Failed to join thread from cpu #%d\n", > > - thread_tbl[i].cpu); > > - } > > - pthread_attr_destroy(&thread_tbl[i].attr); > > - } > > -} > > - > > -int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl, > > - const odp_cpumask_t *mask, > > - const odph_linux_thr_params_t *thr_params) > > -{ > > - pid_t pid; > > - int num; > > - int cpu_count; > > - int cpu; > > - int i; > > - > > - num = odp_cpumask_count(mask); > > - > > - memset(proc_tbl, 0, num * sizeof(odph_linux_process_t)); > > - > > - cpu_count = odp_cpu_count(); > > - > > - if (num < 1 || num > cpu_count) { > > - ODPH_ERR("Bad num\n"); > > - return -1; > > - } > > - > > - cpu = odp_cpumask_first(mask); > > - for (i = 0; i < num; i++) { > > - cpu_set_t cpu_set; > > - > > - CPU_ZERO(&cpu_set); > > - CPU_SET(cpu, &cpu_set); > > - > > - pid = fork(); > > - > > - if (pid < 0) { > > - ODPH_ERR("fork() failed\n"); > > - return -1; > > - } > > - > > - /* Parent continues to fork */ > > - if (pid > 0) { > > - proc_tbl[i].pid = pid; > > - proc_tbl[i].cpu = cpu; > > - > > - cpu = odp_cpumask_next(mask, cpu); > > - continue; > > - } > > - > > - /* Child process */ > > - > > - /* Request SIGTERM if parent dies */ > > - prctl(PR_SET_PDEATHSIG, SIGTERM); > > - /* Parent died already? */ > > - if (getppid() == 1) > > - kill(getpid(), SIGTERM); > > - > > - if (sched_setaffinity(0, sizeof(cpu_set_t), &cpu_set)) { > > - ODPH_ERR("sched_setaffinity() failed\n"); > > - return -2; > > - } > > - > > - if (odp_init_local(thr_params->instance, > > - thr_params->thr_type)) { > > - ODPH_ERR("Local init failed\n"); > > - return -2; > > - } > > - > > - return 0; > > - } > > - > > - return 1; > > -} > > - > > -int odph_linux_process_fork(odph_linux_process_t *proc, int cpu, > > - const odph_linux_thr_params_t *thr_params) > > -{ > > - odp_cpumask_t mask; > > - > > - odp_cpumask_zero(&mask); > > - odp_cpumask_set(&mask, cpu); > > - return odph_linux_process_fork_n(proc, &mask, thr_params); > > -} > > - > > -int odph_linux_process_wait_n(odph_linux_process_t *proc_tbl, int num) > > -{ > > - pid_t pid; > > - int i, j; > > - int status = 0; > > - > > - for (i = 0; i < num; i++) { > > - pid = wait(&status); > > - > > - if (pid < 0) { > > - ODPH_ERR("wait() failed\n"); > > - return -1; > > - } > > - > > - for (j = 0; j < num; j++) { > > - if (proc_tbl[j].pid == pid) { > > - proc_tbl[j].status = status; > > - break; > > - } > > - } > > - > > - if (j == num) { > > - ODPH_ERR("Bad pid:%d\n", (int)pid); > > - return -1; > > - } > > - > > - /* Examine the child process' termination status */ > > - if (WIFEXITED(status) && WEXITSTATUS(status) != > EXIT_SUCCESS) { > > - ODPH_ERR("Child exit status:%d (pid:%d)\n", > > - WEXITSTATUS(status), (int)pid); > > - return -1; > > - } > > - if (WIFSIGNALED(status)) { > > - int signo = WTERMSIG(status); > > - > > - ODPH_ERR("Child term signo:%d - %s (pid:%d)\n", > > - signo, strsignal(signo), (int)pid); > > - return -1; > > - } > > - } > > - > > - return 0; > > -} > > - > > /* > > * wrapper for odpthreads, either implemented as linux threads or > processes. > > * (in process mode, if start_routine returns NULL, the process return > FAILURE). > > > > -- Mike Holmes Program Manager - Linaro Networking Group Linaro.org <http://www.linaro.org/> *│ *Open source software for ARM SoCs "Work should be fun and collaborative, the rest follows"
Why that question? The files are deleted, what would you expect -M to do, Maxim? -M would track move, but deletion would not be affected, would they? Christophe On 12 December 2016 at 18:49, Mike Holmes <mike.holmes@linaro.org> wrote: > On 12 December 2016 at 12:04, Maxim Uvarov <maxim.uvarov@linaro.org> > wrote: > > > did you use -M option to format-patch? > > > > I intended to - my history looks like I did > > > 2047 git format-patch origin/master --cover-letter > 2048 git format-patch origin/master --cover-letter -M > 2049 history > > > > > > > > > Maxim. > > > > On 12/12/16 17:52, Mike Holmes wrote: > > > Signed-off-by: Mike Holmes <mike.holmes@linaro.org> > > > --- > > > helper/Makefile.am | 2 +- > > > helper/include/odp/helper/threads.h | 83 +------------- > > > helper/test/Makefile.am | 6 - > > > helper/test/process.c | 92 --------------- > > > helper/test/thread.c | 87 --------------- > > > helper/{linux.c => thread.c} | 216 > ------------------------------ > > ------ > > > 6 files changed, 5 insertions(+), 481 deletions(-) > > > delete mode 100644 helper/test/process.c > > > delete mode 100644 helper/test/thread.c > > > rename helper/{linux.c => thread.c} (70%) > > > > > > diff --git a/helper/Makefile.am b/helper/Makefile.am > > > index 2153d70..942dd60 100644 > > > --- a/helper/Makefile.am > > > +++ b/helper/Makefile.am > > > @@ -35,7 +35,7 @@ __LIB__libodphelper_linux_la_SOURCES = \ > > > eth.c \ > > > ip.c \ > > > chksum.c \ > > > - linux.c \ > > > + thread.c \ > > > hashtable.c \ > > > lineartable.c > > > > > > diff --git a/helper/include/odp/helper/threads.h > > b/helper/include/odp/helper/threads.h > > > index 238bcf8..7c4b68a 100644 > > > --- a/helper/include/odp/helper/threads.h > > > +++ b/helper/include/odp/helper/threads.h > > > @@ -8,15 +8,15 @@ > > > /** > > > * @file > > > * > > > - * ODP Linux helper API > > > + * ODP thread helper API > > > * > > > * 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). > > > */ > > > > > > -#ifndef ODPH_LINUX_H_ > > > -#define ODPH_LINUX_H_ > > > +#ifndef ODPH_THREAD_H_ > > > +#define ODPH_THREAD_H_ > > > > > > #ifdef __cplusplus > > > extern "C" { > > > @@ -28,7 +28,7 @@ extern "C" { > > > #include <getopt.h> > > > #include <sys/types.h> > > > > > > -/** @addtogroup odph_linux ODPH LINUX > > > +/** @addtogroup odph_linux ODPH THREAD > > > * @{ > > > */ > > > > > > @@ -94,81 +94,6 @@ typedef struct { > > > }; > > > } odph_odpthread_t; > > > > > > -/** > > > - * 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' > > > - * thread parameters. > > > - * > > > - * @param[out] proc Pointer to process state info (for output) > > > - * @param cpu Destination CPU for the child process > > > - * @param thr_params Linux helper thread parameters > > > - * > > > - * @return On success: 1 for the parent, 0 for the child > > > - * On failure: -1 for the parent, -2 for the child > > > - */ > > > -int odph_linux_process_fork(odph_linux_process_t *proc, int cpu, > > > - const odph_linux_thr_params_t *thr_params); > > > - > > > - > > > -/** > > > - * Fork a number of processes > > > - * > > > - * Forks and sets CPU affinity for child processes. Ignores 'start' > and > > 'arg' > > > - * thread parameters. > > > - * > > > - * @param[out] proc_tbl Process state info table (for output) > > > - * @param mask CPU mask of processes to create > > > - * @param thr_params Linux helper thread parameters > > > - * > > > - * @return On success: 1 for the parent, 0 for the child > > > - * On failure: -1 for the parent, -2 for the child > > > - */ > > > -int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl, > > > - const odp_cpumask_t *mask, > > > - const odph_linux_thr_params_t *thr_params); > > > - > > > - > > > -/** > > > - * Wait for a number of processes > > > - * > > > - * Waits for a number of child processes to terminate. Records process > > state > > > - * change status into the process state info structure. > > > - * > > > - * @param proc_tbl Process state info table (previously filled by > > fork) > > > - * @param num Number of processes to wait > > > - * > > > - * @return 0 on success, -1 on failure > > > - */ > > > -int odph_linux_process_wait_n(odph_linux_process_t *proc_tbl, int > num); > > > > > > /** > > > * Creates and launches odpthreads (as linux threads or processes) > > > diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am > > > index 545db73..361e45d 100644 > > > --- a/helper/test/Makefile.am > > > +++ b/helper/test/Makefile.am > > > @@ -6,9 +6,7 @@ AM_LDFLAGS += -static > > > TESTS_ENVIRONMENT += TEST_DIR=${builddir} > > > > > > EXECUTABLES = chksum$(EXEEXT) \ > > > - thread$(EXEEXT) \ > > > parse$(EXEEXT)\ > > > - process$(EXEEXT)\ > > > table$(EXEEXT) > > > > > > COMPILE_ONLY = odpthreads > > > @@ -29,9 +27,5 @@ EXTRA_DIST = odpthreads_as_processes > > odpthreads_as_pthreads > > > dist_chksum_SOURCES = chksum.c > > > dist_odpthreads_SOURCES = odpthreads.c > > > odpthreads_LDADD = $(LIB)/libodphelper-linux.la $(LIB)/ > libodp-linux.la > > > -dist_thread_SOURCES = thread.c > > > -thread_LDADD = $(LIB)/libodphelper-linux.la $(LIB)/libodp-linux.la > > > -dist_process_SOURCES = process.c > > > dist_parse_SOURCES = parse.c > > > -process_LDADD = $(LIB)/libodphelper-linux.la $(LIB)/libodp-linux.la > > > dist_table_SOURCES = table.c > > > diff --git a/helper/test/process.c b/helper/test/process.c > > > deleted file mode 100644 > > > index 0e04224..0000000 > > > --- a/helper/test/process.c > > > +++ /dev/null > > > @@ -1,92 +0,0 @@ > > > -/* Copyright (c) 2015, Linaro Limited > > > - * All rights reserved. > > > - * > > > - * SPDX-License-Identifier: BSD-3-Clause > > > - */ > > > - > > > -#include <test_debug.h> > > > -#include <odp_api.h> > > > -#include <odp/helper/linux.h> > > > - > > > -#define NUMBER_WORKERS 16 /* 0 = max */ > > > - > > > -static void *worker_fn(void *arg TEST_UNUSED) > > > -{ > > > - /* depend on the odp helper to call odp_init_local */ > > > - printf("Worker thread on CPU %d\n", odp_cpu_id()); > > > - > > > - return 0; > > > -} > > > - > > > -/* Create additional dataplane processes */ > > > -int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) > > > -{ > > > - odp_cpumask_t cpu_mask; > > > - int num_workers; > > > - int cpu; > > > - char cpumaskstr[ODP_CPUMASK_STR_SIZE]; > > > - int ret; > > > - odph_linux_process_t proc[NUMBER_WORKERS]; > > > - odp_instance_t instance; > > > - odph_linux_thr_params_t thr_params; > > > - > > > - if (odp_init_global(&instance, NULL, NULL)) { > > > - LOG_ERR("Error: ODP global init failed.\n"); > > > - exit(EXIT_FAILURE); > > > - } > > > - > > > - if (odp_init_local(instance, ODP_THREAD_CONTROL)) { > > > - LOG_ERR("Error: ODP local init failed.\n"); > > > - exit(EXIT_FAILURE); > > > - } > > > - > > > - /* discover how many processes this system can support */ > > > - num_workers = odp_cpumask_default_worker(&cpu_mask, > > NUMBER_WORKERS); > > > - if (num_workers < NUMBER_WORKERS) { > > > - printf("System can only support %d processes and not the > > %d requested\n", > > > - num_workers, NUMBER_WORKERS); > > > - } > > > - > > > - /* generate a summary for the user */ > > > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, > > sizeof(cpumaskstr)); > > > - printf("default cpu mask: %s\n", cpumaskstr); > > > - printf("default num worker processes: %i\n", num_workers); > > > - > > > - cpu = odp_cpumask_first(&cpu_mask); > > > - printf("the first CPU: %i\n", cpu); > > > - > > > - /* reserve cpu 0 for the control plane so remove it from > > > - * the default mask */ > > > - odp_cpumask_clr(&cpu_mask, 0); > > > - num_workers = odp_cpumask_count(&cpu_mask); > > > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, > > sizeof(cpumaskstr)); > > > - printf("new cpu mask: %s\n", cpumaskstr); > > > - printf("new num worker processes: %i\n\n", num_workers); > > > - > > > - memset(&thr_params, 0, sizeof(thr_params)); > > > - thr_params.thr_type = ODP_THREAD_WORKER; > > > - thr_params.instance = instance; > > > - > > > - /* Fork worker processes */ > > > - ret = odph_linux_process_fork_n(proc, &cpu_mask, &thr_params); > > > - > > > - if (ret < 0) { > > > - LOG_ERR("Fork workers failed %i\n", ret); > > > - return -1; > > > - } > > > - > > > - if (ret == 0) { > > > - /* Child process */ > > > - worker_fn(NULL); > > > - } else { > > > - /* Parent process */ > > > - odph_linux_process_wait_n(proc, num_workers); > > > - > > > - if (odp_term_global(instance)) { > > > - LOG_ERR("Error: ODP global term failed.\n"); > > > - exit(EXIT_FAILURE); > > > - } > > > - } > > > - > > > - return 0; > > > -} > > > diff --git a/helper/test/thread.c b/helper/test/thread.c > > > deleted file mode 100644 > > > index 8268d9f..0000000 > > > --- a/helper/test/thread.c > > > +++ /dev/null > > > @@ -1,87 +0,0 @@ > > > -/* Copyright (c) 2015, Linaro Limited > > > - * All rights reserved. > > > - * > > > - * SPDX-License-Identifier: BSD-3-Clause > > > - */ > > > - > > > -#include <test_debug.h> > > > -#include <odp_api.h> > > > -#include <odp/helper/linux.h> > > > - > > > -#define NUMBER_WORKERS 16 > > > -static void *worker_fn(void *arg TEST_UNUSED) > > > -{ > > > - /* depend on the odp helper to call odp_init_local */ > > > - > > > - printf("Worker thread on CPU %d\n", odp_cpu_id()); > > > - > > > - /* depend on the odp helper to call odp_term_local */ > > > - > > > - return NULL; > > > -} > > > - > > > -/* Create additional dataplane threads */ > > > -int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) > > > -{ > > > - odph_linux_pthread_t thread_tbl[NUMBER_WORKERS]; > > > - odp_cpumask_t cpu_mask; > > > - int num_workers; > > > - int cpu; > > > - char cpumaskstr[ODP_CPUMASK_STR_SIZE]; > > > - odp_instance_t instance; > > > - odph_linux_thr_params_t thr_params; > > > - > > > - if (odp_init_global(&instance, NULL, NULL)) { > > > - LOG_ERR("Error: ODP global init failed.\n"); > > > - exit(EXIT_FAILURE); > > > - } > > > - > > > - if (odp_init_local(instance, ODP_THREAD_CONTROL)) { > > > - LOG_ERR("Error: ODP local init failed.\n"); > > > - exit(EXIT_FAILURE); > > > - } > > > - > > > - /* discover how many threads this system can support */ > > > - num_workers = odp_cpumask_default_worker(&cpu_mask, > > NUMBER_WORKERS); > > > - if (num_workers < NUMBER_WORKERS) { > > > - printf("System can only support %d threads and not the %d > > requested\n", > > > - num_workers, NUMBER_WORKERS); > > > - } > > > - > > > - /* generate a summary for the user */ > > > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, > > sizeof(cpumaskstr)); > > > - printf("default cpu mask: %s\n", cpumaskstr); > > > - printf("default num worker threads: %i\n", num_workers); > > > - > > > - cpu = odp_cpumask_first(&cpu_mask); > > > - printf("the first CPU: %i\n", cpu); > > > - > > > - /* reserve cpu 0 for the control plane so remove it from > > > - * the default mask */ > > > - odp_cpumask_clr(&cpu_mask, 0); > > > - num_workers = odp_cpumask_count(&cpu_mask); > > > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, > > sizeof(cpumaskstr)); > > > - printf("new cpu mask: %s\n", cpumaskstr); > > > - printf("new num worker threads: %i\n\n", num_workers); > > > - > > > - memset(&thr_params, 0, sizeof(thr_params)); > > > - thr_params.start = worker_fn; > > > - thr_params.arg = NULL; > > > - thr_params.thr_type = ODP_THREAD_WORKER; > > > - thr_params.instance = instance; > > > - > > > - odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, > &thr_params); > > > - odph_linux_pthread_join(thread_tbl, num_workers); > > > - > > > - if (odp_term_local()) { > > > - LOG_ERR("Error: ODP local term failed.\n"); > > > - exit(EXIT_FAILURE); > > > - } > > > - > > > - if (odp_term_global(instance)) { > > > - LOG_ERR("Error: ODP global term failed.\n"); > > > - exit(EXIT_FAILURE); > > > - } > > > - > > > - return 0; > > > -} > > > diff --git a/helper/linux.c b/helper/thread.c > > > similarity index 70% > > > rename from helper/linux.c > > > rename to helper/thread.c > > > index d5215c2..f946f5a 100644 > > > --- a/helper/linux.c > > > +++ b/helper/thread.c > > > @@ -27,222 +27,6 @@ static struct { > > > int proc; /* true when process mode is required, false otherwise > */ > > > } helper_options; > > > > > > -static void *odp_run_start_routine(void *arg) > > > -{ > > > - odph_linux_thr_params_t *thr_params = arg; > > > - > > > - /* ODP thread local init */ > > > - if (odp_init_local(thr_params->instance, thr_params->thr_type)) > { > > > - ODPH_ERR("Local init failed\n"); > > > - return NULL; > > > - } > > > - > > > - void *ret_ptr = thr_params->start(thr_params->arg); > > > - int ret = odp_term_local(); > > > - > > > - if (ret < 0) > > > - ODPH_ERR("Local term failed\n"); > > > - else if (ret == 0 && odp_term_global(thr_params->instance)) > > > - ODPH_ERR("Global term failed\n"); > > > - > > > - return ret_ptr; > > > -} > > > - > > > -int odph_linux_pthread_create(odph_linux_pthread_t *pthread_tbl, > > > - const odp_cpumask_t *mask, > > > - const odph_linux_thr_params_t *thr_params) > > > -{ > > > - int i; > > > - int num; > > > - int cpu_count; > > > - int cpu; > > > - int ret; > > > - > > > - num = odp_cpumask_count(mask); > > > - > > > - memset(pthread_tbl, 0, num * sizeof(odph_linux_pthread_t)); > > > - > > > - cpu_count = odp_cpu_count(); > > > - > > > - if (num < 1 || num > cpu_count) { > > > - ODPH_ERR("Invalid number of threads:%d (%d cores > > available)\n", > > > - num, cpu_count); > > > - return 0; > > > - } > > > - > > > - cpu = odp_cpumask_first(mask); > > > - for (i = 0; i < num; i++) { > > > - cpu_set_t cpu_set; > > > - > > > - CPU_ZERO(&cpu_set); > > > - CPU_SET(cpu, &cpu_set); > > > - > > > - pthread_attr_init(&pthread_tbl[i].attr); > > > - > > > - pthread_tbl[i].cpu = cpu; > > > - > > > - pthread_attr_setaffinity_np(&pthread_tbl[i].attr, > > > - sizeof(cpu_set_t), &cpu_set); > > > - > > > - pthread_tbl[i].thr_params.start = thr_params->start; > > > - pthread_tbl[i].thr_params.arg = thr_params->arg; > > > - pthread_tbl[i].thr_params.thr_type = > thr_params->thr_type; > > > - pthread_tbl[i].thr_params.instance = > thr_params->instance; > > > - > > > - ret = pthread_create(&pthread_tbl[i].thread, > > > - &pthread_tbl[i].attr, > > > - odp_run_start_routine, > > > - &pthread_tbl[i].thr_params); > > > - if (ret != 0) { > > > - ODPH_ERR("Failed to start thread on cpu #%d\n", > > cpu); > > > - break; > > > - } > > > - > > > - cpu = odp_cpumask_next(mask, cpu); > > > - } > > > - > > > - return i; > > > -} > > > - > > > -void odph_linux_pthread_join(odph_linux_pthread_t *thread_tbl, int > num) > > > -{ > > > - int i; > > > - int ret; > > > - > > > - for (i = 0; i < num; i++) { > > > - /* Wait thread to exit */ > > > - ret = pthread_join(thread_tbl[i].thread, NULL); > > > - if (ret != 0) { > > > - ODPH_ERR("Failed to join thread from cpu #%d\n", > > > - thread_tbl[i].cpu); > > > - } > > > - pthread_attr_destroy(&thread_tbl[i].attr); > > > - } > > > -} > > > - > > > -int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl, > > > - const odp_cpumask_t *mask, > > > - const odph_linux_thr_params_t *thr_params) > > > -{ > > > - pid_t pid; > > > - int num; > > > - int cpu_count; > > > - int cpu; > > > - int i; > > > - > > > - num = odp_cpumask_count(mask); > > > - > > > - memset(proc_tbl, 0, num * sizeof(odph_linux_process_t)); > > > - > > > - cpu_count = odp_cpu_count(); > > > - > > > - if (num < 1 || num > cpu_count) { > > > - ODPH_ERR("Bad num\n"); > > > - return -1; > > > - } > > > - > > > - cpu = odp_cpumask_first(mask); > > > - for (i = 0; i < num; i++) { > > > - cpu_set_t cpu_set; > > > - > > > - CPU_ZERO(&cpu_set); > > > - CPU_SET(cpu, &cpu_set); > > > - > > > - pid = fork(); > > > - > > > - if (pid < 0) { > > > - ODPH_ERR("fork() failed\n"); > > > - return -1; > > > - } > > > - > > > - /* Parent continues to fork */ > > > - if (pid > 0) { > > > - proc_tbl[i].pid = pid; > > > - proc_tbl[i].cpu = cpu; > > > - > > > - cpu = odp_cpumask_next(mask, cpu); > > > - continue; > > > - } > > > - > > > - /* Child process */ > > > - > > > - /* Request SIGTERM if parent dies */ > > > - prctl(PR_SET_PDEATHSIG, SIGTERM); > > > - /* Parent died already? */ > > > - if (getppid() == 1) > > > - kill(getpid(), SIGTERM); > > > - > > > - if (sched_setaffinity(0, sizeof(cpu_set_t), &cpu_set)) { > > > - ODPH_ERR("sched_setaffinity() failed\n"); > > > - return -2; > > > - } > > > - > > > - if (odp_init_local(thr_params->instance, > > > - thr_params->thr_type)) { > > > - ODPH_ERR("Local init failed\n"); > > > - return -2; > > > - } > > > - > > > - return 0; > > > - } > > > - > > > - return 1; > > > -} > > > - > > > -int odph_linux_process_fork(odph_linux_process_t *proc, int cpu, > > > - const odph_linux_thr_params_t *thr_params) > > > -{ > > > - odp_cpumask_t mask; > > > - > > > - odp_cpumask_zero(&mask); > > > - odp_cpumask_set(&mask, cpu); > > > - return odph_linux_process_fork_n(proc, &mask, thr_params); > > > -} > > > - > > > -int odph_linux_process_wait_n(odph_linux_process_t *proc_tbl, int > num) > > > -{ > > > - pid_t pid; > > > - int i, j; > > > - int status = 0; > > > - > > > - for (i = 0; i < num; i++) { > > > - pid = wait(&status); > > > - > > > - if (pid < 0) { > > > - ODPH_ERR("wait() failed\n"); > > > - return -1; > > > - } > > > - > > > - for (j = 0; j < num; j++) { > > > - if (proc_tbl[j].pid == pid) { > > > - proc_tbl[j].status = status; > > > - break; > > > - } > > > - } > > > - > > > - if (j == num) { > > > - ODPH_ERR("Bad pid:%d\n", (int)pid); > > > - return -1; > > > - } > > > - > > > - /* Examine the child process' termination status */ > > > - if (WIFEXITED(status) && WEXITSTATUS(status) != > > EXIT_SUCCESS) { > > > - ODPH_ERR("Child exit status:%d (pid:%d)\n", > > > - WEXITSTATUS(status), (int)pid); > > > - return -1; > > > - } > > > - if (WIFSIGNALED(status)) { > > > - int signo = WTERMSIG(status); > > > - > > > - ODPH_ERR("Child term signo:%d - %s (pid:%d)\n", > > > - signo, strsignal(signo), (int)pid); > > > - return -1; > > > - } > > > - } > > > - > > > - return 0; > > > -} > > > - > > > /* > > > * wrapper for odpthreads, either implemented as linux threads or > > processes. > > > * (in process mode, if start_routine returns NULL, the process return > > FAILURE). > > > > > > > > > > -- > Mike Holmes > Program Manager - Linaro Networking Group > Linaro.org <http://www.linaro.org/> *│ *Open source software for ARM SoCs > "Work should be fun and collaborative, the rest follows" >
On 12/12/16 21:08, Christophe Milard wrote: > Why that question? The files are deleted, what would you expect -M to > do, Maxim? > -M would track move, but deletion would not be affected, would they? > > Christophe Ah, ok, files were deleted. But why process mode tests are deleted? Maxim. > > On 12 December 2016 at 18:49, Mike Holmes <mike.holmes@linaro.org > <mailto:mike.holmes@linaro.org>> wrote: > > On 12 December 2016 at 12:04, Maxim Uvarov <maxim.uvarov@linaro.org > <mailto:maxim.uvarov@linaro.org>> wrote: > > > did you use -M option to format-patch? > > > > I intended to - my history looks like I did > > > 2047 git format-patch origin/master --cover-letter > 2048 git format-patch origin/master --cover-letter -M > 2049 history > > > > > > > > > Maxim. > > > > On 12/12/16 17:52, Mike Holmes wrote: > > > Signed-off-by: Mike Holmes <mike.holmes@linaro.org > <mailto:mike.holmes@linaro.org>> > > > --- > > > helper/Makefile.am | 2 +- > > > helper/include/odp/helper/threads.h | 83 +------------- > > > helper/test/Makefile.am | 6 - > > > helper/test/process.c | 92 --------------- > > > helper/test/thread.c | 87 --------------- > > > helper/{linux.c => thread.c} | 216 > ------------------------------ > > ------ > > > 6 files changed, 5 insertions(+), 481 deletions(-) > > > delete mode 100644 helper/test/process.c > > > delete mode 100644 helper/test/thread.c > > > rename helper/{linux.c => thread.c} (70%) > > > > > > diff --git a/helper/Makefile.am b/helper/Makefile.am > > > index 2153d70..942dd60 100644 > > > --- a/helper/Makefile.am > > > +++ b/helper/Makefile.am > > > @@ -35,7 +35,7 @@ __LIB__libodphelper_linux_la_SOURCES = \ > > > eth.c \ > > > ip.c \ > > > chksum.c \ > > > - linux.c \ > > > + thread.c \ > > > hashtable.c \ > > > lineartable.c > > > > > > diff --git a/helper/include/odp/helper/threads.h > > b/helper/include/odp/helper/threads.h > > > index 238bcf8..7c4b68a 100644 > > > --- a/helper/include/odp/helper/threads.h > > > +++ b/helper/include/odp/helper/threads.h > > > @@ -8,15 +8,15 @@ > > > /** > > > * @file > > > * > > > - * ODP Linux helper API > > > + * ODP thread helper API > > > * > > > * 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). > > > */ > > > > > > -#ifndef ODPH_LINUX_H_ > > > -#define ODPH_LINUX_H_ > > > +#ifndef ODPH_THREAD_H_ > > > +#define ODPH_THREAD_H_ > > > > > > #ifdef __cplusplus > > > extern "C" { > > > @@ -28,7 +28,7 @@ extern "C" { > > > #include <getopt.h> > > > #include <sys/types.h> > > > > > > -/** @addtogroup odph_linux ODPH LINUX > > > +/** @addtogroup odph_linux ODPH THREAD > > > * @{ > > > */ > > > > > > @@ -94,81 +94,6 @@ typedef struct { > > > }; > > > } odph_odpthread_t; > > > > > > -/** > > > - * 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' > > > - * thread parameters. > > > - * > > > - * @param[out] proc Pointer to process state info (for > output) > > > - * @param cpu Destination CPU for the child process > > > - * @param thr_params Linux helper thread parameters > > > - * > > > - * @return On success: 1 for the parent, 0 for the child > > > - * On failure: -1 for the parent, -2 for the child > > > - */ > > > -int odph_linux_process_fork(odph_linux_process_t *proc, int cpu, > > > - const odph_linux_thr_params_t > *thr_params); > > > - > > > - > > > -/** > > > - * Fork a number of processes > > > - * > > > - * Forks and sets CPU affinity for child processes. Ignores > 'start' and > > 'arg' > > > - * thread parameters. > > > - * > > > - * @param[out] proc_tbl Process state info table (for output) > > > - * @param mask CPU mask of processes to create > > > - * @param thr_params Linux helper thread parameters > > > - * > > > - * @return On success: 1 for the parent, 0 for the child > > > - * On failure: -1 for the parent, -2 for the child > > > - */ > > > -int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl, > > > - const odp_cpumask_t *mask, > > > - const odph_linux_thr_params_t > *thr_params); > > > - > > > - > > > -/** > > > - * Wait for a number of processes > > > - * > > > - * Waits for a number of child processes to terminate. Records > process > > state > > > - * change status into the process state info structure. > > > - * > > > - * @param proc_tbl Process state info table (previously > filled by > > fork) > > > - * @param num Number of processes to wait > > > - * > > > - * @return 0 on success, -1 on failure > > > - */ > > > -int odph_linux_process_wait_n(odph_linux_process_t *proc_tbl, > int num); > > > > > > /** > > > * Creates and launches odpthreads (as linux threads or processes) > > > diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am > > > index 545db73..361e45d 100644 > > > --- a/helper/test/Makefile.am > > > +++ b/helper/test/Makefile.am > > > @@ -6,9 +6,7 @@ AM_LDFLAGS += -static > > > TESTS_ENVIRONMENT += TEST_DIR=${builddir} > > > > > > EXECUTABLES = chksum$(EXEEXT) \ > > > - thread$(EXEEXT) \ > > > parse$(EXEEXT)\ > > > - process$(EXEEXT)\ > > > table$(EXEEXT) > > > > > > COMPILE_ONLY = odpthreads > > > @@ -29,9 +27,5 @@ EXTRA_DIST = odpthreads_as_processes > > odpthreads_as_pthreads > > > dist_chksum_SOURCES = chksum.c > > > dist_odpthreads_SOURCES = odpthreads.c > > > odpthreads_LDADD = $(LIB)/libodphelper-linux.la > <http://libodphelper-linux.la> $(LIB)/libodp-linux.la > <http://libodp-linux.la> > > > -dist_thread_SOURCES = thread.c > > > -thread_LDADD = $(LIB)/libodphelper-linux.la > <http://libodphelper-linux.la> $(LIB)/libodp-linux.la > <http://libodp-linux.la> > > > -dist_process_SOURCES = process.c > > > dist_parse_SOURCES = parse.c > > > -process_LDADD = $(LIB)/libodphelper-linux.la > <http://libodphelper-linux.la> $(LIB)/libodp-linux.la > <http://libodp-linux.la> > > > dist_table_SOURCES = table.c > > > diff --git a/helper/test/process.c b/helper/test/process.c > > > deleted file mode 100644 > > > index 0e04224..0000000 > > > --- a/helper/test/process.c > > > +++ /dev/null > > > @@ -1,92 +0,0 @@ > > > -/* Copyright (c) 2015, Linaro Limited > > > - * All rights reserved. > > > - * > > > - * SPDX-License-Identifier: BSD-3-Clause > > > - */ > > > - > > > -#include <test_debug.h> > > > -#include <odp_api.h> > > > -#include <odp/helper/linux.h> > > > - > > > -#define NUMBER_WORKERS 16 /* 0 = max */ > > > - > > > -static void *worker_fn(void *arg TEST_UNUSED) > > > -{ > > > - /* depend on the odp helper to call odp_init_local */ > > > - printf("Worker thread on CPU %d\n", odp_cpu_id()); > > > - > > > - return 0; > > > -} > > > - > > > -/* Create additional dataplane processes */ > > > -int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) > > > -{ > > > - odp_cpumask_t cpu_mask; > > > - int num_workers; > > > - int cpu; > > > - char cpumaskstr[ODP_CPUMASK_STR_SIZE]; > > > - int ret; > > > - odph_linux_process_t proc[NUMBER_WORKERS]; > > > - odp_instance_t instance; > > > - odph_linux_thr_params_t thr_params; > > > - > > > - if (odp_init_global(&instance, NULL, NULL)) { > > > - LOG_ERR("Error: ODP global init failed.\n"); > > > - exit(EXIT_FAILURE); > > > - } > > > - > > > - if (odp_init_local(instance, ODP_THREAD_CONTROL)) { > > > - LOG_ERR("Error: ODP local init failed.\n"); > > > - exit(EXIT_FAILURE); > > > - } > > > - > > > - /* discover how many processes this system can support */ > > > - num_workers = odp_cpumask_default_worker(&cpu_mask, > > NUMBER_WORKERS); > > > - if (num_workers < NUMBER_WORKERS) { > > > - printf("System can only support %d processes and > not the > > %d requested\n", > > > - num_workers, NUMBER_WORKERS); > > > - } > > > - > > > - /* generate a summary for the user */ > > > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, > > sizeof(cpumaskstr)); > > > - printf("default cpu mask: %s\n", cpumaskstr); > > > - printf("default num worker processes: %i\n", num_workers); > > > - > > > - cpu = odp_cpumask_first(&cpu_mask); > > > - printf("the first CPU: %i\n", cpu); > > > - > > > - /* reserve cpu 0 for the control plane so remove it from > > > - * the default mask */ > > > - odp_cpumask_clr(&cpu_mask, 0); > > > - num_workers = odp_cpumask_count(&cpu_mask); > > > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, > > sizeof(cpumaskstr)); > > > - printf("new cpu mask: %s\n", cpumaskstr); > > > - printf("new num worker processes: %i\n\n", num_workers); > > > - > > > - memset(&thr_params, 0, sizeof(thr_params)); > > > - thr_params.thr_type = ODP_THREAD_WORKER; > > > - thr_params.instance = instance; > > > - > > > - /* Fork worker processes */ > > > - ret = odph_linux_process_fork_n(proc, &cpu_mask, &thr_params); > > > - > > > - if (ret < 0) { > > > - LOG_ERR("Fork workers failed %i\n", ret); > > > - return -1; > > > - } > > > - > > > - if (ret == 0) { > > > - /* Child process */ > > > - worker_fn(NULL); > > > - } else { > > > - /* Parent process */ > > > - odph_linux_process_wait_n(proc, num_workers); > > > - > > > - if (odp_term_global(instance)) { > > > - LOG_ERR("Error: ODP global term failed.\n"); > > > - exit(EXIT_FAILURE); > > > - } > > > - } > > > - > > > - return 0; > > > -} > > > diff --git a/helper/test/thread.c b/helper/test/thread.c > > > deleted file mode 100644 > > > index 8268d9f..0000000 > > > --- a/helper/test/thread.c > > > +++ /dev/null > > > @@ -1,87 +0,0 @@ > > > -/* Copyright (c) 2015, Linaro Limited > > > - * All rights reserved. > > > - * > > > - * SPDX-License-Identifier: BSD-3-Clause > > > - */ > > > - > > > -#include <test_debug.h> > > > -#include <odp_api.h> > > > -#include <odp/helper/linux.h> > > > - > > > -#define NUMBER_WORKERS 16 > > > -static void *worker_fn(void *arg TEST_UNUSED) > > > -{ > > > - /* depend on the odp helper to call odp_init_local */ > > > - > > > - printf("Worker thread on CPU %d\n", odp_cpu_id()); > > > - > > > - /* depend on the odp helper to call odp_term_local */ > > > - > > > - return NULL; > > > -} > > > - > > > -/* Create additional dataplane threads */ > > > -int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) > > > -{ > > > - odph_linux_pthread_t thread_tbl[NUMBER_WORKERS]; > > > - odp_cpumask_t cpu_mask; > > > - int num_workers; > > > - int cpu; > > > - char cpumaskstr[ODP_CPUMASK_STR_SIZE]; > > > - odp_instance_t instance; > > > - odph_linux_thr_params_t thr_params; > > > - > > > - if (odp_init_global(&instance, NULL, NULL)) { > > > - LOG_ERR("Error: ODP global init failed.\n"); > > > - exit(EXIT_FAILURE); > > > - } > > > - > > > - if (odp_init_local(instance, ODP_THREAD_CONTROL)) { > > > - LOG_ERR("Error: ODP local init failed.\n"); > > > - exit(EXIT_FAILURE); > > > - } > > > - > > > - /* discover how many threads this system can support */ > > > - num_workers = odp_cpumask_default_worker(&cpu_mask, > > NUMBER_WORKERS); > > > - if (num_workers < NUMBER_WORKERS) { > > > - printf("System can only support %d threads and not > the %d > > requested\n", > > > - num_workers, NUMBER_WORKERS); > > > - } > > > - > > > - /* generate a summary for the user */ > > > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, > > sizeof(cpumaskstr)); > > > - printf("default cpu mask: %s\n", cpumaskstr); > > > - printf("default num worker threads: %i\n", num_workers); > > > - > > > - cpu = odp_cpumask_first(&cpu_mask); > > > - printf("the first CPU: %i\n", cpu); > > > - > > > - /* reserve cpu 0 for the control plane so remove it from > > > - * the default mask */ > > > - odp_cpumask_clr(&cpu_mask, 0); > > > - num_workers = odp_cpumask_count(&cpu_mask); > > > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, > > sizeof(cpumaskstr)); > > > - printf("new cpu mask: %s\n", cpumaskstr); > > > - printf("new num worker threads: %i\n\n", num_workers); > > > - > > > - memset(&thr_params, 0, sizeof(thr_params)); > > > - thr_params.start = worker_fn; > > > - thr_params.arg = NULL; > > > - thr_params.thr_type = ODP_THREAD_WORKER; > > > - thr_params.instance = instance; > > > - > > > - odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, > &thr_params); > > > - odph_linux_pthread_join(thread_tbl, num_workers); > > > - > > > - if (odp_term_local()) { > > > - LOG_ERR("Error: ODP local term failed.\n"); > > > - exit(EXIT_FAILURE); > > > - } > > > - > > > - if (odp_term_global(instance)) { > > > - LOG_ERR("Error: ODP global term failed.\n"); > > > - exit(EXIT_FAILURE); > > > - } > > > - > > > - return 0; > > > -} > > > diff --git a/helper/linux.c b/helper/thread.c > > > similarity index 70% > > > rename from helper/linux.c > > > rename to helper/thread.c > > > index d5215c2..f946f5a 100644 > > > --- a/helper/linux.c > > > +++ b/helper/thread.c > > > @@ -27,222 +27,6 @@ static struct { > > > int proc; /* true when process mode is required, false > otherwise */ > > > } helper_options; > > > > > > -static void *odp_run_start_routine(void *arg) > > > -{ > > > - odph_linux_thr_params_t *thr_params = arg; > > > - > > > - /* ODP thread local init */ > > > - if (odp_init_local(thr_params->instance, > thr_params->thr_type)) { > > > - ODPH_ERR("Local init failed\n"); > > > - return NULL; > > > - } > > > - > > > - void *ret_ptr = thr_params->start(thr_params->arg); > > > - int ret = odp_term_local(); > > > - > > > - if (ret < 0) > > > - ODPH_ERR("Local term failed\n"); > > > - else if (ret == 0 && odp_term_global(thr_params->instance)) > > > - ODPH_ERR("Global term failed\n"); > > > - > > > - return ret_ptr; > > > -} > > > - > > > -int odph_linux_pthread_create(odph_linux_pthread_t *pthread_tbl, > > > - const odp_cpumask_t *mask, > > > - const odph_linux_thr_params_t > *thr_params) > > > -{ > > > - int i; > > > - int num; > > > - int cpu_count; > > > - int cpu; > > > - int ret; > > > - > > > - num = odp_cpumask_count(mask); > > > - > > > - memset(pthread_tbl, 0, num * sizeof(odph_linux_pthread_t)); > > > - > > > - cpu_count = odp_cpu_count(); > > > - > > > - if (num < 1 || num > cpu_count) { > > > - ODPH_ERR("Invalid number of threads:%d (%d cores > > available)\n", > > > - num, cpu_count); > > > - return 0; > > > - } > > > - > > > - cpu = odp_cpumask_first(mask); > > > - for (i = 0; i < num; i++) { > > > - cpu_set_t cpu_set; > > > - > > > - CPU_ZERO(&cpu_set); > > > - CPU_SET(cpu, &cpu_set); > > > - > > > - pthread_attr_init(&pthread_tbl[i].attr); > > > - > > > - pthread_tbl[i].cpu = cpu; > > > - > > > - pthread_attr_setaffinity_np(&pthread_tbl[i].attr, > > > - sizeof(cpu_set_t), > &cpu_set); > > > - > > > - pthread_tbl[i].thr_params.start = > thr_params->start; > > > - pthread_tbl[i].thr_params.arg = thr_params->arg; > > > - pthread_tbl[i].thr_params.thr_type = > thr_params->thr_type; > > > - pthread_tbl[i].thr_params.instance = > thr_params->instance; > > > - > > > - ret = pthread_create(&pthread_tbl[i].thread, > > > - &pthread_tbl[i].attr, > > > - odp_run_start_routine, > > > - &pthread_tbl[i].thr_params); > > > - if (ret != 0) { > > > - ODPH_ERR("Failed to start thread on cpu > #%d\n", > > cpu); > > > - break; > > > - } > > > - > > > - cpu = odp_cpumask_next(mask, cpu); > > > - } > > > - > > > - return i; > > > -} > > > - > > > -void odph_linux_pthread_join(odph_linux_pthread_t *thread_tbl, > int num) > > > -{ > > > - int i; > > > - int ret; > > > - > > > - for (i = 0; i < num; i++) { > > > - /* Wait thread to exit */ > > > - ret = pthread_join(thread_tbl[i].thread, NULL); > > > - if (ret != 0) { > > > - ODPH_ERR("Failed to join thread from cpu > #%d\n", > > > - thread_tbl[i].cpu); > > > - } > > > - pthread_attr_destroy(&thread_tbl[i].attr); > > > - } > > > -} > > > - > > > -int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl, > > > - const odp_cpumask_t *mask, > > > - const odph_linux_thr_params_t > *thr_params) > > > -{ > > > - pid_t pid; > > > - int num; > > > - int cpu_count; > > > - int cpu; > > > - int i; > > > - > > > - num = odp_cpumask_count(mask); > > > - > > > - memset(proc_tbl, 0, num * sizeof(odph_linux_process_t)); > > > - > > > - cpu_count = odp_cpu_count(); > > > - > > > - if (num < 1 || num > cpu_count) { > > > - ODPH_ERR("Bad num\n"); > > > - return -1; > > > - } > > > - > > > - cpu = odp_cpumask_first(mask); > > > - for (i = 0; i < num; i++) { > > > - cpu_set_t cpu_set; > > > - > > > - CPU_ZERO(&cpu_set); > > > - CPU_SET(cpu, &cpu_set); > > > - > > > - pid = fork(); > > > - > > > - if (pid < 0) { > > > - ODPH_ERR("fork() failed\n"); > > > - return -1; > > > - } > > > - > > > - /* Parent continues to fork */ > > > - if (pid > 0) { > > > - proc_tbl[i].pid = pid; > > > - proc_tbl[i].cpu = cpu; > > > - > > > - cpu = odp_cpumask_next(mask, cpu); > > > - continue; > > > - } > > > - > > > - /* Child process */ > > > - > > > - /* Request SIGTERM if parent dies */ > > > - prctl(PR_SET_PDEATHSIG, SIGTERM); > > > - /* Parent died already? */ > > > - if (getppid() == 1) > > > - kill(getpid(), SIGTERM); > > > - > > > - if (sched_setaffinity(0, sizeof(cpu_set_t), > &cpu_set)) { > > > - ODPH_ERR("sched_setaffinity() failed\n"); > > > - return -2; > > > - } > > > - > > > - if (odp_init_local(thr_params->instance, > > > - thr_params->thr_type)) { > > > - ODPH_ERR("Local init failed\n"); > > > - return -2; > > > - } > > > - > > > - return 0; > > > - } > > > - > > > - return 1; > > > -} > > > - > > > -int odph_linux_process_fork(odph_linux_process_t *proc, int cpu, > > > - const odph_linux_thr_params_t *thr_params) > > > -{ > > > - odp_cpumask_t mask; > > > - > > > - odp_cpumask_zero(&mask); > > > - odp_cpumask_set(&mask, cpu); > > > - return odph_linux_process_fork_n(proc, &mask, thr_params); > > > -} > > > - > > > -int odph_linux_process_wait_n(odph_linux_process_t *proc_tbl, > int num) > > > -{ > > > - pid_t pid; > > > - int i, j; > > > - int status = 0; > > > - > > > - for (i = 0; i < num; i++) { > > > - pid = wait(&status); > > > - > > > - if (pid < 0) { > > > - ODPH_ERR("wait() failed\n"); > > > - return -1; > > > - } > > > - > > > - for (j = 0; j < num; j++) { > > > - if (proc_tbl[j].pid == pid) { > > > - proc_tbl[j].status = status; > > > - break; > > > - } > > > - } > > > - > > > - if (j == num) { > > > - ODPH_ERR("Bad pid:%d\n", (int)pid); > > > - return -1; > > > - } > > > - > > > - /* Examine the child process' termination status */ > > > - if (WIFEXITED(status) && WEXITSTATUS(status) != > > EXIT_SUCCESS) { > > > - ODPH_ERR("Child exit status:%d (pid:%d)\n", > > > - WEXITSTATUS(status), (int)pid); > > > - return -1; > > > - } > > > - if (WIFSIGNALED(status)) { > > > - int signo = WTERMSIG(status); > > > - > > > - ODPH_ERR("Child term signo:%d - %s > (pid:%d)\n", > > > - signo, strsignal(signo), (int)pid); > > > - return -1; > > > - } > > > - } > > > - > > > - return 0; > > > -} > > > - > > > /* > > > * wrapper for odpthreads, either implemented as linux threads or > > processes. > > > * (in process mode, if start_routine returns NULL, the process > return > > FAILURE). > > > > > > > > > > -- > Mike Holmes > Program Manager - Linaro Networking Group > Linaro.org <http://www.linaro.org/> *│ *Open source software for ARM > SoCs > "Work should be fun and collaborative, the rest follows" > >
they were old test for linux only. process and thread omplementation of odp threads are tested in odpthread.c On 12 December 2016 at 19:51, Maxim Uvarov <maxim.uvarov@linaro.org> wrote: > On 12/12/16 21:08, Christophe Milard wrote: > > Why that question? The files are deleted, what would you expect -M to > > do, Maxim? > > -M would track move, but deletion would not be affected, would they? > > > > Christophe > > > Ah, ok, files were deleted. > > But why process mode tests are deleted? > > Maxim. > > > > > > On 12 December 2016 at 18:49, Mike Holmes <mike.holmes@linaro.org > > <mailto:mike.holmes@linaro.org>> wrote: > > > > On 12 December 2016 at 12:04, Maxim Uvarov <maxim.uvarov@linaro.org > > <mailto:maxim.uvarov@linaro.org>> wrote: > > > > > did you use -M option to format-patch? > > > > > > > I intended to - my history looks like I did > > > > > > 2047 git format-patch origin/master --cover-letter > > 2048 git format-patch origin/master --cover-letter -M > > 2049 history > > > > > > > > > > > > > > > > Maxim. > > > > > > On 12/12/16 17:52, Mike Holmes wrote: > > > > Signed-off-by: Mike Holmes <mike.holmes@linaro.org > > <mailto:mike.holmes@linaro.org>> > > > > --- > > > > helper/Makefile.am | 2 +- > > > > helper/include/odp/helper/threads.h | 83 +------------- > > > > helper/test/Makefile.am | 6 - > > > > helper/test/process.c | 92 --------------- > > > > helper/test/thread.c | 87 --------------- > > > > helper/{linux.c => thread.c} | 216 > > ------------------------------ > > > ------ > > > > 6 files changed, 5 insertions(+), 481 deletions(-) > > > > delete mode 100644 helper/test/process.c > > > > delete mode 100644 helper/test/thread.c > > > > rename helper/{linux.c => thread.c} (70%) > > > > > > > > diff --git a/helper/Makefile.am b/helper/Makefile.am > > > > index 2153d70..942dd60 100644 > > > > --- a/helper/Makefile.am > > > > +++ b/helper/Makefile.am > > > > @@ -35,7 +35,7 @@ __LIB__libodphelper_linux_la_SOURCES = \ > > > > eth.c \ > > > > ip.c \ > > > > chksum.c \ > > > > - linux.c \ > > > > + thread.c \ > > > > hashtable.c \ > > > > lineartable.c > > > > > > > > diff --git a/helper/include/odp/helper/threads.h > > > b/helper/include/odp/helper/threads.h > > > > index 238bcf8..7c4b68a 100644 > > > > --- a/helper/include/odp/helper/threads.h > > > > +++ b/helper/include/odp/helper/threads.h > > > > @@ -8,15 +8,15 @@ > > > > /** > > > > * @file > > > > * > > > > - * ODP Linux helper API > > > > + * ODP thread helper API > > > > * > > > > * 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). > > > > */ > > > > > > > > -#ifndef ODPH_LINUX_H_ > > > > -#define ODPH_LINUX_H_ > > > > +#ifndef ODPH_THREAD_H_ > > > > +#define ODPH_THREAD_H_ > > > > > > > > #ifdef __cplusplus > > > > extern "C" { > > > > @@ -28,7 +28,7 @@ extern "C" { > > > > #include <getopt.h> > > > > #include <sys/types.h> > > > > > > > > -/** @addtogroup odph_linux ODPH LINUX > > > > +/** @addtogroup odph_linux ODPH THREAD > > > > * @{ > > > > */ > > > > > > > > @@ -94,81 +94,6 @@ typedef struct { > > > > }; > > > > } odph_odpthread_t; > > > > > > > > -/** > > > > - * 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' > > > > - * thread parameters. > > > > - * > > > > - * @param[out] proc Pointer to process state info (for > > output) > > > > - * @param cpu Destination CPU for the child process > > > > - * @param thr_params Linux helper thread parameters > > > > - * > > > > - * @return On success: 1 for the parent, 0 for the child > > > > - * On failure: -1 for the parent, -2 for the child > > > > - */ > > > > -int odph_linux_process_fork(odph_linux_process_t *proc, int > cpu, > > > > - const odph_linux_thr_params_t > > *thr_params); > > > > - > > > > - > > > > -/** > > > > - * Fork a number of processes > > > > - * > > > > - * Forks and sets CPU affinity for child processes. Ignores > > 'start' and > > > 'arg' > > > > - * thread parameters. > > > > - * > > > > - * @param[out] proc_tbl Process state info table (for output) > > > > - * @param mask CPU mask of processes to create > > > > - * @param thr_params Linux helper thread parameters > > > > - * > > > > - * @return On success: 1 for the parent, 0 for the child > > > > - * On failure: -1 for the parent, -2 for the child > > > > - */ > > > > -int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl, > > > > - const odp_cpumask_t *mask, > > > > - const odph_linux_thr_params_t > > *thr_params); > > > > - > > > > - > > > > -/** > > > > - * Wait for a number of processes > > > > - * > > > > - * Waits for a number of child processes to terminate. Records > > process > > > state > > > > - * change status into the process state info structure. > > > > - * > > > > - * @param proc_tbl Process state info table (previously > > filled by > > > fork) > > > > - * @param num Number of processes to wait > > > > - * > > > > - * @return 0 on success, -1 on failure > > > > - */ > > > > -int odph_linux_process_wait_n(odph_linux_process_t *proc_tbl, > > int num); > > > > > > > > /** > > > > * Creates and launches odpthreads (as linux threads or > processes) > > > > diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am > > > > index 545db73..361e45d 100644 > > > > --- a/helper/test/Makefile.am > > > > +++ b/helper/test/Makefile.am > > > > @@ -6,9 +6,7 @@ AM_LDFLAGS += -static > > > > TESTS_ENVIRONMENT += TEST_DIR=${builddir} > > > > > > > > EXECUTABLES = chksum$(EXEEXT) \ > > > > - thread$(EXEEXT) \ > > > > parse$(EXEEXT)\ > > > > - process$(EXEEXT)\ > > > > table$(EXEEXT) > > > > > > > > COMPILE_ONLY = odpthreads > > > > @@ -29,9 +27,5 @@ EXTRA_DIST = odpthreads_as_processes > > > odpthreads_as_pthreads > > > > dist_chksum_SOURCES = chksum.c > > > > dist_odpthreads_SOURCES = odpthreads.c > > > > odpthreads_LDADD = $(LIB)/libodphelper-linux.la > > <http://libodphelper-linux.la> $(LIB)/libodp-linux.la > > <http://libodp-linux.la> > > > > -dist_thread_SOURCES = thread.c > > > > -thread_LDADD = $(LIB)/libodphelper-linux.la > > <http://libodphelper-linux.la> $(LIB)/libodp-linux.la > > <http://libodp-linux.la> > > > > -dist_process_SOURCES = process.c > > > > dist_parse_SOURCES = parse.c > > > > -process_LDADD = $(LIB)/libodphelper-linux.la > > <http://libodphelper-linux.la> $(LIB)/libodp-linux.la > > <http://libodp-linux.la> > > > > dist_table_SOURCES = table.c > > > > diff --git a/helper/test/process.c b/helper/test/process.c > > > > deleted file mode 100644 > > > > index 0e04224..0000000 > > > > --- a/helper/test/process.c > > > > +++ /dev/null > > > > @@ -1,92 +0,0 @@ > > > > -/* Copyright (c) 2015, Linaro Limited > > > > - * All rights reserved. > > > > - * > > > > - * SPDX-License-Identifier: BSD-3-Clause > > > > - */ > > > > - > > > > -#include <test_debug.h> > > > > -#include <odp_api.h> > > > > -#include <odp/helper/linux.h> > > > > - > > > > -#define NUMBER_WORKERS 16 /* 0 = max */ > > > > - > > > > -static void *worker_fn(void *arg TEST_UNUSED) > > > > -{ > > > > - /* depend on the odp helper to call odp_init_local */ > > > > - printf("Worker thread on CPU %d\n", odp_cpu_id()); > > > > - > > > > - return 0; > > > > -} > > > > - > > > > -/* Create additional dataplane processes */ > > > > -int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) > > > > -{ > > > > - odp_cpumask_t cpu_mask; > > > > - int num_workers; > > > > - int cpu; > > > > - char cpumaskstr[ODP_CPUMASK_STR_SIZE]; > > > > - int ret; > > > > - odph_linux_process_t proc[NUMBER_WORKERS]; > > > > - odp_instance_t instance; > > > > - odph_linux_thr_params_t thr_params; > > > > - > > > > - if (odp_init_global(&instance, NULL, NULL)) { > > > > - LOG_ERR("Error: ODP global init failed.\n"); > > > > - exit(EXIT_FAILURE); > > > > - } > > > > - > > > > - if (odp_init_local(instance, ODP_THREAD_CONTROL)) { > > > > - LOG_ERR("Error: ODP local init failed.\n"); > > > > - exit(EXIT_FAILURE); > > > > - } > > > > - > > > > - /* discover how many processes this system can support */ > > > > - num_workers = odp_cpumask_default_worker(&cpu_mask, > > > NUMBER_WORKERS); > > > > - if (num_workers < NUMBER_WORKERS) { > > > > - printf("System can only support %d processes and > > not the > > > %d requested\n", > > > > - num_workers, NUMBER_WORKERS); > > > > - } > > > > - > > > > - /* generate a summary for the user */ > > > > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, > > > sizeof(cpumaskstr)); > > > > - printf("default cpu mask: %s\n", cpumaskstr); > > > > - printf("default num worker processes: %i\n", num_workers); > > > > - > > > > - cpu = odp_cpumask_first(&cpu_mask); > > > > - printf("the first CPU: %i\n", cpu); > > > > - > > > > - /* reserve cpu 0 for the control plane so remove it from > > > > - * the default mask */ > > > > - odp_cpumask_clr(&cpu_mask, 0); > > > > - num_workers = odp_cpumask_count(&cpu_mask); > > > > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, > > > sizeof(cpumaskstr)); > > > > - printf("new cpu mask: %s\n", cpumaskstr); > > > > - printf("new num worker processes: %i\n\n", > num_workers); > > > > - > > > > - memset(&thr_params, 0, sizeof(thr_params)); > > > > - thr_params.thr_type = ODP_THREAD_WORKER; > > > > - thr_params.instance = instance; > > > > - > > > > - /* Fork worker processes */ > > > > - ret = odph_linux_process_fork_n(proc, &cpu_mask, > &thr_params); > > > > - > > > > - if (ret < 0) { > > > > - LOG_ERR("Fork workers failed %i\n", ret); > > > > - return -1; > > > > - } > > > > - > > > > - if (ret == 0) { > > > > - /* Child process */ > > > > - worker_fn(NULL); > > > > - } else { > > > > - /* Parent process */ > > > > - odph_linux_process_wait_n(proc, num_workers); > > > > - > > > > - if (odp_term_global(instance)) { > > > > - LOG_ERR("Error: ODP global term > failed.\n"); > > > > - exit(EXIT_FAILURE); > > > > - } > > > > - } > > > > - > > > > - return 0; > > > > -} > > > > diff --git a/helper/test/thread.c b/helper/test/thread.c > > > > deleted file mode 100644 > > > > index 8268d9f..0000000 > > > > --- a/helper/test/thread.c > > > > +++ /dev/null > > > > @@ -1,87 +0,0 @@ > > > > -/* Copyright (c) 2015, Linaro Limited > > > > - * All rights reserved. > > > > - * > > > > - * SPDX-License-Identifier: BSD-3-Clause > > > > - */ > > > > - > > > > -#include <test_debug.h> > > > > -#include <odp_api.h> > > > > -#include <odp/helper/linux.h> > > > > - > > > > -#define NUMBER_WORKERS 16 > > > > -static void *worker_fn(void *arg TEST_UNUSED) > > > > -{ > > > > - /* depend on the odp helper to call odp_init_local */ > > > > - > > > > - printf("Worker thread on CPU %d\n", odp_cpu_id()); > > > > - > > > > - /* depend on the odp helper to call odp_term_local */ > > > > - > > > > - return NULL; > > > > -} > > > > - > > > > -/* Create additional dataplane threads */ > > > > -int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) > > > > -{ > > > > - odph_linux_pthread_t thread_tbl[NUMBER_WORKERS]; > > > > - odp_cpumask_t cpu_mask; > > > > - int num_workers; > > > > - int cpu; > > > > - char cpumaskstr[ODP_CPUMASK_STR_SIZE]; > > > > - odp_instance_t instance; > > > > - odph_linux_thr_params_t thr_params; > > > > - > > > > - if (odp_init_global(&instance, NULL, NULL)) { > > > > - LOG_ERR("Error: ODP global init failed.\n"); > > > > - exit(EXIT_FAILURE); > > > > - } > > > > - > > > > - if (odp_init_local(instance, ODP_THREAD_CONTROL)) { > > > > - LOG_ERR("Error: ODP local init failed.\n"); > > > > - exit(EXIT_FAILURE); > > > > - } > > > > - > > > > - /* discover how many threads this system can support */ > > > > - num_workers = odp_cpumask_default_worker(&cpu_mask, > > > NUMBER_WORKERS); > > > > - if (num_workers < NUMBER_WORKERS) { > > > > - printf("System can only support %d threads and not > > the %d > > > requested\n", > > > > - num_workers, NUMBER_WORKERS); > > > > - } > > > > - > > > > - /* generate a summary for the user */ > > > > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, > > > sizeof(cpumaskstr)); > > > > - printf("default cpu mask: %s\n", cpumaskstr); > > > > - printf("default num worker threads: %i\n", num_workers); > > > > - > > > > - cpu = odp_cpumask_first(&cpu_mask); > > > > - printf("the first CPU: %i\n", cpu); > > > > - > > > > - /* reserve cpu 0 for the control plane so remove it from > > > > - * the default mask */ > > > > - odp_cpumask_clr(&cpu_mask, 0); > > > > - num_workers = odp_cpumask_count(&cpu_mask); > > > > - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, > > > sizeof(cpumaskstr)); > > > > - printf("new cpu mask: %s\n", cpumaskstr); > > > > - printf("new num worker threads: %i\n\n", num_workers); > > > > - > > > > - memset(&thr_params, 0, sizeof(thr_params)); > > > > - thr_params.start = worker_fn; > > > > - thr_params.arg = NULL; > > > > - thr_params.thr_type = ODP_THREAD_WORKER; > > > > - thr_params.instance = instance; > > > > - > > > > - odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, > > &thr_params); > > > > - odph_linux_pthread_join(thread_tbl, num_workers); > > > > - > > > > - if (odp_term_local()) { > > > > - LOG_ERR("Error: ODP local term failed.\n"); > > > > - exit(EXIT_FAILURE); > > > > - } > > > > - > > > > - if (odp_term_global(instance)) { > > > > - LOG_ERR("Error: ODP global term failed.\n"); > > > > - exit(EXIT_FAILURE); > > > > - } > > > > - > > > > - return 0; > > > > -} > > > > diff --git a/helper/linux.c b/helper/thread.c > > > > similarity index 70% > > > > rename from helper/linux.c > > > > rename to helper/thread.c > > > > index d5215c2..f946f5a 100644 > > > > --- a/helper/linux.c > > > > +++ b/helper/thread.c > > > > @@ -27,222 +27,6 @@ static struct { > > > > int proc; /* true when process mode is required, false > > otherwise */ > > > > } helper_options; > > > > > > > > -static void *odp_run_start_routine(void *arg) > > > > -{ > > > > - odph_linux_thr_params_t *thr_params = arg; > > > > - > > > > - /* ODP thread local init */ > > > > - if (odp_init_local(thr_params->instance, > > thr_params->thr_type)) { > > > > - ODPH_ERR("Local init failed\n"); > > > > - return NULL; > > > > - } > > > > - > > > > - void *ret_ptr = thr_params->start(thr_params->arg); > > > > - int ret = odp_term_local(); > > > > - > > > > - if (ret < 0) > > > > - ODPH_ERR("Local term failed\n"); > > > > - else if (ret == 0 && odp_term_global(thr_params-> > instance)) > > > > - ODPH_ERR("Global term failed\n"); > > > > - > > > > - return ret_ptr; > > > > -} > > > > - > > > > -int odph_linux_pthread_create(odph_linux_pthread_t > *pthread_tbl, > > > > - const odp_cpumask_t *mask, > > > > - const odph_linux_thr_params_t > > *thr_params) > > > > -{ > > > > - int i; > > > > - int num; > > > > - int cpu_count; > > > > - int cpu; > > > > - int ret; > > > > - > > > > - num = odp_cpumask_count(mask); > > > > - > > > > - memset(pthread_tbl, 0, num * sizeof(odph_linux_pthread_t)); > > > > - > > > > - cpu_count = odp_cpu_count(); > > > > - > > > > - if (num < 1 || num > cpu_count) { > > > > - ODPH_ERR("Invalid number of threads:%d (%d cores > > > available)\n", > > > > - num, cpu_count); > > > > - return 0; > > > > - } > > > > - > > > > - cpu = odp_cpumask_first(mask); > > > > - for (i = 0; i < num; i++) { > > > > - cpu_set_t cpu_set; > > > > - > > > > - CPU_ZERO(&cpu_set); > > > > - CPU_SET(cpu, &cpu_set); > > > > - > > > > - pthread_attr_init(&pthread_tbl[i].attr); > > > > - > > > > - pthread_tbl[i].cpu = cpu; > > > > - > > > > - pthread_attr_setaffinity_np(&pthread_tbl[i].attr, > > > > - sizeof(cpu_set_t), > > &cpu_set); > > > > - > > > > - pthread_tbl[i].thr_params.start = > > thr_params->start; > > > > - pthread_tbl[i].thr_params.arg = > thr_params->arg; > > > > - pthread_tbl[i].thr_params.thr_type = > > thr_params->thr_type; > > > > - pthread_tbl[i].thr_params.instance = > > thr_params->instance; > > > > - > > > > - ret = pthread_create(&pthread_tbl[i].thread, > > > > - &pthread_tbl[i].attr, > > > > - odp_run_start_routine, > > > > - &pthread_tbl[i].thr_params); > > > > - if (ret != 0) { > > > > - ODPH_ERR("Failed to start thread on cpu > > #%d\n", > > > cpu); > > > > - break; > > > > - } > > > > - > > > > - cpu = odp_cpumask_next(mask, cpu); > > > > - } > > > > - > > > > - return i; > > > > -} > > > > - > > > > -void odph_linux_pthread_join(odph_linux_pthread_t *thread_tbl, > > int num) > > > > -{ > > > > - int i; > > > > - int ret; > > > > - > > > > - for (i = 0; i < num; i++) { > > > > - /* Wait thread to exit */ > > > > - ret = pthread_join(thread_tbl[i].thread, NULL); > > > > - if (ret != 0) { > > > > - ODPH_ERR("Failed to join thread from cpu > > #%d\n", > > > > - thread_tbl[i].cpu); > > > > - } > > > > - pthread_attr_destroy(&thread_tbl[i].attr); > > > > - } > > > > -} > > > > - > > > > -int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl, > > > > - const odp_cpumask_t *mask, > > > > - const odph_linux_thr_params_t > > *thr_params) > > > > -{ > > > > - pid_t pid; > > > > - int num; > > > > - int cpu_count; > > > > - int cpu; > > > > - int i; > > > > - > > > > - num = odp_cpumask_count(mask); > > > > - > > > > - memset(proc_tbl, 0, num * sizeof(odph_linux_process_t)); > > > > - > > > > - cpu_count = odp_cpu_count(); > > > > - > > > > - if (num < 1 || num > cpu_count) { > > > > - ODPH_ERR("Bad num\n"); > > > > - return -1; > > > > - } > > > > - > > > > - cpu = odp_cpumask_first(mask); > > > > - for (i = 0; i < num; i++) { > > > > - cpu_set_t cpu_set; > > > > - > > > > - CPU_ZERO(&cpu_set); > > > > - CPU_SET(cpu, &cpu_set); > > > > - > > > > - pid = fork(); > > > > - > > > > - if (pid < 0) { > > > > - ODPH_ERR("fork() failed\n"); > > > > - return -1; > > > > - } > > > > - > > > > - /* Parent continues to fork */ > > > > - if (pid > 0) { > > > > - proc_tbl[i].pid = pid; > > > > - proc_tbl[i].cpu = cpu; > > > > - > > > > - cpu = odp_cpumask_next(mask, cpu); > > > > - continue; > > > > - } > > > > - > > > > - /* Child process */ > > > > - > > > > - /* Request SIGTERM if parent dies */ > > > > - prctl(PR_SET_PDEATHSIG, SIGTERM); > > > > - /* Parent died already? */ > > > > - if (getppid() == 1) > > > > - kill(getpid(), SIGTERM); > > > > - > > > > - if (sched_setaffinity(0, sizeof(cpu_set_t), > > &cpu_set)) { > > > > - ODPH_ERR("sched_setaffinity() failed\n"); > > > > - return -2; > > > > - } > > > > - > > > > - if (odp_init_local(thr_params->instance, > > > > - thr_params->thr_type)) { > > > > - ODPH_ERR("Local init failed\n"); > > > > - return -2; > > > > - } > > > > - > > > > - return 0; > > > > - } > > > > - > > > > - return 1; > > > > -} > > > > - > > > > -int odph_linux_process_fork(odph_linux_process_t *proc, int > cpu, > > > > - const odph_linux_thr_params_t > *thr_params) > > > > -{ > > > > - odp_cpumask_t mask; > > > > - > > > > - odp_cpumask_zero(&mask); > > > > - odp_cpumask_set(&mask, cpu); > > > > - return odph_linux_process_fork_n(proc, &mask, thr_params); > > > > -} > > > > - > > > > -int odph_linux_process_wait_n(odph_linux_process_t *proc_tbl, > > int num) > > > > -{ > > > > - pid_t pid; > > > > - int i, j; > > > > - int status = 0; > > > > - > > > > - for (i = 0; i < num; i++) { > > > > - pid = wait(&status); > > > > - > > > > - if (pid < 0) { > > > > - ODPH_ERR("wait() failed\n"); > > > > - return -1; > > > > - } > > > > - > > > > - for (j = 0; j < num; j++) { > > > > - if (proc_tbl[j].pid == pid) { > > > > - proc_tbl[j].status = status; > > > > - break; > > > > - } > > > > - } > > > > - > > > > - if (j == num) { > > > > - ODPH_ERR("Bad pid:%d\n", (int)pid); > > > > - return -1; > > > > - } > > > > - > > > > - /* Examine the child process' termination status */ > > > > - if (WIFEXITED(status) && WEXITSTATUS(status) != > > > EXIT_SUCCESS) { > > > > - ODPH_ERR("Child exit status:%d (pid:%d)\n", > > > > - WEXITSTATUS(status), (int)pid); > > > > - return -1; > > > > - } > > > > - if (WIFSIGNALED(status)) { > > > > - int signo = WTERMSIG(status); > > > > - > > > > - ODPH_ERR("Child term signo:%d - %s > > (pid:%d)\n", > > > > - signo, strsignal(signo), > (int)pid); > > > > - return -1; > > > > - } > > > > - } > > > > - > > > > - return 0; > > > > -} > > > > - > > > > /* > > > > * wrapper for odpthreads, either implemented as linux threads > or > > > processes. > > > > * (in process mode, if start_routine returns NULL, the process > > return > > > FAILURE). > > > > > > > > > > > > > > > > -- > > Mike Holmes > > Program Manager - Linaro Networking Group > > Linaro.org <http://www.linaro.org/> *│ *Open source software for ARM > > SoCs > > "Work should be fun and collaborative, the rest follows" > > > > > >
> -----Original Message----- > From: lng-odp [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of Mike > Holmes > Sent: Monday, December 12, 2016 4:52 PM > To: lng-odp@lists.linaro.org > Subject: [lng-odp] [PATCH 2/6] helper: remove unused linux specific apis > > Signed-off-by: Mike Holmes <mike.holmes@linaro.org> > --- > helper/Makefile.am | 2 +- > helper/include/odp/helper/threads.h | 83 +------------- > helper/test/Makefile.am | 6 - > helper/test/process.c | 92 --------------- > helper/test/thread.c | 87 --------------- > helper/{linux.c => thread.c} | 216 ------------------------------- > ----- > 6 files changed, 5 insertions(+), 481 deletions(-) > delete mode 100644 helper/test/process.c > delete mode 100644 helper/test/thread.c > rename helper/{linux.c => thread.c} (70%) > > > -/** > - * 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); Not all applications need to support pthreads and processes without knowing which one is used. We want to run our tests on both, but majority of applications pick one model (pthread or process) and stick with that. For example, OFP uses odph_linux_pthread_create() and friends a lot. So, these should not be removed, but developed and maintained in addition to the opaque thread functions. -Petri
On 13 December 2016 at 05:13, Savolainen, Petri (Nokia - FI/Espoo) < petri.savolainen@nokia-bell-labs.com> wrote: > > -----Original Message----- > > From: lng-odp [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of > Mike > > Holmes > > Sent: Monday, December 12, 2016 4:52 PM > > To: lng-odp@lists.linaro.org > > Subject: [lng-odp] [PATCH 2/6] helper: remove unused linux specific apis > > > > Signed-off-by: Mike Holmes <mike.holmes@linaro.org> > > --- > > helper/Makefile.am | 2 +- > > helper/include/odp/helper/threads.h | 83 +------------- > > helper/test/Makefile.am | 6 - > > helper/test/process.c | 92 --------------- > > helper/test/thread.c | 87 --------------- > > helper/{linux.c => thread.c} | 216 ------------------------------ > - > > ----- > > 6 files changed, 5 insertions(+), 481 deletions(-) > > delete mode 100644 helper/test/process.c > > delete mode 100644 helper/test/thread.c > > rename helper/{linux.c => thread.c} (70%) > > > > > > -/** > > - * 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); > > > Not all applications need to support pthreads and processes without > knowing which one is used. We want to run our tests on both, but majority > of applications pick one model (pthread or process) and stick with that. > For example, OFP uses odph_linux_pthread_create() and friends a lot. > > So, these should not be removed, but developed and maintained in addition > to the opaque thread functions. > We can have linux specific tests in the linux platform, we have test/linux-generic for that purpose, but I dont see how they can be part of the public helper API, the other OS'es in use with ODP can't use them. > > > -Petri > > -- Mike Holmes Program Manager - Linaro Networking Group Linaro.org <http://www.linaro.org/> *│ *Open source software for ARM SoCs "Work should be fun and collaborative, the rest follows"
diff --git a/helper/Makefile.am b/helper/Makefile.am index 2153d70..942dd60 100644 --- a/helper/Makefile.am +++ b/helper/Makefile.am @@ -35,7 +35,7 @@ __LIB__libodphelper_linux_la_SOURCES = \ eth.c \ ip.c \ chksum.c \ - linux.c \ + thread.c \ hashtable.c \ lineartable.c diff --git a/helper/include/odp/helper/threads.h b/helper/include/odp/helper/threads.h index 238bcf8..7c4b68a 100644 --- a/helper/include/odp/helper/threads.h +++ b/helper/include/odp/helper/threads.h @@ -8,15 +8,15 @@ /** * @file * - * ODP Linux helper API + * ODP thread helper API * * 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). */ -#ifndef ODPH_LINUX_H_ -#define ODPH_LINUX_H_ +#ifndef ODPH_THREAD_H_ +#define ODPH_THREAD_H_ #ifdef __cplusplus extern "C" { @@ -28,7 +28,7 @@ extern "C" { #include <getopt.h> #include <sys/types.h> -/** @addtogroup odph_linux ODPH LINUX +/** @addtogroup odph_linux ODPH THREAD * @{ */ @@ -94,81 +94,6 @@ typedef struct { }; } odph_odpthread_t; -/** - * 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' - * thread parameters. - * - * @param[out] proc Pointer to process state info (for output) - * @param cpu Destination CPU for the child process - * @param thr_params Linux helper thread parameters - * - * @return On success: 1 for the parent, 0 for the child - * On failure: -1 for the parent, -2 for the child - */ -int odph_linux_process_fork(odph_linux_process_t *proc, int cpu, - const odph_linux_thr_params_t *thr_params); - - -/** - * Fork a number of processes - * - * Forks and sets CPU affinity for child processes. Ignores 'start' and 'arg' - * thread parameters. - * - * @param[out] proc_tbl Process state info table (for output) - * @param mask CPU mask of processes to create - * @param thr_params Linux helper thread parameters - * - * @return On success: 1 for the parent, 0 for the child - * On failure: -1 for the parent, -2 for the child - */ -int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl, - const odp_cpumask_t *mask, - const odph_linux_thr_params_t *thr_params); - - -/** - * Wait for a number of processes - * - * Waits for a number of child processes to terminate. Records process state - * change status into the process state info structure. - * - * @param proc_tbl Process state info table (previously filled by fork) - * @param num Number of processes to wait - * - * @return 0 on success, -1 on failure - */ -int odph_linux_process_wait_n(odph_linux_process_t *proc_tbl, int num); /** * Creates and launches odpthreads (as linux threads or processes) diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am index 545db73..361e45d 100644 --- a/helper/test/Makefile.am +++ b/helper/test/Makefile.am @@ -6,9 +6,7 @@ AM_LDFLAGS += -static TESTS_ENVIRONMENT += TEST_DIR=${builddir} EXECUTABLES = chksum$(EXEEXT) \ - thread$(EXEEXT) \ parse$(EXEEXT)\ - process$(EXEEXT)\ table$(EXEEXT) COMPILE_ONLY = odpthreads @@ -29,9 +27,5 @@ EXTRA_DIST = odpthreads_as_processes odpthreads_as_pthreads dist_chksum_SOURCES = chksum.c dist_odpthreads_SOURCES = odpthreads.c odpthreads_LDADD = $(LIB)/libodphelper-linux.la $(LIB)/libodp-linux.la -dist_thread_SOURCES = thread.c -thread_LDADD = $(LIB)/libodphelper-linux.la $(LIB)/libodp-linux.la -dist_process_SOURCES = process.c dist_parse_SOURCES = parse.c -process_LDADD = $(LIB)/libodphelper-linux.la $(LIB)/libodp-linux.la dist_table_SOURCES = table.c diff --git a/helper/test/process.c b/helper/test/process.c deleted file mode 100644 index 0e04224..0000000 --- a/helper/test/process.c +++ /dev/null @@ -1,92 +0,0 @@ -/* Copyright (c) 2015, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include <test_debug.h> -#include <odp_api.h> -#include <odp/helper/linux.h> - -#define NUMBER_WORKERS 16 /* 0 = max */ - -static void *worker_fn(void *arg TEST_UNUSED) -{ - /* depend on the odp helper to call odp_init_local */ - printf("Worker thread on CPU %d\n", odp_cpu_id()); - - return 0; -} - -/* Create additional dataplane processes */ -int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) -{ - odp_cpumask_t cpu_mask; - int num_workers; - int cpu; - char cpumaskstr[ODP_CPUMASK_STR_SIZE]; - int ret; - odph_linux_process_t proc[NUMBER_WORKERS]; - odp_instance_t instance; - odph_linux_thr_params_t thr_params; - - if (odp_init_global(&instance, NULL, NULL)) { - LOG_ERR("Error: ODP global init failed.\n"); - exit(EXIT_FAILURE); - } - - if (odp_init_local(instance, ODP_THREAD_CONTROL)) { - LOG_ERR("Error: ODP local init failed.\n"); - exit(EXIT_FAILURE); - } - - /* discover how many processes this system can support */ - num_workers = odp_cpumask_default_worker(&cpu_mask, NUMBER_WORKERS); - if (num_workers < NUMBER_WORKERS) { - printf("System can only support %d processes and not the %d requested\n", - num_workers, NUMBER_WORKERS); - } - - /* generate a summary for the user */ - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, sizeof(cpumaskstr)); - printf("default cpu mask: %s\n", cpumaskstr); - printf("default num worker processes: %i\n", num_workers); - - cpu = odp_cpumask_first(&cpu_mask); - printf("the first CPU: %i\n", cpu); - - /* reserve cpu 0 for the control plane so remove it from - * the default mask */ - odp_cpumask_clr(&cpu_mask, 0); - num_workers = odp_cpumask_count(&cpu_mask); - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, sizeof(cpumaskstr)); - printf("new cpu mask: %s\n", cpumaskstr); - printf("new num worker processes: %i\n\n", num_workers); - - memset(&thr_params, 0, sizeof(thr_params)); - thr_params.thr_type = ODP_THREAD_WORKER; - thr_params.instance = instance; - - /* Fork worker processes */ - ret = odph_linux_process_fork_n(proc, &cpu_mask, &thr_params); - - if (ret < 0) { - LOG_ERR("Fork workers failed %i\n", ret); - return -1; - } - - if (ret == 0) { - /* Child process */ - worker_fn(NULL); - } else { - /* Parent process */ - odph_linux_process_wait_n(proc, num_workers); - - if (odp_term_global(instance)) { - LOG_ERR("Error: ODP global term failed.\n"); - exit(EXIT_FAILURE); - } - } - - return 0; -} diff --git a/helper/test/thread.c b/helper/test/thread.c deleted file mode 100644 index 8268d9f..0000000 --- a/helper/test/thread.c +++ /dev/null @@ -1,87 +0,0 @@ -/* Copyright (c) 2015, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include <test_debug.h> -#include <odp_api.h> -#include <odp/helper/linux.h> - -#define NUMBER_WORKERS 16 -static void *worker_fn(void *arg TEST_UNUSED) -{ - /* depend on the odp helper to call odp_init_local */ - - printf("Worker thread on CPU %d\n", odp_cpu_id()); - - /* depend on the odp helper to call odp_term_local */ - - return NULL; -} - -/* Create additional dataplane threads */ -int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) -{ - odph_linux_pthread_t thread_tbl[NUMBER_WORKERS]; - odp_cpumask_t cpu_mask; - int num_workers; - int cpu; - char cpumaskstr[ODP_CPUMASK_STR_SIZE]; - odp_instance_t instance; - odph_linux_thr_params_t thr_params; - - if (odp_init_global(&instance, NULL, NULL)) { - LOG_ERR("Error: ODP global init failed.\n"); - exit(EXIT_FAILURE); - } - - if (odp_init_local(instance, ODP_THREAD_CONTROL)) { - LOG_ERR("Error: ODP local init failed.\n"); - exit(EXIT_FAILURE); - } - - /* discover how many threads this system can support */ - num_workers = odp_cpumask_default_worker(&cpu_mask, NUMBER_WORKERS); - if (num_workers < NUMBER_WORKERS) { - printf("System can only support %d threads and not the %d requested\n", - num_workers, NUMBER_WORKERS); - } - - /* generate a summary for the user */ - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, sizeof(cpumaskstr)); - printf("default cpu mask: %s\n", cpumaskstr); - printf("default num worker threads: %i\n", num_workers); - - cpu = odp_cpumask_first(&cpu_mask); - printf("the first CPU: %i\n", cpu); - - /* reserve cpu 0 for the control plane so remove it from - * the default mask */ - odp_cpumask_clr(&cpu_mask, 0); - num_workers = odp_cpumask_count(&cpu_mask); - (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, sizeof(cpumaskstr)); - printf("new cpu mask: %s\n", cpumaskstr); - printf("new num worker threads: %i\n\n", num_workers); - - memset(&thr_params, 0, sizeof(thr_params)); - thr_params.start = worker_fn; - thr_params.arg = NULL; - thr_params.thr_type = ODP_THREAD_WORKER; - thr_params.instance = instance; - - odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, &thr_params); - odph_linux_pthread_join(thread_tbl, num_workers); - - if (odp_term_local()) { - LOG_ERR("Error: ODP local term failed.\n"); - exit(EXIT_FAILURE); - } - - if (odp_term_global(instance)) { - LOG_ERR("Error: ODP global term failed.\n"); - exit(EXIT_FAILURE); - } - - return 0; -} diff --git a/helper/linux.c b/helper/thread.c similarity index 70% rename from helper/linux.c rename to helper/thread.c index d5215c2..f946f5a 100644 --- a/helper/linux.c +++ b/helper/thread.c @@ -27,222 +27,6 @@ static struct { int proc; /* true when process mode is required, false otherwise */ } helper_options; -static void *odp_run_start_routine(void *arg) -{ - odph_linux_thr_params_t *thr_params = arg; - - /* ODP thread local init */ - if (odp_init_local(thr_params->instance, thr_params->thr_type)) { - ODPH_ERR("Local init failed\n"); - return NULL; - } - - void *ret_ptr = thr_params->start(thr_params->arg); - int ret = odp_term_local(); - - if (ret < 0) - ODPH_ERR("Local term failed\n"); - else if (ret == 0 && odp_term_global(thr_params->instance)) - ODPH_ERR("Global term failed\n"); - - return ret_ptr; -} - -int odph_linux_pthread_create(odph_linux_pthread_t *pthread_tbl, - const odp_cpumask_t *mask, - const odph_linux_thr_params_t *thr_params) -{ - int i; - int num; - int cpu_count; - int cpu; - int ret; - - num = odp_cpumask_count(mask); - - memset(pthread_tbl, 0, num * sizeof(odph_linux_pthread_t)); - - cpu_count = odp_cpu_count(); - - if (num < 1 || num > cpu_count) { - ODPH_ERR("Invalid number of threads:%d (%d cores available)\n", - num, cpu_count); - return 0; - } - - cpu = odp_cpumask_first(mask); - for (i = 0; i < num; i++) { - cpu_set_t cpu_set; - - CPU_ZERO(&cpu_set); - CPU_SET(cpu, &cpu_set); - - pthread_attr_init(&pthread_tbl[i].attr); - - pthread_tbl[i].cpu = cpu; - - pthread_attr_setaffinity_np(&pthread_tbl[i].attr, - sizeof(cpu_set_t), &cpu_set); - - pthread_tbl[i].thr_params.start = thr_params->start; - pthread_tbl[i].thr_params.arg = thr_params->arg; - pthread_tbl[i].thr_params.thr_type = thr_params->thr_type; - pthread_tbl[i].thr_params.instance = thr_params->instance; - - ret = pthread_create(&pthread_tbl[i].thread, - &pthread_tbl[i].attr, - odp_run_start_routine, - &pthread_tbl[i].thr_params); - if (ret != 0) { - ODPH_ERR("Failed to start thread on cpu #%d\n", cpu); - break; - } - - cpu = odp_cpumask_next(mask, cpu); - } - - return i; -} - -void odph_linux_pthread_join(odph_linux_pthread_t *thread_tbl, int num) -{ - int i; - int ret; - - for (i = 0; i < num; i++) { - /* Wait thread to exit */ - ret = pthread_join(thread_tbl[i].thread, NULL); - if (ret != 0) { - ODPH_ERR("Failed to join thread from cpu #%d\n", - thread_tbl[i].cpu); - } - pthread_attr_destroy(&thread_tbl[i].attr); - } -} - -int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl, - const odp_cpumask_t *mask, - const odph_linux_thr_params_t *thr_params) -{ - pid_t pid; - int num; - int cpu_count; - int cpu; - int i; - - num = odp_cpumask_count(mask); - - memset(proc_tbl, 0, num * sizeof(odph_linux_process_t)); - - cpu_count = odp_cpu_count(); - - if (num < 1 || num > cpu_count) { - ODPH_ERR("Bad num\n"); - return -1; - } - - cpu = odp_cpumask_first(mask); - for (i = 0; i < num; i++) { - cpu_set_t cpu_set; - - CPU_ZERO(&cpu_set); - CPU_SET(cpu, &cpu_set); - - pid = fork(); - - if (pid < 0) { - ODPH_ERR("fork() failed\n"); - return -1; - } - - /* Parent continues to fork */ - if (pid > 0) { - proc_tbl[i].pid = pid; - proc_tbl[i].cpu = cpu; - - cpu = odp_cpumask_next(mask, cpu); - continue; - } - - /* Child process */ - - /* Request SIGTERM if parent dies */ - prctl(PR_SET_PDEATHSIG, SIGTERM); - /* Parent died already? */ - if (getppid() == 1) - kill(getpid(), SIGTERM); - - if (sched_setaffinity(0, sizeof(cpu_set_t), &cpu_set)) { - ODPH_ERR("sched_setaffinity() failed\n"); - return -2; - } - - if (odp_init_local(thr_params->instance, - thr_params->thr_type)) { - ODPH_ERR("Local init failed\n"); - return -2; - } - - return 0; - } - - return 1; -} - -int odph_linux_process_fork(odph_linux_process_t *proc, int cpu, - const odph_linux_thr_params_t *thr_params) -{ - odp_cpumask_t mask; - - odp_cpumask_zero(&mask); - odp_cpumask_set(&mask, cpu); - return odph_linux_process_fork_n(proc, &mask, thr_params); -} - -int odph_linux_process_wait_n(odph_linux_process_t *proc_tbl, int num) -{ - pid_t pid; - int i, j; - int status = 0; - - for (i = 0; i < num; i++) { - pid = wait(&status); - - if (pid < 0) { - ODPH_ERR("wait() failed\n"); - return -1; - } - - for (j = 0; j < num; j++) { - if (proc_tbl[j].pid == pid) { - proc_tbl[j].status = status; - break; - } - } - - if (j == num) { - ODPH_ERR("Bad pid:%d\n", (int)pid); - return -1; - } - - /* Examine the child process' termination status */ - if (WIFEXITED(status) && WEXITSTATUS(status) != EXIT_SUCCESS) { - ODPH_ERR("Child exit status:%d (pid:%d)\n", - WEXITSTATUS(status), (int)pid); - return -1; - } - if (WIFSIGNALED(status)) { - int signo = WTERMSIG(status); - - ODPH_ERR("Child term signo:%d - %s (pid:%d)\n", - signo, strsignal(signo), (int)pid); - return -1; - } - } - - return 0; -} - /* * wrapper for odpthreads, either implemented as linux threads or processes. * (in process mode, if start_routine returns NULL, the process return FAILURE).
Signed-off-by: Mike Holmes <mike.holmes@linaro.org> --- helper/Makefile.am | 2 +- helper/include/odp/helper/threads.h | 83 +------------- helper/test/Makefile.am | 6 - helper/test/process.c | 92 --------------- helper/test/thread.c | 87 --------------- helper/{linux.c => thread.c} | 216 ------------------------------------ 6 files changed, 5 insertions(+), 481 deletions(-) delete mode 100644 helper/test/process.c delete mode 100644 helper/test/thread.c rename helper/{linux.c => thread.c} (70%) -- 2.9.3