From patchwork Mon Jan 26 13:05:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 43755 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1406523FFF for ; Mon, 26 Jan 2015 13:08:14 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id gq15sf4201822lab.3 for ; Mon, 26 Jan 2015 05:08:13 -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=Ki9/9MSqM8uEhHFgdYiR9J5AZ04/Eh7wmL8cjSC+QhKBy/X+hil3hThqk2fzMsgCU2 HjchUyd8EQbq1fvevA6IC+PCeYiRdLjYzCw2qw1fW4imfuJFO3S34sDevRZlqPr57NUK 48nnFLOQ+rwv+hSGV+roELKdLnLe09DUj/zGN25nZXdAhEYEOw7Mv1Cae9lRwkP/jzA+ M2HrGM9XRq20gImpKfEpdNJJYESwjqNslG6dLVBu7fFIKjMA3kRf4G03m91bfdJhmMZY gMM6ZJt6VcJMnSLW9L7QN57ua6+s9AfkpXOrkCBPW6m7x/1IEXOyiPzHDV3khvpd/vqO A97g== X-Gm-Message-State: ALoCoQltj66xt+dOi7n1YuM6fssDHKfdEfcoSn9ae5/LG+YC8TljnKYh7c8RX/k+AdJPAh37JpU8 X-Received: by 10.112.213.72 with SMTP id nq8mr1297479lbc.18.1422277692964; Mon, 26 Jan 2015 05:08:12 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.68 with SMTP id kw4ls436414lac.101.gmail; Mon, 26 Jan 2015 05:08:12 -0800 (PST) X-Received: by 10.152.3.70 with SMTP id a6mr21061820laa.71.1422277692818; Mon, 26 Jan 2015 05:08:12 -0800 (PST) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id bf5si8930253lab.128.2015.01.26.05.08.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 26 Jan 2015 05:08:12 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by mail-la0-f45.google.com with SMTP id gd6so7463786lab.4 for ; Mon, 26 Jan 2015 05:08:12 -0800 (PST) X-Received: by 10.152.5.226 with SMTP id v2mr21076152lav.34.1422277692676; Mon, 26 Jan 2015 05:08:12 -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.35.133 with SMTP id h5csp774582lbj; Mon, 26 Jan 2015 05:08:11 -0800 (PST) X-Received: by 10.140.42.194 with SMTP id c60mr38622938qga.61.1422277690465; Mon, 26 Jan 2015 05:08:10 -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 w5si13038235qge.81.2015.01.26.05.08.09 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 26 Jan 2015 05:08:10 -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 1YFjOh-0005An-6i; Mon, 26 Jan 2015 13:08:07 +0000 Received: from mail-qg0-f50.google.com ([209.85.192.50]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YFjNU-0004pT-R6 for lng-odp@lists.linaro.org; Mon, 26 Jan 2015 13:06:52 +0000 Received: by mail-qg0-f50.google.com with SMTP id f51so6570159qge.9 for ; Mon, 26 Jan 2015 05:06:47 -0800 (PST) X-Received: by 10.224.79.137 with SMTP id p9mr34796283qak.32.1422277607630; Mon, 26 Jan 2015 05:06:47 -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 a1sm4972929qab.28.2015.01.26.05.06.45 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 26 Jan 2015 05:06:46 -0800 (PST) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Mon, 26 Jan 2015 15:05:50 +0200 Message-Id: <1422277551-16417-17-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1422277551-16417-1-git-send-email-petri.savolainen@linaro.org> References: <1422277551-16417-1-git-send-email-petri.savolainen@linaro.org> X-Topics: timers patch Subject: [lng-odp] [PATCH v5 16/17] 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.45 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)