From patchwork Thu Jan 15 15:40:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 43210 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f199.google.com (mail-we0-f199.google.com [74.125.82.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1E08F240BA for ; Thu, 15 Jan 2015 15:41:47 +0000 (UTC) Received: by mail-we0-f199.google.com with SMTP id k11sf8297350wes.2 for ; Thu, 15 Jan 2015 07:41:46 -0800 (PST) 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:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=he+d5mY+z0LJh0D61LhjvO+LjNL3wr+IRF/ugIhgCe8=; b=MLX6lwE9IyXZSDqDo0GxMMWDTDVSxSPYfUQa2s98xOxVxshyYtBbM93F2bCKAnV8So depmqlQFQg6QTcDEasegf456WE/00EenDypxXGdm2dqaKftR1PQoliB+TiL1hBkNGeIQ 9NQ5HS6e4PDgs37IbRvYewAAdC4DaHe5n8dxsjX2S6+J/WhiiI0lKpPbHd+xvffZ7oQ2 eC7Rw5F+KjqYU6y0KcG08hLTq319MYy9OlY3z7kdJ+nDoVyRswDJohlToAI7fdPKXS80 GUI25Vl492JlQy94boSxlGFGt1cftMn50dEbg/+tqsHLc+S7XBSjuHkdSJ5AaB+EsTgH hsqQ== X-Gm-Message-State: ALoCoQnEjQk8chjSV2pMNegBkJKWFiodjSHTTPrq3Z4APnNI6/bmKyoCb+0G/HQssxmwXQ23a7no X-Received: by 10.180.105.97 with SMTP id gl1mr4427157wib.7.1421336506415; Thu, 15 Jan 2015 07:41:46 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.203.226 with SMTP id kt2ls258711lac.52.gmail; Thu, 15 Jan 2015 07:41:46 -0800 (PST) X-Received: by 10.152.27.130 with SMTP id t2mr10426437lag.28.1421336506221; Thu, 15 Jan 2015 07:41:46 -0800 (PST) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id jo17si1810958lab.19.2015.01.15.07.41.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 15 Jan 2015 07:41:46 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by mail-lb0-f178.google.com with SMTP id u14so13871362lbd.9 for ; Thu, 15 Jan 2015 07:41:46 -0800 (PST) X-Received: by 10.152.8.11 with SMTP id n11mr10375708laa.38.1421336506135; Thu, 15 Jan 2015 07:41:46 -0800 (PST) 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.112.9.200 with SMTP id c8csp21982lbb; Thu, 15 Jan 2015 07:41:45 -0800 (PST) X-Received: by 10.224.16.131 with SMTP id o3mr17168486qaa.31.1421336504550; Thu, 15 Jan 2015 07:41:44 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id 65si2352270qgx.47.2015.01.15.07.41.43 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 15 Jan 2015 07:41:44 -0800 (PST) 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-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YBmYH-0007Uv-Mj; Thu, 15 Jan 2015 15:41:41 +0000 Received: from mail-qc0-f171.google.com ([209.85.216.171]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YBmY0-0007Nl-Ob for lng-odp@lists.linaro.org; Thu, 15 Jan 2015 15:41:24 +0000 Received: by mail-qc0-f171.google.com with SMTP id b13so8645200qcw.2 for ; Thu, 15 Jan 2015 07:41:19 -0800 (PST) X-Received: by 10.229.114.137 with SMTP id e9mr17282166qcq.0.1421336479593; Thu, 15 Jan 2015 07:41:19 -0800 (PST) Received: from mcpro03.emea.nsn-net.net (ec2-23-23-178-99.compute-1.amazonaws.com. [23.23.178.99]) by mx.google.com with ESMTPSA id g12sm1563340qay.44.2015.01.15.07.41.17 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 15 Jan 2015 07:41:18 -0800 (PST) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Thu, 15 Jan 2015 17:40:17 +0200 Message-Id: <1421336423-19382-10-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1421336423-19382-1-git-send-email-petri.savolainen@linaro.org> References: <1421336423-19382-1-git-send-email-petri.savolainen@linaro.org> X-Topics: timers patch Subject: [lng-odp] [PATCH 09/15] api: timer: Use odp_event_t instead of odp_buffer_t 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.217.178 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 Changed timer API to use odp_event_t instead of odp_buffer_t. Signed-off-by: Petri Savolainen --- example/timer/odp_timer_test.c | 28 ++++++------ platform/linux-generic/include/api/odp_timer.h | 63 ++++++++++---------------- platform/linux-generic/odp_timer.c | 28 ++++-------- 3 files changed, 50 insertions(+), 69 deletions(-) diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c index c4f0c5b..944ef9e 100644 --- a/example/timer/odp_timer_test.c +++ b/example/timer/odp_timer_test.c @@ -62,8 +62,8 @@ static const char *timerset2str(odp_timer_set_t val) return "too early"; case ODP_TIMER_TOOLATE: return "too late"; - case ODP_TIMER_NOBUF: - return "no buffer"; + case ODP_TIMER_NOEVENT: + return "no event"; default: return "?"; } @@ -72,7 +72,7 @@ static const char *timerset2str(odp_timer_set_t val) /** @private Helper struct for timers */ struct test_timer { odp_timer_t tim; - odp_buffer_t buf; + odp_event_t ev; }; /** @private Array of all timer helper structs */ @@ -86,6 +86,7 @@ static void test_abs_timeouts(int thr, test_args_t *args) odp_queue_t queue; uint64_t tick; struct test_timer *ttp; + odp_buffer_t buf; EXAMPLE_DBG(" [%i] test_timeouts\n", thr); @@ -106,11 +107,12 @@ static void test_abs_timeouts(int thr, test_args_t *args) EXAMPLE_ERR("Failed to allocate timer\n"); return; } - ttp->buf = odp_buffer_alloc(pool); - if (ttp->buf == ODP_BUFFER_INVALID) { + buf = odp_buffer_alloc(pool); + if (buf == ODP_BUFFER_INVALID) { EXAMPLE_ERR("Failed to allocate buffer\n"); return; } + ttp->ev = odp_buffer_to_event(buf); tick = odp_timer_current_tick(tp); while ((int)odp_atomic_load_u32(&remain) > 0) { @@ -118,7 +120,7 @@ static void test_abs_timeouts(int thr, test_args_t *args) odp_timer_set_t rc; tick += period; - rc = odp_timer_set_abs(ttp->tim, tick, &ttp->buf); + rc = odp_timer_set_abs(ttp->tim, tick, &ttp->ev); if (odp_unlikely(rc != ODP_TIMER_SUCCESS)) { /* Too early or too late timeout requested */ EXAMPLE_ABORT("odp_timer_set_abs() failed: %s\n", @@ -134,14 +136,14 @@ static void test_abs_timeouts(int thr, test_args_t *args) if (ev == ODP_EVENT_INVALID) continue; /* Re-check the remain counter */ if (odp_event_type(ev) != ODP_EVENT_TIMEOUT) { - /* Not a default timeout buffer */ + /* Not a default timeout event */ EXAMPLE_ABORT("Unexpected event type (%u) received\n", odp_event_type(ev)); } odp_timeout_t tmo = odp_timeout_from_event(ev); tick = odp_timeout_tick(tmo); ttp = odp_timeout_user_ptr(tmo); - ttp->buf = odp_buffer_from_event(ev); + ttp->ev = ev; if (!odp_timeout_fresh(tmo)) { /* Not the expected expiration tick, timer has * been reset or cancelled or freed */ @@ -154,12 +156,12 @@ static void test_abs_timeouts(int thr, test_args_t *args) } /* Cancel and free last timer used */ - (void)odp_timer_cancel(ttp->tim, &ttp->buf); - if (ttp->buf != ODP_BUFFER_INVALID) - odp_buffer_free(ttp->buf); + (void)odp_timer_cancel(ttp->tim, &ttp->ev); + if (ttp->ev != ODP_EVENT_INVALID) + odp_buffer_free(odp_buffer_from_event(ttp->ev)); else - EXAMPLE_ERR("Lost timeout buffer at timer cancel\n"); - /* Since we have cancelled the timer, there is no timeout buffer to + EXAMPLE_ERR("Lost timeout event at timer cancel\n"); + /* Since we have cancelled the timer, there is no timeout event to * return from odp_timer_free() */ (void)odp_timer_free(ttp->tim); } diff --git a/platform/linux-generic/include/api/odp_timer.h b/platform/linux-generic/include/api/odp_timer.h index cb17b7b..075263a 100644 --- a/platform/linux-generic/include/api/odp_timer.h +++ b/platform/linux-generic/include/api/odp_timer.h @@ -20,7 +20,6 @@ extern "C" { #include #include -#include #include #include @@ -86,10 +85,10 @@ typedef enum { * timer pool. */ ODP_TIMER_TOOLATE = -2, /** - * Timer set operation failed because no timeout buffer specified and no - * timeout buffer present in the timer (timer inactive/expired). + * Timer set operation failed because no timeout event specified and no + * timeout event present in the timer (timer inactive/expired). */ - ODP_TIMER_NOBUF = -3 + ODP_TIMER_NOEVENT = -3 } odp_timer_set_t; /** Maximum timer pool name length in chars (including null char) */ @@ -214,29 +213,29 @@ odp_timer_t odp_timer_alloc(odp_timer_pool_t tpid, * Free a timer * * Free (destroy) a timer, reclaiming associated resources. - * The timeout buffer for an active timer will be returned. - * The timeout buffer for an expired timer will not be returned. It is the + * The timeout event for an active timer will be returned. + * The timeout event for an expired timer will not be returned. It is the * responsibility of the application to handle this timeout when it is received. * * @param tim Timer handle - * @return Buffer handle of timeout buffer or ODP_BUFFER_INVALID + * @return Event handle of timeout event or ODP_EVENT_INVALID */ -odp_buffer_t odp_timer_free(odp_timer_t tim); +odp_event_t odp_timer_free(odp_timer_t tim); /** - * Set a timer (absolute time) with a user-provided timeout buffer + * Set a timer (absolute time) with a user-provided timeout event * * Set (arm) the timer to expire at specific time. The timeout - * buffer will be enqueued when the timer expires. + * event will be enqueued when the timer expires. * * Note: any invalid parameters will be treated as programming errors and will * cause the application to abort. * * @param tim Timer * @param abs_tck Expiration time in absolute timer ticks - * @param[in,out] tmo_buf Reference to a buffer variable that points to - * timeout buffer or NULL to reuse the existing timeout buffer. Any existing - * timeout buffer that is replaced by a successful set operation will be + * @param[in,out] tmo_ev Reference to an event variable that points to + * timeout event or NULL to reuse the existing timeout event. Any existing + * timeout event that is replaced by a successful set operation will be * returned here. * * @retval ODP_TIMER_SUCCESS Operation succeeded @@ -244,15 +243,15 @@ odp_buffer_t odp_timer_free(odp_timer_t tim); * early * @retval ODP_TIMER_TOOLATE Operation failed because expiration tick too * late - * @retval ODP_TIMER_NOBUF Operation failed because timeout buffer not + * @retval ODP_TIMER_NOEVENT Operation failed because timeout event not * specified in odp_timer_set call and not present in timer */ int odp_timer_set_abs(odp_timer_t tim, uint64_t abs_tck, - odp_buffer_t *tmo_buf); + odp_event_t *tmo_ev); /** - * Set a timer with a relative expiration time and user-provided buffer. + * Set a timer with a relative expiration time and user-provided event. * * Set (arm) the timer to expire at a relative future time. * @@ -262,9 +261,9 @@ int odp_timer_set_abs(odp_timer_t tim, * @param tim Timer * @param rel_tck Expiration time in timer ticks relative to current time of * the timer pool the timer belongs to - * @param[in,out] tmo_buf Reference to a buffer variable that points to - * timeout buffer or NULL to reuse the existing timeout buffer. Any existing - * timeout buffer that is replaced by a successful set operation will be + * @param[in,out] tmo_ev Reference to an event variable that points to + * timeout event or NULL to reuse the existing timeout event. Any existing + * timeout event that is replaced by a successful set operation will be * returned here. * * @retval ODP_TIMER_SUCCESS Operation succeeded @@ -272,18 +271,18 @@ int odp_timer_set_abs(odp_timer_t tim, * early * @retval ODP_TIMER_TOOLATE Operation failed because expiration tick too * late - * @retval ODP_TIMER_NOBUF Operation failed because timeout buffer not + * @retval ODP_TIMER_NOEVENT Operation failed because timeout event not * specified in call and not present in timer */ int odp_timer_set_rel(odp_timer_t tim, uint64_t rel_tck, - odp_buffer_t *tmo_buf); + odp_event_t *tmo_ev); /** * Cancel a timer * * Cancel a timer, preventing future expiration and delivery. Return any - * present timeout buffer. + * present timeout event. * * A timer that has already expired may be impossible to cancel and the timeout * will instead be delivered to the destination queue. @@ -292,23 +291,11 @@ int odp_timer_set_rel(odp_timer_t tim, * cause the application to abort. * * @param tim Timer - * @param[out] tmo_buf Pointer to a buffer variable - * @retval 0 Success, active timer cancelled, timeout returned in '*tmo_buf' + * @param[out] tmo_ev Pointer to an event variable + * @retval 0 Success, active timer cancelled, timeout returned in '*tmo_ev' * @retval -1 Failure, timer already expired (or inactive) */ -int odp_timer_cancel(odp_timer_t tim, odp_buffer_t *tmo_buf); - -/** - * Return timeout handle that is associated with timeout buffer - * - * Note: any invalid parameters will cause undefined behavior and may cause - * the application to abort or crash. - * - * @param buf A buffer of type ODP_BUFFER_TYPE_TIMEOUT - * - * @return timeout handle - */ -odp_timeout_t odp_timeout_from_buf(odp_buffer_t buf); +int odp_timer_cancel(odp_timer_t tim, odp_event_t *tmo_ev); /** * Return timeout handle that is associated with timeout event @@ -316,7 +303,7 @@ odp_timeout_t odp_timeout_from_buf(odp_buffer_t buf); * Note: any invalid parameters will cause undefined behavior and may cause * the application to abort or crash. * - * @param buf An event of type ODP_EVENT_TIMEOUT + * @param ev An event of type ODP_EVENT_TIMEOUT * * @return timeout handle */ diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index dd4cc72..7469278 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -739,17 +739,17 @@ odp_timer_t odp_timer_alloc(odp_timer_pool_t tpid, return ODP_TIMER_INVALID; } -odp_buffer_t odp_timer_free(odp_timer_t hdl) +odp_event_t odp_timer_free(odp_timer_t hdl) { odp_timer_pool *tp = handle_to_tp(hdl); uint32_t idx = handle_to_idx(hdl, tp); odp_buffer_t old_buf = timer_free(tp, idx); - return old_buf; + return odp_buffer_to_event(old_buf); } int odp_timer_set_abs(odp_timer_t hdl, uint64_t abs_tck, - odp_buffer_t *tmo_buf) + odp_event_t *tmo_ev) { odp_timer_pool *tp = handle_to_tp(hdl); uint32_t idx = handle_to_idx(hdl, tp); @@ -758,15 +758,15 @@ int odp_timer_set_abs(odp_timer_t hdl, return ODP_TIMER_TOOEARLY; if (odp_unlikely(abs_tck > cur_tick + tp->max_rel_tck)) return ODP_TIMER_TOOLATE; - if (timer_reset(idx, abs_tck, tmo_buf, tp)) + if (timer_reset(idx, abs_tck, (odp_buffer_t *)tmo_ev, tp)) return ODP_TIMER_SUCCESS; else - return ODP_TIMER_NOBUF; + return ODP_TIMER_NOEVENT; } int odp_timer_set_rel(odp_timer_t hdl, uint64_t rel_tck, - odp_buffer_t *tmo_buf) + odp_event_t *tmo_ev) { odp_timer_pool *tp = handle_to_tp(hdl); uint32_t idx = handle_to_idx(hdl, tp); @@ -775,34 +775,26 @@ int odp_timer_set_rel(odp_timer_t hdl, return ODP_TIMER_TOOEARLY; if (odp_unlikely(rel_tck > tp->max_rel_tck)) return ODP_TIMER_TOOLATE; - if (timer_reset(idx, abs_tck, tmo_buf, tp)) + if (timer_reset(idx, abs_tck, (odp_buffer_t *)tmo_ev, tp)) return ODP_TIMER_SUCCESS; else - return ODP_TIMER_NOBUF; + return ODP_TIMER_NOEVENT; } -int odp_timer_cancel(odp_timer_t hdl, odp_buffer_t *tmo_buf) +int odp_timer_cancel(odp_timer_t hdl, odp_event_t *tmo_ev) { odp_timer_pool *tp = handle_to_tp(hdl); uint32_t idx = handle_to_idx(hdl, tp); /* Set the expiration tick of the timer to TMO_INACTIVE */ odp_buffer_t old_buf = timer_cancel(tp, idx, TMO_INACTIVE); if (old_buf != ODP_BUFFER_INVALID) { - *tmo_buf = old_buf; + *tmo_ev = odp_buffer_to_event(old_buf); return 0; /* Active timer cancelled, timeout returned */ } else { return -1; /* Timer already expired, no timeout returned */ } } -odp_timeout_t odp_timeout_from_buf(odp_buffer_t buf) -{ - /* This check not mandated by the API specification */ - if (_odp_buffer_type(buf) != ODP_BUFFER_TYPE_TIMEOUT) - ODP_ABORT("Buffer not a timeout"); - return (odp_timeout_t)timeout_hdr_from_buf(buf); -} - odp_timeout_t odp_timeout_from_event(odp_event_t ev) { /* This check not mandated by the API specification */