From patchwork Wed May 11 16:41:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 67570 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp298882qge; Wed, 11 May 2016 08:57:34 -0700 (PDT) X-Received: by 10.140.248.84 with SMTP id t81mr4571783qhc.94.1462982254288; Wed, 11 May 2016 08:57:34 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id o71si5630886qkh.85.2016.05.11.08.57.33; Wed, 11 May 2016 08:57:34 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id D831361663; Wed, 11 May 2016 15:57:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 724C6616CA; Wed, 11 May 2016 15:46:24 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 25997616C3; Wed, 11 May 2016 15:46:11 +0000 (UTC) Received: from mail-lf0-f41.google.com (mail-lf0-f41.google.com [209.85.215.41]) by lists.linaro.org (Postfix) with ESMTPS id EF62F61657 for ; Wed, 11 May 2016 15:44:20 +0000 (UTC) Received: by mail-lf0-f41.google.com with SMTP id y84so54204860lfc.0 for ; Wed, 11 May 2016 08:44:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OJYnYAq9M3mcdcVS2rls62jzy8+Y9W/65zJetrQbkb4=; b=Ghi76iqkUps//SIEkElw3HzNx9hcGrnNqMFtk6kCo4VqL9vXiHGlrEe8IA4i/F4ZW+ hsiHbU1yGkUB8ahIDA7enf3JCKmjBYxRm2/D1cUz3ycp2oAlqMeCr/JeqfowCM8BzixX LHyYX2/c2tZn3mYuRU/Tw/zyeaVDjnhXX/lgfU3/I8jtV9/lwB0hd6s0DDa/yoajuPM0 tE45D2tipmosUFHO/Dhr97as6xpQDXSCBUW1WULmdQbZSEA73SP6SjWbigLvhavGjgWy B7r6XeJCNlZunSCau84l5gw6q9W7VIfyx4fIz2rPzmpAZWdSAI4FpYFCoDD5XRW1T028 ecyQ== X-Gm-Message-State: AOPr4FX+ux5ltIpWRRrFGURPz7ggs7CpgaBpFwC6zo3we491pITj64LP0jO4sTkf0Z8HdSfiGAM= X-Received: by 10.25.152.133 with SMTP id a127mr1946361lfe.36.1462981459888; Wed, 11 May 2016 08:44:19 -0700 (PDT) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-90-46.cust.bredband2.com. [83.233.90.46]) by smtp.gmail.com with ESMTPSA id n37sm1421164lfg.46.2016.05.11.08.44.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 May 2016 08:44:19 -0700 (PDT) From: Christophe Milard To: brian.brooks@linaro.org, mike.holmes@linaro.org, lng-odp@lists.linaro.org Date: Wed, 11 May 2016 18:41:57 +0200 Message-Id: <1462984942-53326-14-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1462984942-53326-1-git-send-email-christophe.milard@linaro.org> References: <1462984942-53326-1-git-send-email-christophe.milard@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv6 13/38] performance: odp_scheduling: proc mode done by helper X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" 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 --- 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;