From patchwork Thu Aug 28 14:15:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 36210 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CCE4420565 for ; Thu, 28 Aug 2014 14:14:44 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id lf10sf19315844pab.5 for ; Thu, 28 Aug 2014 07:14:40 -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=tz/wmHb5Q7n4YBJHqu2QHlIwyBFvDvDBol8qrzGMH6Y=; b=EMFrMonNwHxCKMlaK1lEBwY9Ggs74E9UFwQzuNEid49Jn5b82TNfJw1SJKxPvobYOD IriMcv96oProtqhQnaf2iJkzd+sk81NaTerIek933KaRxM/uDqiZSCO7misZw2KA/f65 MdmR7TtW5wtFaoJMUTdrPTKpkWKebFqJaqv0XHKV4Me7St7Zixs+wIysdQIi+Y4PBHnN 8MWO3GL0yFuOuyeAr+6HtNJB7JYUZ5iGcIWKo7IH3cxlz6bb9rPNT97Buc1KshuFutBe +NPiLSa8OMfzPQkk1HzZdgBa91liWJjt2NkxcVJFHGBFWsszMsmGoRRBjCRJgc9jNFkK gizQ== X-Gm-Message-State: ALoCoQkBLGJDtOsZhnr0/CnWNJrl2BYxzj3SzZYYoQD0MvR1eZpvLbzOw7FFp0v3H/R4oLbq3tG8 X-Received: by 10.66.245.197 with SMTP id xq5mr2241954pac.42.1409235279852; Thu, 28 Aug 2014 07:14:39 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.104.18 with SMTP id z18ls665191qge.0.gmail; Thu, 28 Aug 2014 07:14:39 -0700 (PDT) X-Received: by 10.220.194.130 with SMTP id dy2mr1075174vcb.47.1409235279673; Thu, 28 Aug 2014 07:14:39 -0700 (PDT) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id be11si3566352vdd.60.2014.08.28.07.14.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 28 Aug 2014 07:14:39 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id ik5so863691vcb.35 for ; Thu, 28 Aug 2014 07:14:39 -0700 (PDT) X-Received: by 10.52.120.51 with SMTP id kz19mr714806vdb.95.1409235279418; Thu, 28 Aug 2014 07:14:39 -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 uj3csp243442vcb; Thu, 28 Aug 2014 07:14:39 -0700 (PDT) X-Received: by 10.229.62.129 with SMTP id x1mr7124734qch.16.1409235278083; Thu, 28 Aug 2014 07:14:38 -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 y107si5688107qgy.116.2014.08.28.07.14.37 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 28 Aug 2014 07:14:38 -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 1XN0TD-0003rB-Hg; Thu, 28 Aug 2014 14:14:35 +0000 Received: from mail-qc0-f177.google.com ([209.85.216.177]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XN0T7-0003r6-Ud for lng-odp@lists.linaro.org; Thu, 28 Aug 2014 14:14:29 +0000 Received: by mail-qc0-f177.google.com with SMTP id i8so816717qcq.36 for ; Thu, 28 Aug 2014 07:14:24 -0700 (PDT) X-Received: by 10.140.41.101 with SMTP id y92mr6343158qgy.69.1409235264617; Thu, 28 Aug 2014 07:14:24 -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 p78sm5721137qgd.11.2014.08.28.07.14.22 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 28 Aug 2014 07:14:23 -0700 (PDT) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Thu, 28 Aug 2014 17:15:12 +0300 Message-Id: <1409235313-20445-1-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.1.0 X-Topics: timers patch Subject: [lng-odp] [PATCH 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.176 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. Signed-off-by: Petri Savolainen --- platform/linux-generic/odp_timer.c | 68 ++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index 1bf37f9..07b1029 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -18,9 +18,16 @@ #include + +/* Nanoseconds */ +#define USEC 1000UL +#define MSEC 1000000UL +#define SEC 1000000000UL + #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 +119,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 +186,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 +202,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 +262,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 +315,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 +342,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 +351,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; }