From patchwork Fri Jan 23 11:42:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 43626 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B692B240D9 for ; Fri, 23 Jan 2015 11:44:25 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id c13sf4554095eek.1 for ; Fri, 23 Jan 2015 03:44:25 -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=whiQnN0NoD6KScljImZG755w2HoNOdvQPSWjWACIgJQ=; b=myVhOQ5P0VgJc77PNcKXtsfuj5e5R3mziJLCvHMeff49Hxqyi3yenH43P0UUWl1pGh oJCZreGKKrjsjVt412OEzGfkwjjFgsTHkiIxts2UVYAxb52STP+fSn1rDrOE5OPBWubN TpO+6xy1XUOpPi0AUkRiO+ndRfeZoQe7OMaN9u60Mkbt+9iHA6AQ9g2Cb25krOHrMVak OFXLPSwaYvPEFPlrRMD1RccDYgssJxYUylroVrhyz7ZRfT/ezxUeAvfK5MnnYVTt0Az4 Qq6NhhIC3UOhm/T2JFcwd02I8wYBE0TZ5pIV7QLo/9MOxUrzakICWFRI0b1nGBhYmtEP YXgg== X-Gm-Message-State: ALoCoQn0HNywb7FSu2dZB66uU6V4aeE90Uw0Y9LCt8dI2SoKsQ0SIOJeoGRGAhaymNTItrMTJSkA X-Received: by 10.194.78.42 with SMTP id y10mr160785wjw.4.1422013465019; Fri, 23 Jan 2015 03:44:25 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.182.172 with SMTP id ef12ls253736lac.104.gmail; Fri, 23 Jan 2015 03:44:24 -0800 (PST) X-Received: by 10.112.235.67 with SMTP id uk3mr6868074lbc.48.1422013464790; Fri, 23 Jan 2015 03:44:24 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id lc12si1175892lbb.14.2015.01.23.03.44.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Jan 2015 03:44:24 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id l4so6539342lbv.13 for ; Fri, 23 Jan 2015 03:44:24 -0800 (PST) X-Received: by 10.152.245.44 with SMTP id xl12mr1184904lac.81.1422013464701; Fri, 23 Jan 2015 03:44:24 -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 c8csp221126lbb; Fri, 23 Jan 2015 03:44:23 -0800 (PST) X-Received: by 10.140.22.99 with SMTP id 90mr12450947qgm.72.1422013462679; Fri, 23 Jan 2015 03:44:22 -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 j4si1558387qao.97.2015.01.23.03.44.21 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 23 Jan 2015 03:44:22 -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 1YEcex-0003Xa-E0; Fri, 23 Jan 2015 11:44:19 +0000 Received: from mail-qg0-f42.google.com ([209.85.192.42]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YEceA-0003P2-UN for lng-odp@lists.linaro.org; Fri, 23 Jan 2015 11:43:30 +0000 Received: by mail-qg0-f42.google.com with SMTP id q107so5614045qgd.1 for ; Fri, 23 Jan 2015 03:43:25 -0800 (PST) X-Received: by 10.224.14.84 with SMTP id f20mr13001519qaa.43.1422013405774; Fri, 23 Jan 2015 03:43:25 -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 f7sm1182892qaq.42.2015.01.23.03.43.23 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 23 Jan 2015 03:43:24 -0800 (PST) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Fri, 23 Jan 2015 13:42:24 +0200 Message-Id: <1422013344-6655-17-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1422013344-6655-1-git-send-email-petri.savolainen@linaro.org> References: <1422013344-6655-1-git-send-email-petri.savolainen@linaro.org> X-Topics: timers patch Subject: [lng-odp] [PATCH v4 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.217.182 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/buffer/odp_buffer_pool_test.c | 13 ++++++++-- test/validation/odp_timer.c | 20 ++++++--------- 7 files changed, 97 insertions(+), 31 deletions(-) diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c index 808b582..fafa0a4 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) { @@ -167,7 +167,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 @@ -195,7 +195,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"); @@ -371,17 +371,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 8a39fb3..174bb06 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..b904738 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 pool); + +/** + * 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 a09d189..11fc69e 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -804,6 +804,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; @@ -835,6 +842,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/buffer/odp_buffer_pool_test.c b/test/validation/buffer/odp_buffer_pool_test.c index 6ef2238..c018b59 100644 --- a/test/validation/buffer/odp_buffer_pool_test.c +++ b/test/validation/buffer/odp_buffer_pool_test.c @@ -121,6 +121,7 @@ static void pool_alloc_type(int type) const size_t size = 1500; odp_buffer_t buffer[num]; odp_packet_t packet[num]; + odp_timeout_t tmo[num]; odp_event_t ev; int index; char wrong_type = 0, wrong_size = 0; @@ -145,7 +146,6 @@ static void pool_alloc_type(int type) if (wrong_type || wrong_size) odp_buffer_print(buffer[index]); break; - case ODP_POOL_PACKET: packet[index] = odp_packet_alloc(pool, size); @@ -157,7 +157,14 @@ static void pool_alloc_type(int type) wrong_type = 1; break; case ODP_POOL_TIMEOUT: - /* Don't test timeout alloc until it's implemented */ + tmo[index] = odp_timeout_alloc(pool); + + if (tmo[index] == ODP_TIMEOUT_INVALID) + break; + + ev = odp_timeout_to_event(tmo[index]); + if (odp_event_type(ev) != ODP_EVENT_TIMEOUT) + wrong_type = 1; break; default: break; @@ -184,6 +191,8 @@ static void pool_alloc_type(int type) odp_packet_free(packet[index]); break; case ODP_POOL_TIMEOUT: + for (; index >= 0; index--) + odp_timeout_free(tmo[index]); break; default: break; 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)