From patchwork Thu May 19 16:26:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 68140 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp3274586qge; Thu, 19 May 2016 08:41:33 -0700 (PDT) X-Received: by 10.55.212.71 with SMTP id l68mr15530608qki.123.1463672493057; Thu, 19 May 2016 08:41:33 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id c70si13135245qka.36.2016.05.19.08.41.32; Thu, 19 May 2016 08:41:33 -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 B825E617F1; Thu, 19 May 2016 15:41:32 +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_H2, 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 5092761849; Thu, 19 May 2016 15:30:43 +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 D2AA4617F5; Thu, 19 May 2016 15:30:35 +0000 (UTC) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com [209.85.217.175]) by lists.linaro.org (Postfix) with ESMTPS id 79FF8617FF for ; Thu, 19 May 2016 15:28:39 +0000 (UTC) Received: by mail-lb0-f175.google.com with SMTP id n11so25934968lbh.1 for ; Thu, 19 May 2016 08:28:39 -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=SlnwJUsBWQpuwOuQZHpJGhKqtMLk3QYHhIiKMVmz5CA=; b=bJ/u3PHhq3zTi6Kpo5rPVm+uRS3GbVbhcb5n8I30pw2Mt/g8v1EM9wRTJZWKVHTuL2 nrI3K6K2ZS/zYo8SGk6E6wLDaBSsTG2Wk0AziY2yNAXb0IiPvhq7mBRwuVwoit+W5vaR 7vM7Zz7jJbKBhqAA0GjvNYZxP4fUgI83EMzdgiccS2AxxxemaQNRiU7kM3vNT33SMYt6 a27jSlFsK8QDpzOaw6axPIK/eaNWV/CesF0M9H3yNQMZXDU+yOfYWUKWXlUUkZv2C3Tw tHJVJWOVRwDViKxAkKl4r56dNIH384bLMqpH4YS81Bv0EDeV5hU3zacwuUu1mgF76No4 NvMw== X-Gm-Message-State: AOPr4FXPr63JSMsBSvqwuvIsR4snl6kTGwoc0dFEzUWeT4yqUoytSsOXsAMXUZZjNPqzKoCUADM= X-Received: by 10.112.20.35 with SMTP id k3mr3255595lbe.75.1463671718358; Thu, 19 May 2016 08:28:38 -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 cv11sm2366290lbb.49.2016.05.19.08.28.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 May 2016 08:28:37 -0700 (PDT) From: Christophe Milard To: brian.brooks@linaro.org, maxim.uvarov@linaro.com, lng-odp@lists.linaro.org Date: Thu, 19 May 2016 18:26:49 +0200 Message-Id: <1463675234-6739-11-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1463675234-6739-1-git-send-email-christophe.milard@linaro.org> References: <1463675234-6739-1-git-send-email-christophe.milard@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv8 10/35] 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, 30 insertions(+), 61 deletions(-) diff --git a/test/performance/odp_scheduling.c b/test/performance/odp_scheduling.c index c7a3049..1d3bfd1 100644 --- a/test/performance/odp_scheduling.c +++ b/test/performance/odp_scheduling.c @@ -51,7 +51,6 @@ typedef struct { /** Test arguments */ typedef struct { int cpu_count; /**< CPU count */ - int proc_mode; /**< Process mode */ int fairness; /**< Check fairness */ } test_args_t; @@ -562,9 +561,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_shm_t shm; @@ -580,7 +579,7 @@ static void *run_thread(void *arg) if (globals == NULL) { LOG_ERR("Shared mem lookup failed\n"); - return NULL; + return -1; } barrier = &globals->barrier; @@ -605,17 +604,17 @@ static void *run_thread(void *arg) odp_barrier_wait(barrier); if (test_alloc_single(thr, globals)) - return NULL; + return -1; odp_barrier_wait(barrier); if (test_alloc_multi(thr, globals)) - return NULL; + return -1; odp_barrier_wait(barrier); if (test_plain_queue(thr, globals)) - return NULL; + return -1; /* Low prio */ @@ -623,19 +622,19 @@ static void *run_thread(void *arg) if (test_schedule_single("sched_____s_lo", thr, ODP_SCHED_PRIO_LOWEST, globals)) - return NULL; + return -1; odp_barrier_wait(barrier); if (test_schedule_many("sched_____m_lo", thr, ODP_SCHED_PRIO_LOWEST, globals)) - return NULL; + return -1; odp_barrier_wait(barrier); if (test_schedule_multi("sched_multi_lo", thr, ODP_SCHED_PRIO_LOWEST, globals)) - return NULL; + return -1; /* High prio */ @@ -643,24 +642,24 @@ static void *run_thread(void *arg) if (test_schedule_single("sched_____s_hi", thr, ODP_SCHED_PRIO_HIGHEST, globals)) - return NULL; + return -1; odp_barrier_wait(barrier); if (test_schedule_many("sched_____m_hi", thr, ODP_SCHED_PRIO_HIGHEST, globals)) - return NULL; + return -1; odp_barrier_wait(barrier); if (test_schedule_multi("sched_multi_hi", thr, ODP_SCHED_PRIO_HIGHEST, globals)) - return NULL; + return -1; printf("Thread %i exits\n", thr); fflush(NULL); - return arg; + return 0; } /** @@ -715,7 +714,6 @@ static void print_usage(void) printf("Options:\n"); printf(" -c, --count CPU count\n"); printf(" -h, --help this help\n"); - printf(" -p, --proc process mode\n"); printf(" -f, --fair collect fairness statistics\n"); printf("\n\n"); } @@ -732,26 +730,26 @@ 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'}, - {"proc", no_argument, NULL, 'p'}, {"fair", no_argument, NULL, 'f'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0} }; + static const char *shortopts = "+c:fh"; + + /* 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:pfh", - longopts, &long_index); + opt = getopt_long(argc, argv, shortopts, longopts, &long_index); if (opt == -1) break; /* No more options */ switch (opt) { - case 'p': - args->proc_mode = 1; - break; - case 'f': args->fairness = 1; break; @@ -777,7 +775,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; @@ -790,18 +788,13 @@ int main(int argc, char *argv[]) odp_pool_param_t params; int ret = 0; 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 */ @@ -944,42 +937,18 @@ int main(int argc, char *argv[]) odp_spinlock_init(&globals->lock); globals->first_thr = -1; + /* 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; - } + /* Wait for worker threads to terminate */ + odph_odpthreads_join(thread_tbl); - 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; - - /* 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 < NUM_PRIOS; i++) { odp_queue_t queue;