Remove the --proc option from odp_scheduling.c and use the helper
functions (odph_odpthreads_create, odph_odpthreads_join)
to handle odp threads. Let helper parse its command line args, hence
recognising the --odph_proc option doing what --proc did.

Signed-off-by: Christophe Milard <christophe.mil...@linaro.org>
---
 test/performance/odp_scheduling.c | 91 +++++++++++++--------------------------
 1 file changed, 31 insertions(+), 60 deletions(-)

diff --git a/test/performance/odp_scheduling.c 
b/test/performance/odp_scheduling.c
index 6592277..3902765 100644
--- a/test/performance/odp_scheduling.c
+++ b/test/performance/odp_scheduling.c
@@ -49,7 +49,6 @@ typedef struct {
 /** Test arguments */
 typedef struct {
        int cpu_count;  /**< CPU count */
-       int proc_mode;  /**< Process mode */
 } test_args_t;
 
 
@@ -591,9 +590,9 @@ static int test_schedule_multi(const char *str, int thr,
  *
  * @param arg  Arguments
  *
- * @return NULL on failure
+ * @return non zero on failure
  */
-static void *run_thread(void *arg)
+static int run_thread(void *arg ODP_UNUSED)
 {
        int thr;
        odp_pool_t msg_pool;
@@ -610,7 +609,7 @@ static void *run_thread(void *arg)
 
        if (globals == NULL) {
                LOG_ERR("Shared mem lookup failed\n");
-               return NULL;
+               return -1;
        }
 
        barrier = &globals->barrier;
@@ -630,23 +629,23 @@ static void *run_thread(void *arg)
 
        if (msg_pool == ODP_POOL_INVALID) {
                LOG_ERR("  [%i] msg_pool not found\n", thr);
-               return NULL;
+               return -1;
        }
 
        odp_barrier_wait(barrier);
 
        if (test_alloc_single(thr, msg_pool))
-               return NULL;
+               return -1;
 
        odp_barrier_wait(barrier);
 
        if (test_alloc_multi(thr, msg_pool))
-               return NULL;
+               return -1;
 
        odp_barrier_wait(barrier);
 
        if (test_plain_queue(thr, msg_pool))
-               return NULL;
+               return -1;
 
        /* Low prio */
 
@@ -654,19 +653,19 @@ static void *run_thread(void *arg)
 
        if (test_schedule_single("sched_____s_lo", thr, msg_pool,
                                 ODP_SCHED_PRIO_LOWEST, barrier))
-               return NULL;
+               return -1;
 
        odp_barrier_wait(barrier);
 
        if (test_schedule_many("sched_____m_lo", thr, msg_pool,
                               ODP_SCHED_PRIO_LOWEST, barrier))
-               return NULL;
+               return -1;
 
        odp_barrier_wait(barrier);
 
        if (test_schedule_multi("sched_multi_lo", thr, msg_pool,
                                ODP_SCHED_PRIO_LOWEST, barrier))
-               return NULL;
+               return -1;
 
        /* High prio */
 
@@ -674,24 +673,24 @@ static void *run_thread(void *arg)
 
        if (test_schedule_single("sched_____s_hi", thr, msg_pool,
                                 ODP_SCHED_PRIO_HIGHEST, barrier))
-               return NULL;
+               return -1;
 
        odp_barrier_wait(barrier);
 
        if (test_schedule_many("sched_____m_hi", thr, msg_pool,
                               ODP_SCHED_PRIO_HIGHEST, barrier))
-               return NULL;
+               return -1;
 
        odp_barrier_wait(barrier);
 
        if (test_schedule_multi("sched_multi_hi", thr, msg_pool,
                                ODP_SCHED_PRIO_HIGHEST, barrier))
-               return NULL;
+               return -1;
 
 
        printf("Thread %i exits\n", thr);
        fflush(NULL);
-       return arg;
+       return 0;
 }
 
 /**
@@ -762,24 +761,25 @@ static void parse_args(int argc, char *argv[], 
test_args_t *args)
        int opt;
        int long_index;
 
-       static struct option longopts[] = {
+       static const struct option longopts[] = {
                {"count", required_argument, NULL, 'c'},
                {"help", no_argument, NULL, 'h'},
-               {"proc", no_argument, NULL, 0},
                {NULL, 0, NULL, 0}
        };
 
+       static const char *shortopts = "+c:h";
+
+       /* let helper collect its own arguments (e.g. --odph_proc) */
+       odph_parse_options(argc, argv, shortopts, longopts);
+
+       opterr = 0; /* do not issue errors on helper options */
        while (1) {
-               opt = getopt_long(argc, argv, "+c:h", longopts, &long_index);
+               opt = getopt_long(argc, argv, shortopts, longopts, &long_index);
 
                if (opt == -1)
                        break;  /* No more options */
 
                switch (opt) {
-               case 0:
-                       args->proc_mode = 1;
-                       break;
-
                case 'c':
                        args->cpu_count = atoi(optarg);
                        break;
@@ -801,7 +801,7 @@ static void parse_args(int argc, char *argv[], test_args_t 
*args)
  */
 int main(int argc, char *argv[])
 {
-       odph_linux_pthread_t thread_tbl[MAX_WORKERS];
+       odph_odpthread_t thread_tbl[MAX_WORKERS];
        test_args_t args;
        int num_workers;
        odp_cpumask_t cpumask;
@@ -816,18 +816,13 @@ int main(int argc, char *argv[])
        int ret = 0;
        char name[] = "sched_XX_YY";
        odp_instance_t instance;
-       odph_linux_thr_params_t thr_params;
+       odph_odpthread_params_t thr_params;
 
        printf("\nODP example starts\n\n");
 
        memset(&args, 0, sizeof(args));
        parse_args(argc, argv, &args);
 
-       if (args.proc_mode)
-               printf("Process mode\n");
-       else
-               printf("Thread mode\n");
-
        memset(thread_tbl, 0, sizeof(thread_tbl));
 
        /* ODP global init */
@@ -953,42 +948,18 @@ int main(int argc, char *argv[])
        /* Barrier to sync test case execution */
        odp_barrier_init(&globals->barrier, num_workers);
 
+       /* Create and launch worker threads */
        memset(&thr_params, 0, sizeof(thr_params));
        thr_params.thr_type = ODP_THREAD_WORKER;
        thr_params.instance = instance;
+       thr_params.start = run_thread;
+       thr_params.arg   = NULL;
+       odph_odpthreads_create(thread_tbl, &cpumask, &thr_params);
 
-       if (args.proc_mode) {
-               odph_linux_process_t proc[MAX_WORKERS];
-
-               /* Fork worker processes */
-               ret = odph_linux_process_fork_n(proc, &cpumask, &thr_params);
-
-               if (ret < 0) {
-                       LOG_ERR("Fork workers failed %i\n", ret);
-                       return -1;
-               }
-
-               if (ret == 0) {
-                       /* Child process */
-                       run_thread(NULL);
-               } else {
-                       /* Parent process */
-                       odph_linux_process_wait_n(proc, num_workers);
-                       printf("ODP example complete\n\n");
-               }
-
-       } else {
-               thr_params.start = run_thread;
-               thr_params.arg   = NULL;
+       /* Wait for worker threads to terminate */
+       odph_odpthreads_join(thread_tbl);
 
-               /* Create and launch worker threads */
-               odph_linux_pthread_create(thread_tbl, &cpumask, &thr_params);
-
-               /* Wait for worker threads to terminate */
-               odph_linux_pthread_join(thread_tbl, num_workers);
-
-               printf("ODP example complete\n\n");
-       }
+       printf("ODP example complete\n\n");
 
        for (i = 0; i < prios; i++) {
                odp_queue_t queue;
-- 
2.5.0

_______________________________________________
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to