From patchwork Tue Feb 16 14:54:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gary.robertson@linaro.org X-Patchwork-Id: 62037 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1710773lbl; Tue, 16 Feb 2016 06:55:29 -0800 (PST) X-Received: by 10.140.19.147 with SMTP id 19mr27835116qgh.70.1455634529703; Tue, 16 Feb 2016 06:55:29 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id f185si40929913qkb.71.2016.02.16.06.55.29; Tue, 16 Feb 2016 06:55:29 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 0677F617EE; Tue, 16 Feb 2016 14:55:29 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=hewODNao; dkim-adsp=none (unprotected policy); dkim-atps=neutral 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.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, 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 C8F7361720; Tue, 16 Feb 2016 14:55:17 +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 632D461752; Tue, 16 Feb 2016 14:55:10 +0000 (UTC) Received: from mail-ob0-f177.google.com (mail-ob0-f177.google.com [209.85.214.177]) by lists.linaro.org (Postfix) with ESMTPS id 13DA86162C for ; Tue, 16 Feb 2016 14:55:06 +0000 (UTC) Received: by mail-ob0-f177.google.com with SMTP id jq7so77374780obb.0 for ; Tue, 16 Feb 2016 06:55:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EkD8ZOzJ0wXfANN8DVSyz2CscOOv8szgHFs/XySaKJ8=; b=hewODNao+Z2PSCxRTXpMnd0hOGzDWQrwErsVfua9C508yJovwOHc053tjiMYHfYTGT ODLfK5fQ3xqMhxji/q7mM9WWd1gtLht4MRcUHYfrvnWyBI1uAY/ySJGF4oHE6auZeQet OJ0d7XmiO7dzISadkZOTyjsHOMfIGjlTeJWRw= 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=EkD8ZOzJ0wXfANN8DVSyz2CscOOv8szgHFs/XySaKJ8=; b=Yca3noEYTzBfKCAeq+DDFWMeYCFf6BMfSZt/GxHvCZuDagDzepgUggEQTdcRoqdBeR p87sVaY963z0dZlAypC4nnOq6mGYd5AzMj/V1bueB2BkhnFN1o3UairtXYorYx6CS6pL 4SbBtpDRI1Q1o5ZCPelg5l4NfM5Olj/iTyuF4D2xxg5mq7ZK+r1VoXBrNAMrER6IaTcP 9b4olED07mMIpQ96Yu/ivVOy1W6LuuViGBylRN0cqamGQjHTwp775iYbj3HWre7A8N89 caL6T0lmZYoIaiSiOqTxedV4EZtsl07qg5ST05tlrDVFmEwR+rg+cjUUd8/mnWRtU6ws ts1w== X-Gm-Message-State: AG10YOQfpOSw82Tpzsu0VxpT5QqccTN1jTm2izh/gxiKxTnTYw0ukh9bsxIZG/xTjCCADhrsNS8= X-Received: by 10.182.108.229 with SMTP id hn5mr17780367obb.75.1455634474865; Tue, 16 Feb 2016 06:54:34 -0800 (PST) Received: from honkintosh.cybertech.lan (65-120-133-114.dia.static.qwest.net. [65.120.133.114]) by smtp.googlemail.com with ESMTPSA id h127sm11292528oib.12.2016.02.16.06.54.33 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 16 Feb 2016 06:54:34 -0800 (PST) From: "Gary S. Robertson" To: mike.holmes@linaro.org, bill.fischofer@linaro.org, maxim.uvarov@linaro.org, anders.roxell@linaro.org, petri.savolainen@linaro.org Date: Tue, 16 Feb 2016 08:54:19 -0600 Message-Id: <1455634460-26806-2-git-send-email-gary.robertson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455634460-26806-1-git-send-email-gary.robertson@linaro.org> References: <56C2ED44.5010209@linaro.org> <1455634460-26806-1-git-send-email-gary.robertson@linaro.org> X-Topics: patch Cc: lng-odp@lists.linaro.org Subject: [lng-odp] [PATCH V2 1/2] linux-generic: Correct worker count calculation in tests 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" During the process of addressing Linaro BUG 2027 which relates to inaccurate reporting of available CPUs by ODP linux-generic when running atop a kernel compiled with NO_HZ_FULL support, a number of instances were encountered in the validation and performance test software where incorrect methods were used to determine the proper (or maximum) number of worker threads to create. The use of odp_cpu_count() for this purpose is incorrect and deprecated... odp_cpumask_default_worker() should always be used to determine the set and number of CPUs available for creating worker threads. The use of odp_cpu_count() for this purpose in conjunction with the correct means of determining available CPUs resulted in some tests hanging in calls to odp_barrier_wait() as the barriers were initialized to expect threads on ALL CPUs rather than on worker CPUs alone... and there were too few worker threads created to satisfy the barriers. The changes below correct all instances I could find of this depecated technique and allowed all tests to complete successfully with the BUG 2027 patch applied. (BTW they also run correctly without that patch after the application of the modifications included here.) Signed-off-by: Gary S. Robertson --- test/api_test/odp_common.c | 4 +++- test/api_test/odp_ring_test.c | 4 +++- test/performance/odp_atomic.c | 9 ++++++--- test/validation/cpumask/cpumask.c | 2 +- test/validation/shmem/shmem.c | 5 ++++- test/validation/timer/timer.c | 16 +++++++++------- 6 files changed, 26 insertions(+), 14 deletions(-) diff --git a/test/api_test/odp_common.c b/test/api_test/odp_common.c index 70aee96..e89acf1 100644 --- a/test/api_test/odp_common.c +++ b/test/api_test/odp_common.c @@ -53,6 +53,8 @@ void odp_print_system_info(void) /** test init globals and call odp_init_global() */ int odp_test_global_init(void) { + odp_cpumask_t unused; + memset(thread_tbl, 0, sizeof(thread_tbl)); if (odp_init_global(NULL, NULL)) { @@ -60,7 +62,7 @@ int odp_test_global_init(void) return -1; } - num_workers = odp_cpu_count(); + num_workers = odp_cpumask_default_worker(&unused, 0); /* force to max CPU count */ if (num_workers > MAX_WORKERS) num_workers = MAX_WORKERS; diff --git a/test/api_test/odp_ring_test.c b/test/api_test/odp_ring_test.c index e8a962a..51e9121 100644 --- a/test/api_test/odp_ring_test.c +++ b/test/api_test/odp_ring_test.c @@ -51,6 +51,7 @@ #include #include #include +#include #define RING_SIZE 4096 #define MAX_BULK 32 @@ -422,6 +423,7 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) { ring_arg_t rarg; + odp_cpumask_t unused; if (odp_test_global_init() != 0) return -1; @@ -430,7 +432,7 @@ int main(int argc __attribute__((__unused__)), odph_ring_tailq_init(); - rarg.thrdarg.numthrds = odp_cpu_count(); + rarg.thrdarg.numthrds = odp_cpumask_default_worker(&unused, 0); #ifdef RING_TEST_BASIC rarg.thrdarg.testcase = ODP_RING_TEST_BASIC; diff --git a/test/performance/odp_atomic.c b/test/performance/odp_atomic.c index 067329b..7e2e22f 100644 --- a/test/performance/odp_atomic.c +++ b/test/performance/odp_atomic.c @@ -303,6 +303,8 @@ int odp_test_thread_exit(pthrd_arg *arg) /** test init globals and call odp_init_global() */ int odp_test_global_init(void) { + odp_cpumask_t unused; + memset(thread_tbl, 0, sizeof(thread_tbl)); if (odp_init_global(NULL, NULL)) { @@ -310,7 +312,8 @@ int odp_test_global_init(void) return -1; } - num_workers = odp_cpu_count(); + num_workers = odp_cpumask_default_worker(&unused, 0); + /* force to max CPU count */ if (num_workers > MAX_WORKERS) num_workers = MAX_WORKERS; @@ -378,7 +381,7 @@ int main(int argc, char *argv[]) goto err_exit; } if (test_type < TEST_MIX || test_type > TEST_MAX || - pthrdnum > odp_cpu_count() || pthrdnum < 0) { + pthrdnum > num_workers || pthrdnum < 0) { usage(); goto err_exit; } @@ -386,7 +389,7 @@ int main(int argc, char *argv[]) } if (pthrdnum == 0) - pthrdnum = odp_cpu_count(); + pthrdnum = num_workers; test_atomic_init(); test_atomic_store(); diff --git a/test/validation/cpumask/cpumask.c b/test/validation/cpumask/cpumask.c index 2419f47..1bb8f8d 100644 --- a/test/validation/cpumask/cpumask.c +++ b/test/validation/cpumask/cpumask.c @@ -67,7 +67,7 @@ void cpumask_test_odp_cpumask_def(void) mask_count = odp_cpumask_count(&mask); CU_ASSERT(mask_count == num_control); - CU_ASSERT(num_control == 1); + CU_ASSERT(num_control >= 1); CU_ASSERT(num_worker <= available_cpus); CU_ASSERT(num_worker > 0); } diff --git a/test/validation/shmem/shmem.c b/test/validation/shmem/shmem.c index 08425e6..be8bd6f 100644 --- a/test/validation/shmem/shmem.c +++ b/test/validation/shmem/shmem.c @@ -6,6 +6,8 @@ #include #include +#include + #include "shmem.h" #define ALIGE_SIZE (128) @@ -52,6 +54,7 @@ void shmem_test_odp_shm_sunnyday(void) pthrd_arg thrdarg; odp_shm_t shm; test_shared_data_t *test_shared_data; + odp_cpumask_t unused; shm = odp_shm_reserve(TESTNAME, sizeof(test_shared_data_t), ALIGE_SIZE, 0); @@ -70,7 +73,7 @@ void shmem_test_odp_shm_sunnyday(void) test_shared_data->foo = TEST_SHARE_FOO; test_shared_data->bar = TEST_SHARE_BAR; - thrdarg.numthrds = odp_cpu_count(); + thrdarg.numthrds = odp_cpumask_default_worker(&unused, 0); if (thrdarg.numthrds > MAX_WORKERS) thrdarg.numthrds = MAX_WORKERS; diff --git a/test/validation/timer/timer.c b/test/validation/timer/timer.c index 004670a..bee3e8d 100644 --- a/test/validation/timer/timer.c +++ b/test/validation/timer/timer.c @@ -15,6 +15,7 @@ #include #include +#include #include "odp_cunit_common.h" #include "test_debug.h" #include "timer.h" @@ -41,12 +42,6 @@ static odp_atomic_u32_t ndelivtoolate; * caches may make this number lower than the capacity of the pool */ static odp_atomic_u32_t timers_allocated; -/** @private min() function */ -static int min(int a, int b) -{ - return a < b ? a : b; -} - /* @private Timer helper structure */ struct test_timer { odp_timer_t tim; /* Timer handle */ @@ -457,10 +452,17 @@ void timer_test_odp_timer_all(void) int rc; odp_pool_param_t params; odp_timer_pool_param_t tparam; + odp_cpumask_t unused; + /* Reserve at least one core for running other processes so the timer * test hopefully can run undisturbed and thus get better timing * results. */ - int num_workers = min(odp_cpu_count() - 1, MAX_WORKERS); + int num_workers = odp_cpumask_default_worker(&unused, 0); + + /* force to max CPU count */ + if (num_workers > MAX_WORKERS) + num_workers = MAX_WORKERS; + /* On a single-CPU machine run at least one thread */ if (num_workers < 1) num_workers = 1;