From patchwork Fri Jan 20 05:22:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wang X-Patchwork-Id: 92028 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp619512qgi; Thu, 19 Jan 2017 21:23:06 -0800 (PST) X-Received: by 10.55.189.70 with SMTP id n67mr10857019qkf.204.1484889785874; Thu, 19 Jan 2017 21:23:05 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id a28si4168413qta.159.2017.01.19.21.23.05; Thu, 19 Jan 2017 21:23:05 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 874E662D30; Fri, 20 Jan 2017 05:23:05 +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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, 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 9A0CF62D00; Fri, 20 Jan 2017 05:22:57 +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 B4CE662D0B; Fri, 20 Jan 2017 05:22:53 +0000 (UTC) Received: from mail-pf0-f177.google.com (mail-pf0-f177.google.com [209.85.192.177]) by lists.linaro.org (Postfix) with ESMTPS id E54FA62CFC for ; Fri, 20 Jan 2017 05:22:24 +0000 (UTC) Received: by mail-pf0-f177.google.com with SMTP id e4so19436771pfg.1 for ; Thu, 19 Jan 2017 21:22:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=niOJilMKDOS1luXekRf338iI1Z6JRA1ffr8mTjkjZFk=; b=a79w4sGagIEFHBIU5n2qhEioY/DDstbT8l/wo/CxdG+osUoAyQCeJsWTfd3pWdSw8x pXswpEjGaI925wMyPoO0sCFyVsdFQDHUnPR4Icq4PlWMtCO6kmj8Zq5kAr0QTdJIxnWP Pwi/5MAsENrNG8D7ord95f0kixdwq2BctY6j55un2WPdcxFj5zew9qYP83UZwZsdG1vh 30MoJRErkMOhZ07TlFhGJ+wBluNn5IZfcVmAxaCknj1MV6bwuoDq7uWXAvLnAE6RGZjn Ve+logF6Qu4T+7L79MYTNQ9faLG8IRLXJiAwjlt/AvlGEBeh38WMBac52APW0fr3avVU 4B9w== X-Gm-Message-State: AIkVDXKpyY+jyVB2ueXjH156AkL/6VcN8lk7c2Q0Ox9H7iVAtH4Kf0Cwym4IrCAgcTN+ST0PvCc= X-Received: by 10.84.214.150 with SMTP id j22mr18894001pli.23.1484889744108; Thu, 19 Jan 2017 21:22:24 -0800 (PST) Received: from ubuntu.heyii.co (ubuntu.heyii.co. [45.32.66.203]) by smtp.googlemail.com with ESMTPSA id s17sm12782888pgo.27.2017.01.19.21.22.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Jan 2017 21:22:23 -0800 (PST) From: Kevin Wang To: lng-odp@lists.linaro.org Date: Fri, 20 Jan 2017 05:22:20 +0000 Message-Id: <1484889740-15122-1-git-send-email-kevin.wang@linaro.org> X-Mailer: git-send-email 1.9.1 Subject: [lng-odp] [API-NEXT PATCH 3/4] validation/example: call odp_timer_capability() before creating a timer pool 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Use odp_timer_capability() to determine the max timer resolution Signed-off-by: Kevin Wang --- example/generator/odp_generator.c | 8 +++++++- example/timer/odp_timer_simple.c | 9 ++++++++- example/timer/odp_timer_test.c | 6 +++++- test/common_plat/validation/api/timer/timer.c | 28 ++++++++++++++++++--------- 4 files changed, 39 insertions(+), 12 deletions(-) -- 1.9.1 diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index ccd47f6..4bf4ac6 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -34,6 +34,7 @@ #define APPL_MODE_UDP 0 /**< UDP mode */ #define APPL_MODE_PING 1 /**< ping mode */ #define APPL_MODE_RCV 2 /**< receive mode */ +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) /** print appl mode */ #define PRINT_APPL_MODE(x) printf("%s(%i)\n", #x, (x)) @@ -638,6 +639,7 @@ int main(int argc, char *argv[]) odp_pktio_t *pktio; odp_instance_t instance; odph_odpthread_params_t thr_params; + odp_timer_capability_t timer_capa; /* Init ODP before calling anything else */ if (odp_init_global(&instance, NULL, NULL)) { @@ -718,7 +720,11 @@ int main(int argc, char *argv[]) odp_pool_print(pool); /* Create timer pool */ - tparams.res_ns = 1 * ODP_TIME_MSEC_IN_NS; + if (odp_timer_capability(ODP_CLOCK_CPU, &timer_capa)) { + EXAMPLE_ERR("Error: get timer capacity failed.\n"); + exit(EXIT_FAILURE); + } + tparams.res_ns = MAX(1 * ODP_TIME_MSEC_IN_NS, timer_capa.res_ns); tparams.min_tmo = 0; tparams.max_tmo = 10000 * ODP_TIME_SEC_IN_NS; tparams.num_timers = num_workers; /* One timer per worker */ diff --git a/example/timer/odp_timer_simple.c b/example/timer/odp_timer_simple.c index 70804bb..631bbcc 100644 --- a/example/timer/odp_timer_simple.c +++ b/example/timer/odp_timer_simple.c @@ -18,6 +18,8 @@ /* ODP main header */ #include +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) + int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED) { odp_instance_t instance; @@ -35,6 +37,7 @@ int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED) uint64_t tick; odp_timeout_t tmo; int ret = 0; + odp_timer_capability_t timer_capa; /* * Init ODP app @@ -61,7 +64,11 @@ int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED) /* * Create pool of timeouts */ - tparams.res_ns = 10 * ODP_TIME_MSEC_IN_NS; + if (odp_timer_capability(ODP_CLOCK_CPU, &timer_capa)) { + ret += 1; + goto err_tp; + } + tparams.res_ns = MAX(10 * ODP_TIME_MSEC_IN_NS, timer_capa.res_ns); tparams.min_tmo = 10 * ODP_TIME_MSEC_IN_NS; tparams.max_tmo = 1 * ODP_TIME_SEC_IN_NS; tparams.num_timers = 1; /* One timer per worker */ diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c index 035ab2e..1403c1f 100644 --- a/example/timer/odp_timer_test.c +++ b/example/timer/odp_timer_test.c @@ -23,6 +23,7 @@ #define MAX_WORKERS 32 /**< Max worker threads */ #define NUM_TMOS 10000 /**< Number of timers */ #define WAIT_NUM 10 /**< Max tries to rx last tmo per worker */ +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) /** Test arguments */ @@ -259,6 +260,7 @@ static void parse_args(int argc, char *argv[], test_args_t *args) { int opt; int long_index; + odp_timer_capability_t timer_capa; static const struct option longopts[] = { {"count", required_argument, NULL, 'c'}, @@ -277,8 +279,10 @@ static void parse_args(int argc, char *argv[], test_args_t *args) odph_parse_options(argc, argv, shortopts, longopts); /* defaults */ + odp_timer_capability(ODP_CLOCK_CPU, &timer_capa); + args->cpu_count = 0; /* all CPU's */ - args->resolution_us = 10000; + args->resolution_us = MAX(10000, timer_capa.res_ns/ODP_TIME_USEC_IN_NS); args->min_us = 0; args->max_us = 10000000; args->period_us = 1000000; diff --git a/test/common_plat/validation/api/timer/timer.c b/test/common_plat/validation/api/timer/timer.c index 1945afa..326d739 100644 --- a/test/common_plat/validation/api/timer/timer.c +++ b/test/common_plat/validation/api/timer/timer.c @@ -20,6 +20,8 @@ #include "test_debug.h" #include "timer.h" +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) + /** @private Timeout range in milliseconds (ms) */ #define RANGE_MS 2000 @@ -140,6 +142,7 @@ void timer_test_odp_timer_cancel(void) odp_timeout_t tmo; odp_timer_set_t rc; uint64_t tick; + odp_timer_capability_t timer_capa; odp_pool_param_init(¶ms); params.type = ODP_POOL_TIMEOUT; @@ -150,7 +153,10 @@ void timer_test_odp_timer_cancel(void) if (pool == ODP_POOL_INVALID) CU_FAIL_FATAL("Timeout pool create failed"); - tparam.res_ns = 100 * ODP_TIME_MSEC_IN_NS; + if (odp_timer_capability(ODP_CLOCK_CPU, &timer_capa)) + CU_FAIL_FATAL("Get timer capability failed") + + tparam.res_ns = MAX(100 * ODP_TIME_MSEC_IN_NS, timer_capa.res_ns); tparam.min_tmo = 1 * ODP_TIME_SEC_IN_NS; tparam.max_tmo = 10 * ODP_TIME_SEC_IN_NS; tparam.num_timers = 1; @@ -480,6 +486,7 @@ void timer_test_odp_timer_all(void) uint64_t ns; uint64_t t2; pthrd_arg thrdarg; + odp_timer_capability_t timer_capa; /* Reserve at least one core for running other processes so the timer * test hopefully can run undisturbed and thus get better timing @@ -505,12 +512,15 @@ void timer_test_odp_timer_all(void) #define NAME "timer_pool" #define RES (10 * ODP_TIME_MSEC_IN_NS / 3) -#define MIN (10 * ODP_TIME_MSEC_IN_NS / 3) -#define MAX (1000000 * ODP_TIME_MSEC_IN_NS) +#define MIN_TMO (10 * ODP_TIME_MSEC_IN_NS / 3) +#define MAX_TMO (1000000 * ODP_TIME_MSEC_IN_NS) /* Create a timer pool */ - tparam.res_ns = RES; - tparam.min_tmo = MIN; - tparam.max_tmo = MAX; + if (odp_timer_capability(ODP_CLOCK_CPU, &timer_capa)) + CU_FAIL("Error: get timer capacity failed.\n"); + + tparam.res_ns = MAX(RES, timer_capa.res_ns); + tparam.min_tmo = MIN_TMO; + tparam.max_tmo = MAX_TMO; tparam.num_timers = num_workers * NTIMERS; tparam.priv = 0; tparam.clk_src = ODP_CLOCK_CPU; @@ -524,9 +534,9 @@ void timer_test_odp_timer_all(void) if (odp_timer_pool_info(tp, &tpinfo) != 0) CU_FAIL("odp_timer_pool_info"); CU_ASSERT(strcmp(tpinfo.name, NAME) == 0); - CU_ASSERT(tpinfo.param.res_ns == RES); - CU_ASSERT(tpinfo.param.min_tmo == MIN); - CU_ASSERT(tpinfo.param.max_tmo == MAX); + CU_ASSERT(tpinfo.param.res_ns == MAX(RES, timer_capa.res_ns)); + CU_ASSERT(tpinfo.param.min_tmo == MIN_TMO); + CU_ASSERT(tpinfo.param.max_tmo == MAX_TMO); CU_ASSERT(strcmp(tpinfo.name, NAME) == 0); LOG_DBG("Timer pool handle: %" PRIu64 "\n", odp_timer_pool_to_u64(tp));