From patchwork Tue Jan 20 11:18:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 43360 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f71.google.com (mail-ee0-f71.google.com [74.125.83.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F15F32034D for ; Tue, 20 Jan 2015 11:20:37 +0000 (UTC) Received: by mail-ee0-f71.google.com with SMTP id d49sf3295542eek.2 for ; Tue, 20 Jan 2015 03:20:37 -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=YtwcriwbIi+bIMTzGkXYIssktRlw8rNSv0JWjwzahvI=; b=isixamzPbOewq3bDa+5Hbf4NgoP8JSbYde6g0q2e4z4Gemo//HnK2b+aLlB6cHMD3v Z+6I8ss+LtQlo5bdEqrV4NTGM/QKx3lsmr3U/woKT5uTI3Ixkh95UJb0fl0PILM8Y68K AkSudXYUkM0G5FuFkfFjY9HBIgOX8WjE7LXHTcLTIXi5O7Df3W1aNp2x0ZnJvfnPbxJn fhXHebbqgcc+3wh4sxs1OgPYk5PQmsPO3yKtUSwKy91ysw9HykL1C8fxPWJ9cRq0oJ1D vneCIXfNgba8gKb5N+CadaEoyx93sG9Q1nmlshrU/wOyHfAcU5BY0Hw3A3kikwnsHiGn sBgw== X-Gm-Message-State: ALoCoQldVdOd+lcQHAxqufkVzRol/UEESyzZvnjgK8zP71eAFgbou+TlN0nCoDsbF7u39JzIyRHO X-Received: by 10.152.182.204 with SMTP id eg12mr11932lac.10.1421752837191; Tue, 20 Jan 2015 03:20:37 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.9 with SMTP id o9ls732248lao.83.gmail; Tue, 20 Jan 2015 03:20:37 -0800 (PST) X-Received: by 10.112.125.202 with SMTP id ms10mr37456007lbb.33.1421752837029; Tue, 20 Jan 2015 03:20:37 -0800 (PST) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id jd8si14878617lbc.99.2015.01.20.03.20.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 20 Jan 2015 03:20:37 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by mail-la0-f46.google.com with SMTP id s18so12712353lam.5 for ; Tue, 20 Jan 2015 03:20:37 -0800 (PST) X-Received: by 10.112.170.36 with SMTP id aj4mr37205821lbc.3.1421752836932; Tue, 20 Jan 2015 03:20:36 -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 c8csp1381061lbb; Tue, 20 Jan 2015 03:20:35 -0800 (PST) X-Received: by 10.224.103.195 with SMTP id l3mr56901534qao.38.1421752835312; Tue, 20 Jan 2015 03:20:35 -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 k11si8877126qav.104.2015.01.20.03.20.34 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 20 Jan 2015 03:20:35 -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 1YDWrE-0006TE-L1; Tue, 20 Jan 2015 11:20:28 +0000 Received: from mail-qg0-f49.google.com ([209.85.192.49]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YDWqR-0006H7-9Z for lng-odp@lists.linaro.org; Tue, 20 Jan 2015 11:19:39 +0000 Received: by mail-qg0-f49.google.com with SMTP id i50so5014148qgf.8 for ; Tue, 20 Jan 2015 03:19:34 -0800 (PST) X-Received: by 10.224.22.196 with SMTP id o4mr56045815qab.85.1421752774157; Tue, 20 Jan 2015 03:19:34 -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 t2sm14975907qae.6.2015.01.20.03.19.32 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 20 Jan 2015 03:19:33 -0800 (PST) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Tue, 20 Jan 2015 13:18:12 +0200 Message-Id: <1421752692-24439-17-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1421752692-24439-1-git-send-email-petri.savolainen@linaro.org> References: <1421752692-24439-1-git-send-email-petri.savolainen@linaro.org> X-Topics: timers patch Subject: [lng-odp] [PATCH v2 16/16] api: timer: Added timeout alloc and free 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.215.46 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 * Timeout is an event that has a dedicated pool type. Added timeout_alloc, _free and _to_event functions to avoid timeout <-> buffer conversions (which must not be done anymore). * Added timeout pool parameters (num). Pool was modified minimally (re-uses still buf.xxx params). Signed-off-by: Petri Savolainen --- example/timer/odp_timer_test.c | 26 +++++++++---------- platform/linux-generic/include/api/odp_pool.h | 5 +++- platform/linux-generic/include/api/odp_timer.h | 35 ++++++++++++++++++++++++++ platform/linux-generic/odp_buffer_pool.c | 10 ++++++-- platform/linux-generic/odp_timer.c | 19 ++++++++++++++ test/validation/odp_timer.c | 20 ++++++--------- 6 files changed, 86 insertions(+), 29 deletions(-) diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c index 737a46a..8945fa5 100644 --- a/example/timer/odp_timer_test.c +++ b/example/timer/odp_timer_test.c @@ -26,7 +26,7 @@ #define MAX_WORKERS 32 /**< Max worker threads */ -#define MSG_NUM_BUFS 10000 /**< Number of timers */ +#define NUM_TMOS 10000 /**< Number of timers */ /** Test arguments */ @@ -43,7 +43,7 @@ typedef struct { /** @private Barrier for test synchronisation */ static odp_barrier_t test_barrier; -/** @private Buffer pool handle */ +/** @private Pool handle */ static odp_pool_t pool; /** @private Timer pool handle */ @@ -86,7 +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; + odp_timeout_t tmo; EXAMPLE_DBG(" [%i] test_timeouts\n", thr); @@ -107,12 +107,12 @@ static void test_abs_timeouts(int thr, test_args_t *args) EXAMPLE_ERR("Failed to allocate timer\n"); return; } - buf = odp_buffer_alloc(pool); - if (buf == ODP_BUFFER_INVALID) { - EXAMPLE_ERR("Failed to allocate buffer\n"); + tmo = odp_timeout_alloc(pool); + if (tmo == ODP_TIMEOUT_INVALID) { + EXAMPLE_ERR("Failed to allocate timeout\n"); return; } - ttp->ev = odp_buffer_to_event(buf); + ttp->ev = odp_timeout_to_event(tmo); tick = odp_timer_current_tick(tp); while ((int)odp_atomic_load_u32(&remain) > 0) { @@ -158,7 +158,7 @@ static void test_abs_timeouts(int thr, test_args_t *args) /* Cancel and free last timer used */ (void)odp_timer_cancel(ttp->tim, &ttp->ev); if (ttp->ev != ODP_EVENT_INVALID) - odp_buffer_free(odp_buffer_from_event(ttp->ev)); + odp_timeout_free(odp_timeout_from_event(ttp->ev)); else EXAMPLE_ERR("Lost timeout event at timer cancel\n"); /* Since we have cancelled the timer, there is no timeout event to @@ -186,7 +186,7 @@ static void *run_thread(void *ptr) printf("Thread %i starts on cpu %i\n", thr, odp_thread_cpu()); /* - * Find the buffer pool + * Find the pool */ msg_pool = odp_pool_lookup("msg_pool"); @@ -362,17 +362,15 @@ int main(int argc, char *argv[]) printf("timeouts: %i\n", args.tmo_count); /* - * Create buffer pool for timeouts + * Create pool for timeouts */ - params.buf.size = 0; - params.buf.align = 0; - params.buf.num = MSG_NUM_BUFS; + params.tmo.num = NUM_TMOS; params.type = ODP_POOL_TIMEOUT; pool = odp_pool_create("msg_pool", ODP_SHM_NULL, ¶ms); if (pool == ODP_POOL_INVALID) { - EXAMPLE_ERR("Buffer pool create failed.\n"); + EXAMPLE_ERR("Pool create failed.\n"); return -1; } diff --git a/platform/linux-generic/include/api/odp_pool.h b/platform/linux-generic/include/api/odp_pool.h index 7e5e3c5..60962dd 100644 --- a/platform/linux-generic/include/api/odp_pool.h +++ b/platform/linux-generic/include/api/odp_pool.h @@ -57,9 +57,12 @@ typedef struct odp_pool_param_t { uint32_t seg_align; uint32_t num; } pkt; +*/ struct { + uint32_t __res1; /* Keep struct identical to buf, */ + uint32_t __res2; /* until pool implementation is fixed*/ + uint32_t num; /**< Number of timeouts in the pool */ } tmo; -*/ }; int type; /**< Pool type */ diff --git a/platform/linux-generic/include/api/odp_timer.h b/platform/linux-generic/include/api/odp_timer.h index 075263a..ff61276 100644 --- a/platform/linux-generic/include/api/odp_timer.h +++ b/platform/linux-generic/include/api/odp_timer.h @@ -66,6 +66,11 @@ typedef void *odp_timeout_t; #define ODP_TIMER_INVALID ((uint32_t)~0U) /** + * Invalid timeout handle (platform dependent). + */ +#define ODP_TIMEOUT_INVALID NULL + +/** * Return values of timer set calls. */ typedef enum { @@ -310,6 +315,15 @@ int odp_timer_cancel(odp_timer_t tim, odp_event_t *tmo_ev); odp_timeout_t odp_timeout_from_event(odp_event_t ev); /** + * Convert timeout handle to event handle + * + * @param tmo Timeout handle + * + * @return Event handle + */ +odp_event_t odp_timeout_to_event(odp_timeout_t tmo); + +/** * Check for fresh timeout * If the corresponding timer has been reset or cancelled since this timeout * was enqueued, the timeout is stale (not fresh). @@ -358,6 +372,27 @@ uint64_t odp_timeout_tick(odp_timeout_t tmo); void *odp_timeout_user_ptr(odp_timeout_t tmo); /** + * Timeout alloc + * + * Allocates timeout from pool. Pool must be created with ODP_POOL_TIMEOUT type. + * + * @param pool Pool handle + * + * @return Timeout handle + * @retval ODP_TIMEOUT_INVALID Timeout could not be allocated + */ +odp_timeout_t odp_timeout_alloc(odp_pool_t); + +/** + * Timeout free + * + * Frees the timeout back to the pool it was allocated from. + * + * @param tmo Timeout handle + */ +void odp_timeout_free(odp_timeout_t tmo); + +/** * @} */ diff --git a/platform/linux-generic/odp_buffer_pool.c b/platform/linux-generic/odp_buffer_pool.c index dcb1e5e..ac12057 100644 --- a/platform/linux-generic/odp_buffer_pool.c +++ b/platform/linux-generic/odp_buffer_pool.c @@ -100,13 +100,19 @@ int odp_buffer_pool_init_global(void) */ odp_pool_t odp_pool_create(const char *name, - odp_shm_t shm, - odp_pool_param_t *params) + odp_shm_t shm, + odp_pool_param_t *params) { odp_pool_t pool_hdl = ODP_POOL_INVALID; pool_entry_t *pool; uint32_t i, headroom = 0, tailroom = 0; + /* Default size and align for timeouts */ + if (params->type == ODP_POOL_TIMEOUT) { + params->buf.size = 0; /* tmo.__res1 */ + params->buf.align = 0; /* tmo.__res2 */ + } + /* Default initialization paramters */ static _odp_buffer_pool_init_t default_init_params = { .udata_size = 0, diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index 3194310..c9ad610 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -803,6 +803,13 @@ odp_timeout_t odp_timeout_from_event(odp_event_t ev) return (odp_timeout_t)timeout_hdr_from_buf(odp_buffer_from_event(ev)); } +odp_event_t odp_timeout_to_event(odp_timeout_t tmo) +{ + odp_timeout_hdr_t *tmo_hdr = (odp_timeout_hdr_t *)tmo; + odp_buffer_t buf = odp_hdr_to_buf(&tmo_hdr->buf_hdr); + return odp_buffer_to_event(buf); +} + int odp_timeout_fresh(odp_timeout_t tmo) { const odp_timeout_hdr_t *hdr = (odp_timeout_hdr_t *)tmo; @@ -834,6 +841,18 @@ void *odp_timeout_user_ptr(odp_timeout_t tmo) return hdr->user_ptr; } +odp_timeout_t odp_timeout_alloc(odp_pool_t pool) +{ + odp_buffer_t buf = odp_buffer_alloc(pool); + return odp_timeout_from_event(odp_buffer_to_event(buf)); +} + +void odp_timeout_free(odp_timeout_t tmo) +{ + odp_event_t ev = odp_timeout_to_event(tmo); + odp_buffer_free(odp_buffer_from_event(ev)); +} + int odp_timer_init_global(void) { #ifndef ODP_ATOMIC_U128 diff --git a/test/validation/odp_timer.c b/test/validation/odp_timer.c index 3783531..c0b6f67 100644 --- a/test/validation/odp_timer.c +++ b/test/validation/odp_timer.c @@ -22,7 +22,7 @@ /** @private Barrier for thread synchronisation */ static odp_barrier_t test_barrier; -/** @private Timeout buffer pool handle used by all threads */ +/** @private Timeout pool handle used by all threads */ static odp_pool_t tbp; /** @private Timer pool handle used by all threads */ @@ -123,11 +123,9 @@ static void *worker_entrypoint(void *arg) tt[i].tim = odp_timer_alloc(tp, queue, &tt[i]); if (tt[i].tim == ODP_TIMER_INVALID) CU_FAIL_FATAL("Failed to allocate timer"); - /* Timeout alloc is needed. - * With this alloc call pool/event type should be buffer. */ - tt[i].ev = odp_buffer_to_event(odp_buffer_alloc(tbp)); + tt[i].ev = odp_timeout_to_event(odp_timeout_alloc(tbp)); if (tt[i].ev == ODP_EVENT_INVALID) - CU_FAIL_FATAL("Failed to allocate timeout buffer"); + CU_FAIL_FATAL("Failed to allocate timeout"); tt[i].ev2 = tt[i].ev; tt[i].tick = TICK_INVALID; } @@ -216,7 +214,7 @@ static void *worker_entrypoint(void *arg) tt[i].tick = TICK_INVALID; if (tt[i].ev == ODP_EVENT_INVALID) /* Cancel too late, timer already expired and - * timoeut buffer enqueued */ + * timeout enqueued */ nstale++; if (odp_timer_free(tt[i].tim) != ODP_EVENT_INVALID) CU_FAIL("odp_timer_free"); @@ -262,14 +260,12 @@ static void test_odp_timer_all(void) * @TODO move to test/performance */ int num_workers = min(odp_sys_cpu_count()-1, MAX_WORKERS); - /* Create timeout buffer pools */ - params.buf.size = 0; - params.buf.align = ODP_CACHE_LINE_SIZE; - params.buf.num = (NTIMERS + 1) * num_workers; - params.type = ODP_POOL_TIMEOUT; + /* Create timeout pools */ + params.tmo.num = (NTIMERS + 1) * num_workers; + params.type = ODP_POOL_TIMEOUT; tbp = odp_pool_create("tmo_pool", ODP_SHM_INVALID, ¶ms); if (tbp == ODP_POOL_INVALID) - CU_FAIL_FATAL("Timeout buffer pool create failed"); + CU_FAIL_FATAL("Timeout pool create failed"); #define NAME "timer_pool" #define RES (10 * ODP_TIME_MSEC / 3)