From patchwork Thu Sep 4 09:55:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 36686 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f198.google.com (mail-pd0-f198.google.com [209.85.192.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 92D9820523 for ; Thu, 4 Sep 2014 09:56:18 +0000 (UTC) Received: by mail-pd0-f198.google.com with SMTP id fp1sf57428012pdb.1 for ; Thu, 04 Sep 2014 02:56:14 -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=PLhK5EldbrhM5DzvCfKTdn3cHqNms31Ewfwf4R9e/qQ=; b=JdFDMZxCEDYRsAoWpmiJ1ah13MakKEHS+uJgg3h+j+dF82A4zeGDv/LLZHa6UINVWJ 0a38KwNRDOFwRM3InsGcVgGqkE9X7so1QPQzJTbn4jbSfiupby7V523TEyeywPPnMw1d nGYEcWGDDIIrwY7AcH4KPlWBwqYtHEJ7UeNd4+wEGywgA4e6YSvW05sH5KydEUVpQp70 Cc7SiPw0t1LG12ZUDATlp5CN1YrS0tBxr8yhkOr7hgKO2lbKIgcAqdi33LAi5fRnNFri ebrM8hNzVNJSDQFt4V+Ul3yALr34uiBVcP0qegser28ylpsKe8Ie6QymtU0ierQW3NwK zpJA== X-Gm-Message-State: ALoCoQk21RrE0zXEZBICsDLFYGyt4eY8PNEp4+ipRZQcTZxXaJUHVQY+fNkasUiR/88zwNGDko4O X-Received: by 10.66.145.69 with SMTP id ss5mr1943263pab.20.1409824470964; Thu, 04 Sep 2014 02:54:30 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.101.6 with SMTP id t6ls182202qge.32.gmail; Thu, 04 Sep 2014 02:54:30 -0700 (PDT) X-Received: by 10.220.247.3 with SMTP id ma3mr2469334vcb.29.1409824470829; Thu, 04 Sep 2014 02:54:30 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id wn1si4061252vcb.98.2014.09.04.02.54.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 04 Sep 2014 02:54:30 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id id10so10256494vcb.2 for ; Thu, 04 Sep 2014 02:54:30 -0700 (PDT) X-Received: by 10.52.190.71 with SMTP id go7mr2122976vdc.28.1409824470682; Thu, 04 Sep 2014 02:54:30 -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 uj3csp807899vcb; Thu, 4 Sep 2014 02:54:30 -0700 (PDT) X-Received: by 10.140.47.80 with SMTP id l74mr5164738qga.24.1409824469954; Thu, 04 Sep 2014 02:54:29 -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 k47si13876531qgd.59.2014.09.04.02.54.29 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 04 Sep 2014 02:54:29 -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 1XPTkK-0006EF-39; Thu, 04 Sep 2014 09:54:28 +0000 Received: from mail-qc0-f178.google.com ([209.85.216.178]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XPTkE-0006DP-QC for lng-odp@lists.linaro.org; Thu, 04 Sep 2014 09:54:22 +0000 Received: by mail-qc0-f178.google.com with SMTP id x13so10316137qcv.9 for ; Thu, 04 Sep 2014 02:54:17 -0700 (PDT) X-Received: by 10.224.115.134 with SMTP id i6mr4997557qaq.71.1409824457562; Thu, 04 Sep 2014 02:54:17 -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 o6sm18938555qag.40.2014.09.04.02.54.15 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 04 Sep 2014 02:54:16 -0700 (PDT) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Thu, 4 Sep 2014 12:55:10 +0300 Message-Id: <1409824511-11368-1-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.1.0 X-Topics: timers patch Subject: [lng-odp] [PATCH v4 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.171 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 | 63 +++++++++++++++++++-------- 2 files changed, 51 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..ecddb54 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..313c713 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 @@ -20,7 +21,8 @@ #define NUM_TIMERS 1 #define MAX_TICKS 1024 -#define RESOLUTION_NS 1000000 +#define MAX_RES ODP_TIME_SEC +#define MIN_RES (100*ODP_TIME_USEC) typedef struct { @@ -112,13 +114,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 +181,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 +197,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 / ODP_TIME_SEC; + nsec = res - sec*ODP_TIME_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 +257,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 +310,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 +337,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 +346,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; }