From patchwork Wed Jan 21 15:15:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 43459 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 CC8B0218DB for ; Wed, 21 Jan 2015 15:18:56 +0000 (UTC) Received: by mail-we0-f199.google.com with SMTP id k11sf23289990wes.2 for ; Wed, 21 Jan 2015 07:18:56 -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=jTM7k/OuV9zBc+RlLf/tuz8Mg8IgRXdlaYqBWu/C67E=; b=Qb/EyaAavp/E9ZK4yo4mIlA1KZztHc+YGIavAeDTcmrnMrhwc+SDitNEl/rUzQIEDP DDAaMIPjegAe6F63Sq6oTCJp+v611Uc5MRCTJu4aQkVhoKeQR1/qtyAaNNT9Rtz0Z3l0 Ji1uHh2dSV13DUf/ta5k76QXHPX+7qKx2fz/JZ512o6jDOZg2+ocBP8/K+AkOcO3mrec N/1fwv6dm/zuiupMZWoIiQU+8obJGOHAozK/P0RmpdAfpLD89f2PnAzw2iAzT1BTZJVW UzCEy8VABs9floj8uzXgQXb6ouUaifmWtgVDzPCsMq+cpeu5f5uFjfEXdny/RA51wgnG Vbsg== X-Gm-Message-State: ALoCoQnu9BZDlsNoOXDH4gdflcgPePs+K+4n3zhOrp4CHT5SfyZcL63BV82cG3ETq5MAsOubSm2R X-Received: by 10.152.170.201 with SMTP id ao9mr375415lac.5.1421853536046; Wed, 21 Jan 2015 07:18:56 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.7.132 with SMTP id dc4ls41799lad.97.gmail; Wed, 21 Jan 2015 07:18:55 -0800 (PST) X-Received: by 10.152.87.106 with SMTP id w10mr15990540laz.41.1421853535903; Wed, 21 Jan 2015 07:18:55 -0800 (PST) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id ld9si18169928lbc.77.2015.01.21.07.18.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 21 Jan 2015 07:18:55 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by mail-lb0-f179.google.com with SMTP id z11so39831613lbi.10 for ; Wed, 21 Jan 2015 07:18:55 -0800 (PST) X-Received: by 10.152.180.136 with SMTP id do8mr18470905lac.31.1421853535622; Wed, 21 Jan 2015 07:18:55 -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 c8csp1810643lbb; Wed, 21 Jan 2015 07:18:54 -0800 (PST) X-Received: by 10.140.91.74 with SMTP id y68mr38553289qgd.90.1421853533645; Wed, 21 Jan 2015 07:18:53 -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 q9si482488qgq.83.2015.01.21.07.18.52 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 21 Jan 2015 07:18:53 -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 1YDx3R-0008Cq-Su; Wed, 21 Jan 2015 15:18:49 +0000 Received: from mail-qg0-f47.google.com ([209.85.192.47]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YDx2L-00080x-SY for lng-odp@lists.linaro.org; Wed, 21 Jan 2015 15:17:41 +0000 Received: by mail-qg0-f47.google.com with SMTP id z60so3256027qgd.6 for ; Wed, 21 Jan 2015 07:17:36 -0800 (PST) X-Received: by 10.224.79.12 with SMTP id n12mr69594649qak.2.1421853455594; Wed, 21 Jan 2015 07:17:35 -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 91sm415056qgf.1.2015.01.21.07.17.33 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 21 Jan 2015 07:17:34 -0800 (PST) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Wed, 21 Jan 2015 17:15:43 +0200 Message-Id: <1421853343-22138-17-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1421853343-22138-1-git-send-email-petri.savolainen@linaro.org> References: <1421853343-22138-1-git-send-email-petri.savolainen@linaro.org> X-Topics: timers patch Subject: [lng-odp] [PATCH v3 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.179 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 | 17 ++++++++++--- test/validation/odp_timer.c | 20 ++++++--------- 7 files changed, 100 insertions(+), 32 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 d1623f1..aded64a 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 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 18a5756..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; @@ -132,7 +133,6 @@ static void pool_alloc_type(int type) for (index = 0; index < num; index++) { switch (type) { case ODP_POOL_BUFFER: - case ODP_POOL_TIMEOUT: buffer[index] = odp_buffer_alloc(pool); if (buffer[index] == ODP_BUFFER_INVALID) @@ -146,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 +156,16 @@ static void pool_alloc_type(int type) if (odp_event_type(ev) != ODP_EVENT_PACKET) wrong_type = 1; break; + case ODP_POOL_TIMEOUT: + 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; } @@ -175,7 +183,6 @@ static void pool_alloc_type(int type) switch (type) { case ODP_POOL_BUFFER: - case ODP_POOL_TIMEOUT: for (; index >= 0; index--) odp_buffer_free(buffer[index]); break; @@ -183,6 +190,10 @@ static void pool_alloc_type(int type) for (; index >= 0; index--) 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)