From patchwork Tue Sep 2 12:47:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 36465 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f200.google.com (mail-ie0-f200.google.com [209.85.223.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AC5682032B for ; Tue, 2 Sep 2014 12:46:38 +0000 (UTC) Received: by mail-ie0-f200.google.com with SMTP id at20sf37457595iec.3 for ; Tue, 02 Sep 2014 05:46:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=aqG0Fpx+W5yfzJDElJ24LuFBSxN0WIjXQNEFT3H6teg=; b=JXxPmgWUy2d4a9RMSz6hHxLz7XM5wKJN16W1+bXVZsgFdAHa9EyPlC2RpRzBLAXSaE JfgWlYbmhYiFoSMJkmna2oVMf9x/Sx0FQp7vZ9XIDdz2igM/9wNEkxUwCoVzxLTAbj1r JdZA8sBh1OsXW0/QKhDkumIvUUy36JvI9oYJ+nlucJ8EeaeeLaFXwnmasKdt5aiQdCYi i0u195m0HuoBGA3rsgSOi4KHKUndglM0LeF+DnzQUSszZGH0VVFZTv6MmacAZu6c/qxW PAjGsjat/iRBg2DJCR+SN+YQ67smLz5GcVOh4x+la4XbQLNBD51zM8EU905Pm75nrM/4 Y4rg== X-Gm-Message-State: ALoCoQkDJG3GWKNv7DSm3aYdV+U1X2bLRZBGkDL8fV7Qvyv20TAsrEKfskhuZXC4mL5j30SuNH0p X-Received: by 10.50.136.194 with SMTP id qc2mr15373567igb.7.1409661998217; Tue, 02 Sep 2014 05:46:38 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.23.201 with SMTP id 67ls2403022qgp.45.gmail; Tue, 02 Sep 2014 05:46:38 -0700 (PDT) X-Received: by 10.220.74.195 with SMTP id v3mr30012993vcj.23.1409661998125; Tue, 02 Sep 2014 05:46:38 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id x11si2187883vdg.56.2014.09.02.05.46.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Sep 2014 05:46:38 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id ij19so6785344vcb.26 for ; Tue, 02 Sep 2014 05:46:38 -0700 (PDT) X-Received: by 10.220.97.5 with SMTP id j5mr30196837vcn.16.1409661997962; Tue, 02 Sep 2014 05:46:37 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp521730vcb; Tue, 2 Sep 2014 05:46:35 -0700 (PDT) X-Received: by 10.224.65.196 with SMTP id k4mr56858827qai.56.1409661992550; Tue, 02 Sep 2014 05:46:32 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id i7si5072781qan.28.2014.09.02.05.46.31 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 02 Sep 2014 05:46:32 -0700 (PDT) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XOnTh-0005ND-Vt; Tue, 02 Sep 2014 12:46:30 +0000 Received: from mail-qg0-f48.google.com ([209.85.192.48]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XOnTb-0005N3-WA for lng-odp@lists.linaro.org; Tue, 02 Sep 2014 12:46:24 +0000 Received: by mail-qg0-f48.google.com with SMTP id z107so6407447qgd.21 for ; Tue, 02 Sep 2014 05:46:18 -0700 (PDT) X-Received: by 10.140.49.201 with SMTP id q67mr50977907qga.7.1409661978713; Tue, 02 Sep 2014 05:46:18 -0700 (PDT) Received: from localhost.localdomain (ec2-23-23-178-99.compute-1.amazonaws.com. [23.23.178.99]) by mx.google.com with ESMTPSA id e64sm4806029qgd.37.2014.09.02.05.46.16 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Sep 2014 05:46:17 -0700 (PDT) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Tue, 2 Sep 2014 15:47:23 +0300 Message-Id: <1409662044-23337-1-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.1.0 X-Topics: timers patch Subject: [lng-odp] [PATCH v2 1/2] Use timer resolution X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: 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-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: petri.savolainen@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Use resolution and min/max tmo values from timer create call. Use common nanosec time defines. Signed-off-by: Petri Savolainen --- platform/linux-generic/include/api/odp_time.h | 5 ++ platform/linux-generic/odp_timer.c | 67 ++++++++++++++++++++------- 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/platform/linux-generic/include/api/odp_time.h b/platform/linux-generic/include/api/odp_time.h index 188d1fe..1770223 100644 --- a/platform/linux-generic/include/api/odp_time.h +++ b/platform/linux-generic/include/api/odp_time.h @@ -21,6 +21,11 @@ extern "C" { #include +/* Time in nanoseconds */ +#define ODP_TIME_USEC 1000UL /*< Microsecond in nsec */ +#define ODP_TIME_MSEC 1000000UL /*< Millisecond in nsec */ +#define ODP_TIME_SEC 1000000000UL /*< Second in nsec */ + /** * Current time in CPU cycles diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index 1bf37f9..6e89f5c 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -18,9 +19,14 @@ #include +#define USEC ODP_TIME_USEC +#define MSEC ODP_TIME_MSEC +#define SEC ODP_TIME_SEC + #define NUM_TIMERS 1 #define MAX_TICKS 1024 -#define RESOLUTION_NS 1000000 +#define MAX_RES SEC +#define MIN_RES (100*USEC) typedef struct { @@ -112,13 +118,13 @@ static int find_and_del_tmo(timeout_t **tmo, odp_timer_tmo_t handle) int odp_timer_cancel_tmo(odp_timer_t timer_hdl, odp_timer_tmo_t tmo) { int id; - uint64_t tick_idx; + int tick_idx; timeout_t *cancel_tmo; odp_timeout_hdr_t *tmo_hdr; tick_t *tick; /* get id */ - id = timer_hdl - 1; + id = (int)timer_hdl - 1; tmo_hdr = odp_timeout_hdr((odp_timeout_t) tmo); /* get tmo_buf to cancel */ @@ -179,6 +185,7 @@ static void timer_start(timer_ring_t *timer) { struct sigevent sigev; struct itimerspec ispec; + uint64_t res, sec, nsec; ODP_DBG("\nTimer (%u) starts\n", timer->timer_hdl); @@ -194,10 +201,14 @@ static void timer_start(timer_ring_t *timer) return; } - ispec.it_interval.tv_sec = 0; - ispec.it_interval.tv_nsec = RESOLUTION_NS; - ispec.it_value.tv_sec = 0; - ispec.it_value.tv_nsec = RESOLUTION_NS; + res = timer->resolution_ns; + sec = res / SEC; + nsec = res - sec*SEC; + + 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(timer->timerid, 0, &ispec, NULL)) { ODP_DBG("Timer set failed\n"); @@ -250,19 +261,41 @@ int odp_timer_disarm_all(void) } odp_timer_t odp_timer_create(const char *name, odp_buffer_pool_t pool, - uint64_t resolution, uint64_t min_tmo, - uint64_t max_tmo) + uint64_t resolution_ns, uint64_t min_ns, + uint64_t max_ns) { uint32_t id; timer_ring_t *timer; odp_timer_t timer_hdl; int i; - (void) name; (void) resolution; (void) min_tmo; (void) max_tmo; + uint64_t max_ticks; + (void) name; + + if (resolution_ns < MIN_RES) + resolution_ns = MIN_RES; + + if (resolution_ns > MAX_RES) + resolution_ns = MAX_RES; + + max_ticks = max_ns / resolution_ns; + + if (max_ticks > MAX_TICKS) { + ODP_DBG("Maximum timeout too long: %"PRIu64" ticks\n", + max_ticks); + return ODP_TIMER_INVALID; + } + + if (min_ns < resolution_ns) { + ODP_DBG("Min timeout %"PRIu64" ns < resolution %"PRIu64" ns\n", + min_ns, resolution_ns); + return ODP_TIMER_INVALID; + } odp_spinlock_lock(&odp_timer.lock); if (odp_timer.num_timers >= NUM_TIMERS) { odp_spinlock_unlock(&odp_timer.lock); + ODP_DBG("All timers allocated\n"); return ODP_TIMER_INVALID; } @@ -281,7 +314,7 @@ odp_timer_t odp_timer_create(const char *name, odp_buffer_pool_t pool, timer->timer_hdl = timer_hdl; timer->pool = pool; - timer->resolution_ns = RESOLUTION_NS; + timer->resolution_ns = resolution_ns; timer->max_ticks = MAX_TICKS; for (i = 0; i < MAX_TICKS; i++) { @@ -308,7 +341,7 @@ odp_timer_tmo_t odp_timer_absolute_tmo(odp_timer_t timer_hdl, uint64_t tmo_tick, odp_timeout_hdr_t *tmo_hdr; timer_ring_t *timer; - id = timer_hdl - 1; + id = (int)timer_hdl - 1; timer = &odp_timer.timer[id]; cur_tick = timer->cur_tick; @@ -317,17 +350,17 @@ odp_timer_tmo_t odp_timer_absolute_tmo(odp_timer_t timer_hdl, uint64_t tmo_tick, return ODP_TIMER_TMO_INVALID; } - tick = tmo_tick - cur_tick; - if (tick > MAX_TICKS) { - ODP_DBG("timeout too far\n"); + if ((tmo_tick - cur_tick) > MAX_TICKS) { + ODP_DBG("timeout too far: cur %"PRIu64" tmo %"PRIu64"\n", + cur_tick, tmo_tick); return ODP_TIMER_TMO_INVALID; } - tick = (cur_tick + tick) % MAX_TICKS; + tick = tmo_tick % MAX_TICKS; tmo_buf = odp_buffer_alloc(timer->pool); if (tmo_buf == ODP_BUFFER_INVALID) { - ODP_DBG("alloc failed\n"); + ODP_DBG("tmo buffer alloc failed\n"); return ODP_TIMER_TMO_INVALID; }