From patchwork Wed Feb 8 02:37:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wang X-Patchwork-Id: 93598 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2485014qgi; Tue, 7 Feb 2017 18:38:19 -0800 (PST) X-Received: by 10.55.192.196 with SMTP id v65mr17869290qkv.40.1486521499200; Tue, 07 Feb 2017 18:38:19 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id s65si4501068qtd.192.2017.02.07.18.38.18; Tue, 07 Feb 2017 18:38:19 -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 C630962FB6; Wed, 8 Feb 2017 02:38:18 +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 6123362DFC; Wed, 8 Feb 2017 02:38:11 +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 41BAE62DFC; Wed, 8 Feb 2017 02:38:06 +0000 (UTC) Received: from mail-pf0-f181.google.com (mail-pf0-f181.google.com [209.85.192.181]) by lists.linaro.org (Postfix) with ESMTPS id D526D60F4E for ; Wed, 8 Feb 2017 02:37:14 +0000 (UTC) Received: by mail-pf0-f181.google.com with SMTP id y143so37954403pfb.0 for ; Tue, 07 Feb 2017 18:37:14 -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:in-reply-to :references; bh=9FchMrv2VA1aB1TA2wnMKCfNJDOZWgVVHQHXMglTWMg=; b=aHZa5LrdNk47Xslzeb+jbofOX2ga5/zOiulSXLfLt39r0Lr5skBnO/yTPJ3qeGBYoD 1+MzpgKRZyHAvIT/374+sfLcvA6Dq1rCAMc0O8B1MGPXBXPlffSZWIi1FP5KKtCadV// V96x9Kp1zMbnrT3mtMV5TP4R+gy/HEKKLhDzJS8BEymeQ0IQ4Z8/87yYTeLoqOxHrBTC 3dhJM+9mi893U7vPNOznOruADDGnOie7f7XklC3TNOKla2OYeUOyp55zwtXSieG7aTZk LTR3bVVSPE+UGXX68NXpx9XlRXLdu4CI27OgtlXH/eA7vv9ERbIP6MPDusbU3/jeTDcc naJQ== X-Gm-Message-State: AIkVDXIoEOMhvl+Hi2ocpkjBdYbS5UWV5SbnvTQKxCzPmUy/ociiVLEtUx5HKv6Ou0gn38l5NJo= X-Received: by 10.99.152.10 with SMTP id q10mr23936597pgd.192.1486521434114; Tue, 07 Feb 2017 18:37:14 -0800 (PST) Received: from ubuntu.heyii.co (ubuntu.heyii.co. [45.32.66.203]) by smtp.googlemail.com with ESMTPSA id i82sm14714084pfk.52.2017.02.07.18.37.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Feb 2017 18:37:13 -0800 (PST) From: Kevin Wang To: lng-odp@lists.linaro.org Date: Wed, 8 Feb 2017 02:37:01 +0000 Message-Id: <1486521424-11172-2-git-send-email-kevin.wang@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1486521424-11172-1-git-send-email-kevin.wang@linaro.org> References: <1486521424-11172-1-git-send-email-kevin.wang@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv4 1/4] api: timer: add odp_timer_capability() api 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" Currently, user needs to decide the timer resolution before creating a timer pool. But sometimes it will cause timer overrun as the system can't support such high resolution. So a new API is required to expose the timer capability to the user. Signed-off-by: Kevin Wang --- include/odp/api/spec/timer.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) -- 1.9.1 diff --git a/include/odp/api/spec/timer.h b/include/odp/api/spec/timer.h index 75f9db9..e8d85b7 100644 --- a/include/odp/api/spec/timer.h +++ b/include/odp/api/spec/timer.h @@ -108,6 +108,27 @@ typedef struct { } odp_timer_pool_param_t; /** + * Timer capability + */ +typedef struct { + uint64_t res_ns; /**< Timeout resolution in nanoseconds */ +} odp_timer_capability_t; + +/** + * Query Timer interface capabilities + * + * Outputs Timer interface capabilities on success. + * + * @param clk_src Clock source for timers + * @param[out] capa Pointer to capability structure for output + * + * @retval 0 on success + * @retval <0 on failure + */ +int odp_timer_capability(odp_timer_clk_src_t clk_src, + odp_timer_capability_t *capa); + +/** * Create a timer pool * * The use of pool name is optional. Unique names are not required. From patchwork Wed Feb 8 02:37:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wang X-Patchwork-Id: 93599 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2485102qgi; Tue, 7 Feb 2017 18:38:43 -0800 (PST) X-Received: by 10.55.7.2 with SMTP id 2mr20688488qkh.228.1486521523312; Tue, 07 Feb 2017 18:38:43 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id w58si4491353qtc.245.2017.02.07.18.38.42; Tue, 07 Feb 2017 18:38:43 -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 97C3662FE1; Wed, 8 Feb 2017 02:38:42 +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 CD80360F53; Wed, 8 Feb 2017 02:38:14 +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 D839962DE5; Wed, 8 Feb 2017 02:38:07 +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 80D3862FCE for ; Wed, 8 Feb 2017 02:37:16 +0000 (UTC) Received: by mail-pf0-f177.google.com with SMTP id f144so37945494pfa.2 for ; Tue, 07 Feb 2017 18:37:16 -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:in-reply-to :references; bh=kQ3GL/jt6j92+1oBGJbkT2fQiU7oXKSszOgnHsewsBo=; b=tUl8WYsD21pe+SRKnvFQWbNDIODnhAVQN1ajnR0sazv5cxLbRy5S2SgKGCukWRppZ0 FW7fdhoU4FRw1L9M16xvF3BE4O54sbe/AWbunoLA7OgHRBivfmF/mPzoZ0a2qNolUPJM YL4G7W+pq+dYvf5rseMtHd3yzLBFyjhfqYaJNdja4qNK9ypAO5jD4qANbBv3h3DLc0F0 2CS2uEEvShGyeM3/DtkejMBBr8M+ofHj3C+rohaQt/pjiP0e8oa3N7/iCN+L9AQrn93+ 4w3TvBfM90YkcxVjch6VP+Qpayk3drgDGOBi/yH10G5e/O3Sj6Rbro32EWJfYrhWFYfp 2BNQ== X-Gm-Message-State: AIkVDXIaGLx2IduEB+FqvPgNq6JiCB2XOD5iqaR35aHj5ewT+Z5P1zZ9SiihFrcmC/bFcaRY2so= X-Received: by 10.84.141.1 with SMTP id 1mr30767879plu.33.1486521435653; Tue, 07 Feb 2017 18:37:15 -0800 (PST) Received: from ubuntu.heyii.co (ubuntu.heyii.co. [45.32.66.203]) by smtp.googlemail.com with ESMTPSA id i82sm14714084pfk.52.2017.02.07.18.37.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Feb 2017 18:37:15 -0800 (PST) From: Kevin Wang To: lng-odp@lists.linaro.org Date: Wed, 8 Feb 2017 02:37:02 +0000 Message-Id: <1486521424-11172-3-git-send-email-kevin.wang@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1486521424-11172-1-git-send-email-kevin.wang@linaro.org> References: <1486521424-11172-1-git-send-email-kevin.wang@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv4 2/4] linux-generic: timer: implement odp_timer_capability() 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" Implement a new internal function timer_res_init() to detect the max timer resolution without overrun at the ODP init stage. It will check timer resolution from 1ms to 100us, 10us...1ns until the timer is overrun. Signed-off-by: Kevin Wang --- platform/linux-generic/odp_timer.c | 95 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) -- 1.9.1 diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index 53fec08..9b884ea 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -70,6 +70,9 @@ static _odp_atomic_flag_t locks[NUM_LOCKS]; /* Multiple locks per cache line! */ #define IDX2LOCK(idx) (&locks[(idx) % NUM_LOCKS]) #endif +/* Timer resolution in nanoseconds */ +static uint64_t timer_res; + /****************************************************************************** * Translation between timeout buffer and timeout header *****************************************************************************/ @@ -188,6 +191,7 @@ typedef struct odp_timer_pool_s { #define MAX_TIMER_POOLS 255 /* Leave one for ODP_TIMER_INVALID */ #define INDEX_BITS 24 +#define TIMER_RES_TEST_LOOP_COUNT 10 static odp_atomic_u32_t num_timer_pools; static odp_timer_pool *timer_pool[MAX_TIMER_POOLS]; @@ -738,6 +742,81 @@ static void *timer_thread(void *arg) return NULL; } +/* Get the max timer resolution without overrun and fill in timer_res variable. + * + * Set timer's interval with candidate resolutions to get the max resolution + * that the timer would not be overrun. + * The candidate resolution value is from 1ms to 100us, 10us...1ns etc. + */ +static int timer_res_init(void) +{ + struct sigevent sigev; + timer_t timerid; + uint64_t res, sec, nsec; + struct itimerspec ispec; + sigset_t sigset; + siginfo_t si; + int loop_cnt; + struct timespec tmo; + + sigev.sigev_notify = SIGEV_THREAD_ID; + sigev._sigev_un._tid = (pid_t)syscall(SYS_gettid); + sigev.sigev_signo = SIGUSR1; + + /* Create timer */ + if (timer_create(CLOCK_MONOTONIC, &sigev, &timerid)) + ODP_ABORT("timer_create() returned error %s\n", + strerror(errno)); + + /* Timer resolution start from 1ms */ + res = ODP_TIME_MSEC_IN_NS; + /* Set initial value of timer_res */ + timer_res = res; + sigemptyset(&sigset); + /* Add SIGUSR1 to sigset */ + sigaddset(&sigset, SIGUSR1); + sigprocmask(SIG_BLOCK, &sigset, NULL); + + while (res > 0) { + /* Loop for 10 times to test the result */ + loop_cnt = TIMER_RES_TEST_LOOP_COUNT; + sec = res / ODP_TIME_SEC_IN_NS; + nsec = res - sec * ODP_TIME_SEC_IN_NS; + + memset(&ispec, 0, sizeof(ispec)); + ispec.it_interval.tv_sec = (time_t)sec; + ispec.it_interval.tv_nsec = (long)nsec; + ispec.it_value.tv_sec = (time_t)sec; + ispec.it_value.tv_nsec = (long)nsec; + + if (timer_settime(timerid, 0, &ispec, NULL)) + ODP_ABORT("timer_settime() returned error %s\n", + strerror(errno)); + /* Set signal wait timeout to 10*res */ + tmo.tv_sec = 0; + tmo.tv_nsec = res * 10; + while (loop_cnt--) { + if (sigtimedwait(&sigset, &si, &tmo) > 0) { + if (timer_getoverrun(timerid)) + /* overrun at this resolution */ + /* goto the end */ + goto timer_res_init_done; + } + } + /* Set timer_res */ + timer_res = res; + /* Test the next timer resolution candidate */ + res /= 10; + } +timer_res_init_done: + if (timer_delete(timerid) != 0) + ODP_ABORT("timer_delete() returned error %s\n", + strerror(errno)); + sigemptyset(&sigset); + sigprocmask(SIG_BLOCK, &sigset, NULL); + return 0; +} + static void itimer_init(odp_timer_pool *tp) { struct sigevent sigev; @@ -795,6 +874,20 @@ static void itimer_fini(odp_timer_pool *tp) * Some parameter checks and error messages * No modificatios of internal state *****************************************************************************/ +int odp_timer_capability(odp_timer_clk_src_t clk_src, + odp_timer_capability_t *capa) +{ + int ret = 0; + + if (clk_src == ODP_CLOCK_CPU) { + capa->res_ns = timer_res; + } else { + ODP_ERR("ODP timer system doesn't support external clock source currently\n"); + ret = -1; + } + return ret; +} + odp_timer_pool_t odp_timer_pool_create(const char *name, const odp_timer_pool_param_t *param) @@ -1003,6 +1096,8 @@ int odp_timer_init_global(void) #endif odp_atomic_init_u32(&num_timer_pools, 0); + timer_res_init(); + block_sigalarm(); return 0; From patchwork Wed Feb 8 02:37:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wang X-Patchwork-Id: 93600 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2485257qgi; Tue, 7 Feb 2017 18:39:19 -0800 (PST) X-Received: by 10.107.195.143 with SMTP id t137mr13952930iof.46.1486521559632; Tue, 07 Feb 2017 18:39:19 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b82si462274itb.118.2017.02.07.18.39.19; Tue, 07 Feb 2017 18:39:19 -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 18CD162DE5; Wed, 8 Feb 2017 02:39:19 +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 2CDCF62FDB; Wed, 8 Feb 2017 02:38:21 +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 E1F2762DFC; Wed, 8 Feb 2017 02:38:09 +0000 (UTC) Received: from mail-pg0-f43.google.com (mail-pg0-f43.google.com [74.125.83.43]) by lists.linaro.org (Postfix) with ESMTPS id DF92860F53 for ; Wed, 8 Feb 2017 02:37:17 +0000 (UTC) Received: by mail-pg0-f43.google.com with SMTP id 204so44113388pge.0 for ; Tue, 07 Feb 2017 18:37:17 -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:in-reply-to :references; bh=pjgmW1kRpbevIqyuHnyqW4ltkB3seB63tfpTAHbZ/1w=; b=f5z9pahvoCOAogzKTbG5++jahgOgVObEzWz0dYY2fHbjZ5VQFIBsGHgGnK2yACyYDI In0NwJl1BplaRXAyWTU8b6CIAFksV90WP6AUD5uVzpW6oRotOrp0dQCtnYabhNLRstq6 VqT8cOihKXhm9taS3I7WioQu1L584tkY46scoR34HUn4JPutxImPFOZRLLSJzXsKYlqG qVjJ/TyVULyNMq37WWPv5AoERJix3N4uvJXtbB13D/aZbGZu/BRbweHW3hz5wGc2k5WN 1ltaJIoKe2JYG3rUlnj/ZYnjZoc/JGBTYSnY51YYsbKUCrfeS2EyG/1yPUnfP4BGYCYc sNog== X-Gm-Message-State: AIkVDXJIVH0Dy4cNuaKaTRZZXSyi9IC5wMM24swF6m39YoO8lkWT62bSxm5stXTLMjY6VyE8zts= X-Received: by 10.99.155.18 with SMTP id r18mr23726933pgd.193.1486521437132; Tue, 07 Feb 2017 18:37:17 -0800 (PST) Received: from ubuntu.heyii.co (ubuntu.heyii.co. [45.32.66.203]) by smtp.googlemail.com with ESMTPSA id i82sm14714084pfk.52.2017.02.07.18.37.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Feb 2017 18:37:16 -0800 (PST) From: Kevin Wang To: lng-odp@lists.linaro.org Date: Wed, 8 Feb 2017 02:37:03 +0000 Message-Id: <1486521424-11172-4-git-send-email-kevin.wang@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1486521424-11172-1-git-send-email-kevin.wang@linaro.org> References: <1486521424-11172-1-git-send-email-kevin.wang@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv4 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 | 7 ++++++- test/common_plat/validation/api/timer/timer.c | 28 ++++++++++++++++++--------- 4 files changed, 40 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..0ee7e14 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,11 @@ 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)); From patchwork Wed Feb 8 02:37:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wang X-Patchwork-Id: 93601 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2485410qgi; Tue, 7 Feb 2017 18:39:55 -0800 (PST) X-Received: by 10.107.192.70 with SMTP id q67mr7715865iof.110.1486521595507; Tue, 07 Feb 2017 18:39:55 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id x67si433826itg.20.2017.02.07.18.39.55; Tue, 07 Feb 2017 18:39:55 -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 06A5F62FB6; Wed, 8 Feb 2017 02:39:55 +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_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 93B0F62FEC; Wed, 8 Feb 2017 02:38:23 +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 219C562FB6; Wed, 8 Feb 2017 02:38:12 +0000 (UTC) Received: from mail-pg0-f50.google.com (mail-pg0-f50.google.com [74.125.83.50]) by lists.linaro.org (Postfix) with ESMTPS id 6D57062FDB for ; Wed, 8 Feb 2017 02:37:19 +0000 (UTC) Received: by mail-pg0-f50.google.com with SMTP id 194so44119104pgd.2 for ; Tue, 07 Feb 2017 18:37:19 -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:in-reply-to :references; bh=Z+qFojlBnt170IXQyNRAU2DDVN2p+JKGQKTzzLlxW0Y=; b=uGxAsSwBUjNzoTXtT5Jpe6t+iqmMfGRZSrHfq5Ihry9TBNln63w4za8RALrcRBI4vE KX0VzJgyzwIRQOpl6eceLG5fFQEMbmmAaNsr2QBpjFZnjvkjY/cIcX3Rdo5UUwvyvncf ZgWEWRVoDSyzfwbyt6wvtC+zdca6xSAGgPGpCgDg9l+BL2YCgygOqRKqZEv8bflDyH/p G4xHJxjTuwxvnItxYZPZxpmW0VrKUcJge6kjfOKKskJvKmv/13ifXzEo7swm0/BX7pUJ YZoihxR1jSCjLaQxX/vuwR9XBThMTkgIeljtMO/JSNUqcsL/KG/rIZ6Bva4PuEhLWCDy 9cDA== X-Gm-Message-State: AIkVDXIM68mtE3k249XlfgpRFD2GRUSXydX3MNwFI/f1PmQzNKtEln+DpiJyAAvKYsmyNfwMUNU= X-Received: by 10.98.37.132 with SMTP id l126mr23744591pfl.45.1486521438623; Tue, 07 Feb 2017 18:37:18 -0800 (PST) Received: from ubuntu.heyii.co (ubuntu.heyii.co. [45.32.66.203]) by smtp.googlemail.com with ESMTPSA id i82sm14714084pfk.52.2017.02.07.18.37.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Feb 2017 18:37:18 -0800 (PST) From: Kevin Wang To: lng-odp@lists.linaro.org Date: Wed, 8 Feb 2017 02:37:04 +0000 Message-Id: <1486521424-11172-5-git-send-email-kevin.wang@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1486521424-11172-1-git-send-email-kevin.wang@linaro.org> References: <1486521424-11172-1-git-send-email-kevin.wang@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv4 4/4] doc: userguide: add odp_timer_capability() section to user guide 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" Signed-off-by: Kevin Wang --- doc/users-guide/users-guide-timer.adoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/doc/users-guide/users-guide-timer.adoc b/doc/users-guide/users-guide-timer.adoc index 9cd30de..ccca7d4 100644 --- a/doc/users-guide/users-guide-timer.adoc +++ b/doc/users-guide/users-guide-timer.adoc @@ -6,7 +6,8 @@ timing features found in various platforms that support ODP implementations. Timers are drawn from specialized pools called _timer pools_ that have their own abstract type (`odp_timer_pool_t`). Each timer pool is a logically independent time source with its own _resolution_ measured in nanoseconds (ns) -and a maximum number of timers that it can support. Applications can have many +and a maximum number of timers that it can support. The max _resolution_ is +able to be obtained from `odp_timer_capability()`. Applications can have many timers active at the same time and can set them to use either relative or absolute time. Associated with each timer is a queue that is to receive events when this timer expires. This queue is created by a separate