From patchwork Fri Apr 25 08:07:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 29033 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yk0-f199.google.com (mail-yk0-f199.google.com [209.85.160.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E5AB3203AC for ; Fri, 25 Apr 2014 08:05:25 +0000 (UTC) Received: by mail-yk0-f199.google.com with SMTP id 200sf4296359ykr.6 for ; Fri, 25 Apr 2014 01:05:25 -0700 (PDT) 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:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=SVVoWwVdzVLS4uqa7eXmsqFk+lWlzJPqHp7aBCcAK7E=; b=f87Tr0M+ondT5y9eV3EupCW5gImjqEylt20f0lREWjryNhfMPxGpRzHL7rBNdGCtBi oYHu7YJ4buVPvCaAlacVXkQBYRTL4h047aL8YoH5Y5MbqZWyQ+Vz+56MdQrMfBATx9xz I3lixvGTkN+xveaijMZpA9y40n+HIsbMtLmQ5M3mfu/JszMTEQmboSE1Mxxyl33lnnD6 AIDPoJYQwmd3lvM3ArQoO8Uuo/nGXmKr712xQ/lhzqISrFrtcCnTYkQkoewtZNI1d9nu os9ZqM6oKJuTSC3GHuIlxcBoz/SUSV53EKdsHehtjZMQTk5yt3jmiSrgtKz2obn4VMm6 oNcw== X-Gm-Message-State: ALoCoQkgVSgqttcyjVag3GAmxkRAb1SCezKZxupdcwJbGRToj26WjO+EMV3onXyQrZ3skjpt4LTU X-Received: by 10.236.134.98 with SMTP id r62mr3133560yhi.14.1398413125680; Fri, 25 Apr 2014 01:05:25 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.97.66 with SMTP id l60ls949126qge.17.gmail; Fri, 25 Apr 2014 01:05:25 -0700 (PDT) X-Received: by 10.52.251.199 with SMTP id zm7mr4688539vdc.21.1398413125560; Fri, 25 Apr 2014 01:05:25 -0700 (PDT) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id dh4si1538104veb.49.2014.04.25.01.05.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 25 Apr 2014 01:05:25 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id sa20so4241757veb.22 for ; Fri, 25 Apr 2014 01:05:25 -0700 (PDT) X-Received: by 10.221.74.200 with SMTP id yx8mr5481133vcb.3.1398413125441; Fri, 25 Apr 2014 01:05:25 -0700 (PDT) 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.220.221.72 with SMTP id ib8csp78364vcb; Fri, 25 Apr 2014 01:05:24 -0700 (PDT) X-Received: by 10.224.161.10 with SMTP id p10mr9566148qax.12.1398413124226; Fri, 25 Apr 2014 01:05:24 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id s6si3444250qaj.177.2014.04.25.01.04.54 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 25 Apr 2014 01:05:24 -0700 (PDT) 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-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Wdb7W-0002IJ-8j; Fri, 25 Apr 2014 08:04:30 +0000 Received: from mail-qc0-f178.google.com ([209.85.216.178]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Wdb7Q-0002IE-8z for lng-odp@lists.linaro.org; Fri, 25 Apr 2014 08:04:24 +0000 Received: by mail-qc0-f178.google.com with SMTP id i8so3589596qcq.23 for ; Fri, 25 Apr 2014 01:04:42 -0700 (PDT) X-Received: by 10.140.98.233 with SMTP id o96mr8898650qge.86.1398413082212; Fri, 25 Apr 2014 01:04:42 -0700 (PDT) Received: from localhost.localdomain (ec2-23-23-178-99.compute-1.amazonaws.com. [23.23.178.99]) by mx.google.com with ESMTPSA id m7sm2012811qae.35.2014.04.25.01.04.39 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 25 Apr 2014 01:04:41 -0700 (PDT) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Fri, 25 Apr 2014 11:07:39 +0300 Message-Id: <1398413259-10207-1-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 1.9.1 Subject: [lng-odp] [PATCH] Added timeout buffer type 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=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) 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 New buffer types: timeout and any. Timeout is used for timeout nofications. A pool initilized with buffer type 'any' can allocate buffers for different usage (raw, packet, timeout, ...). Signed-off-by: Petri Savolainen --- include/odp_buffer.h | 8 ++-- include/odp_timer.h | 31 +++++++++++-- .../linux-generic/include/odp_buffer_internal.h | 5 ++- .../linux-generic/include/odp_timer_internal.h | 52 ++++++++++++++++++++++ platform/linux-generic/source/odp_buffer.c | 4 +- platform/linux-generic/source/odp_buffer_pool.c | 33 +++++++++++--- platform/linux-generic/source/odp_timer.c | 13 ++++++ test/timer/odp_timer_test.c | 11 ++++- 8 files changed, 140 insertions(+), 17 deletions(-) create mode 100644 platform/linux-generic/include/odp_timer_internal.h diff --git a/include/odp_buffer.h b/include/odp_buffer.h index 2d2c25a..3156a20 100644 --- a/include/odp_buffer.h +++ b/include/odp_buffer.h @@ -62,9 +62,11 @@ size_t odp_buffer_size(odp_buffer_t buf); int odp_buffer_type(odp_buffer_t buf); #define ODP_BUFFER_TYPE_INVALID (-1) /**< Buffer type invalid */ -#define ODP_BUFFER_TYPE_RAW 0 /**< Raw buffer */ -#define ODP_BUFFER_TYPE_PACKET 1 /**< Packet buffer */ -#define ODP_BUFFER_TYPE_TIMER 2 /**< Timer buffer */ +#define ODP_BUFFER_TYPE_ANY 0 /**< Buffer that can hold any other + buffer types */ +#define ODP_BUFFER_TYPE_RAW 1 /**< Raw buffer, no metadata */ +#define ODP_BUFFER_TYPE_PACKET 2 /**< Packet buffer */ +#define ODP_BUFFER_TYPE_TIMEOUT 3 /**< Timeout buffer */ /** * Tests if buffer is part of a scatter/gather list diff --git a/include/odp_timer.h b/include/odp_timer.h index 80babd1..e7a6200 100644 --- a/include/odp_timer.h +++ b/include/odp_timer.h @@ -25,8 +25,8 @@ extern "C" { /** -* ODP timer handle -*/ + * ODP timer handle + */ typedef uint32_t odp_timer_t; /** Invalid timer */ @@ -34,8 +34,8 @@ typedef uint32_t odp_timer_t; /** -* ODP timeout handle -*/ + * ODP timeout handle + */ typedef odp_buffer_t odp_timer_tmo_t; /** Invalid timeout */ @@ -43,6 +43,12 @@ typedef odp_buffer_t odp_timer_tmo_t; /** + * Timeout notification + */ +typedef void *odp_timeout_t; + + +/** * Create a timer * * Creates a new timer with requested properties. @@ -133,6 +139,23 @@ odp_timer_tmo_t odp_timer_absolute_tmo(odp_timer_t timer, uint64_t tmo_tick, */ int odp_timer_cancel_tmo(odp_timer_t timer, odp_timer_tmo_t tmo); +/** + * Convert buffer handle to timeout handle + * + * @param buf Buffer handle + * + * @return Timeout buffer handle + */ +odp_timeout_t odp_timeout_from_buffer(odp_buffer_t buf); + +/** + * Return absolute timeout tick + * + * @param tmo Timeout buffer handle + * + * @return Absolute timeout tick + */ +uint64_t odp_timeout_tick(odp_timeout_t tmo); #ifdef __cplusplus } diff --git a/platform/linux-generic/include/odp_buffer_internal.h b/platform/linux-generic/include/odp_buffer_internal.h index f8ebc7c..d24c748 100644 --- a/platform/linux-generic/include/odp_buffer_internal.h +++ b/platform/linux-generic/include/odp_buffer_internal.h @@ -89,8 +89,11 @@ typedef struct odp_buffer_hdr_t { size_t cur_offset; /* current offset */ odp_atomic_int_t ref_count; /* reference count */ odp_buffer_scatter_t scatter; /* Scatter/gather list */ - int type; /* type of next header */ odp_buffer_pool_t pool; /* buffer pool */ + int org_type; /* original buffer type */ + int cur_type; /* type of next header */ + + int pad; /* padding for payload align */ uint8_t payload[]; /* next header or data */ } odp_buffer_hdr_t; diff --git a/platform/linux-generic/include/odp_timer_internal.h b/platform/linux-generic/include/odp_timer_internal.h new file mode 100644 index 0000000..97851a2 --- /dev/null +++ b/platform/linux-generic/include/odp_timer_internal.h @@ -0,0 +1,52 @@ +/* Copyright (c) 2013, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + + +/** + * @file + * + * ODP timer timeout descriptor - implementation internal + */ + +#ifndef ODP_TIMER_INTERNAL_H_ +#define ODP_TIMER_INTERNAL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + +struct odp_timeout_hdr_t; + +/** + * Timeout notification header + */ +typedef struct odp_timeout_hdr_t { + odp_buffer_hdr_t buf_hdr; + + uint64_t tick; + + uint8_t payload[]; +} odp_timeout_hdr_t; + + + +ODP_ASSERT(sizeof(odp_timeout_hdr_t) == + ODP_OFFSETOF(odp_timeout_hdr_t, payload), + ODP_TIMEOUT_HDR_T__SIZE_ERR); + +ODP_ASSERT(sizeof(odp_timeout_hdr_t) % sizeof(uint64_t) == 0, + ODP_TIMEOUT_HDR_T__SIZE_ERR2); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/source/odp_buffer.c b/platform/linux-generic/source/odp_buffer.c index afbe96a..ff7a892 100644 --- a/platform/linux-generic/source/odp_buffer.c +++ b/platform/linux-generic/source/odp_buffer.c @@ -32,7 +32,7 @@ int odp_buffer_type(odp_buffer_t buf) { odp_buffer_hdr_t *hdr = odp_buf_to_hdr(buf); - return hdr->type; + return hdr->cur_type; } @@ -86,7 +86,7 @@ int odp_buffer_snprint(char *str, size_t n, odp_buffer_t buf) len += snprintf(&str[len], n-len, " ref_count %i\n", hdr->ref_count); len += snprintf(&str[len], n-len, - " type %i\n", hdr->type); + " type %i\n", hdr->cur_type); len += snprintf(&str[len], n-len, " Scatter list\n"); len += snprintf(&str[len], n-len, diff --git a/platform/linux-generic/source/odp_buffer_pool.c b/platform/linux-generic/source/odp_buffer_pool.c index 90214ba..3a5cb94 100644 --- a/platform/linux-generic/source/odp_buffer_pool.c +++ b/platform/linux-generic/source/odp_buffer_pool.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,15 @@ #define NULL_INDEX ((uint32_t)-1) +union buffer_type_any_u { + odp_buffer_hdr_t buf; + odp_packet_hdr_t pkt; + odp_timeout_hdr_t tmo; +}; + +ODP_ASSERT(sizeof(union buffer_type_any_u) % sizeof(uint64_t) == 0, + BUFFER_TYPE_ANY_U__SIZE_ERR); + typedef union pool_entry_u { struct pool_entry_s s; @@ -177,8 +187,9 @@ static void add_chunk(pool_entry_t *pool, odp_buffer_chunk_hdr_t *chunk_hdr) if (pool->s.head) { /* link pool head to the chunk */ add_buf_index(chunk_hdr, pool->s.head->buf_hdr.index); - } else + } else { add_buf_index(chunk_hdr, NULL_INDEX); + } pool->s.head = chunk_hdr; pool->s.free_bufs += ODP_BUFS_PER_CHUNK; @@ -214,6 +225,11 @@ static void fill_hdr(void *ptr, pool_entry_t *pool, uint32_t index, if (pool->s.buf_type == ODP_BUFFER_TYPE_PACKET) { odp_packet_hdr_t *packet_hdr = ptr; payload = packet_hdr->payload; + } else if (pool->s.buf_type == ODP_BUFFER_TYPE_TIMEOUT) { + odp_timeout_hdr_t *tmo_hdr = ptr; + payload = tmo_hdr->payload; + } else if (pool->s.buf_type == ODP_BUFFER_TYPE_ANY) { + payload = ((uint8_t *)ptr) + sizeof(union buffer_type_any_u); } memset(hdr, 0, size); @@ -224,7 +240,8 @@ static void fill_hdr(void *ptr, pool_entry_t *pool, uint32_t index, hdr->index = index; hdr->size = pool->s.payload_size; hdr->pool = pool->s.pool; - hdr->type = buf_type; + hdr->org_type = pool->s.buf_type; + hdr->cur_type = buf_type; check_align(pool, hdr); } @@ -251,11 +268,15 @@ static void link_bufs(pool_entry_t *pool) pool_size = pool->s.pool_size; pool_base = (uintptr_t) pool->s.pool_base_addr; - if (buf_type == ODP_BUFFER_TYPE_RAW) + if (buf_type == ODP_BUFFER_TYPE_RAW) { hdr_size = sizeof(odp_buffer_hdr_t); - else if (buf_type == ODP_BUFFER_TYPE_PACKET) + } else if (buf_type == ODP_BUFFER_TYPE_PACKET) { hdr_size = sizeof(odp_packet_hdr_t); - else { + } else if (buf_type == ODP_BUFFER_TYPE_TIMEOUT) { + hdr_size = sizeof(odp_timeout_hdr_t); + } else if (buf_type == ODP_BUFFER_TYPE_ANY) { + hdr_size = sizeof(union buffer_type_any_u); + } else { ODP_ERR("odp_buffer_pool_create: Bad type %i\n", buf_type); exit(0); @@ -404,7 +425,7 @@ odp_buffer_t odp_buffer_alloc(odp_buffer_pool_t pool_id) if (chunk->chunk.num_bufs == 0) { /* give the chunk buffer */ local_chunk[pool_id] = NULL; - chunk->buf_hdr.type = pool->s.buf_type; + chunk->buf_hdr.cur_type = pool->s.buf_type; handle = chunk->buf_hdr.handle; } else { diff --git a/platform/linux-generic/source/odp_timer.c b/platform/linux-generic/source/odp_timer.c index 6fb5025..7c6c4f4 100644 --- a/platform/linux-generic/source/odp_timer.c +++ b/platform/linux-generic/source/odp_timer.c @@ -5,6 +5,8 @@ */ #include +#include +#include #include #include #include @@ -330,3 +332,14 @@ uint64_t odp_timer_current_tick(odp_timer_t timer) id = timer - 1; return odp_timer.timer[id].cur_tick; } + +odp_timeout_t odp_timeout_from_buffer(odp_buffer_t buf) +{ + return (odp_timeout_t) odp_buf_to_hdr(buf); +} + +uint64_t odp_timeout_tick(odp_timeout_t tmo) +{ + odp_timeout_hdr_t *tmo_hdr = tmo; + return tmo_hdr->tick; +} diff --git a/test/timer/odp_timer_test.c b/test/timer/odp_timer_test.c index 341265d..0af87b2 100644 --- a/test/timer/odp_timer_test.c +++ b/test/timer/odp_timer_test.c @@ -70,8 +70,17 @@ static void test_timeouts(int thr) ODP_DBG(" [%i] current tick %"PRIu64"\n", thr, tick); while (1) { + int type; + buf = odp_schedule_one(&queue, ODP_SCHED_WAIT); + type = odp_buffer_type(buf); + + if (type == ODP_BUFFER_TYPE_TIMEOUT) + ODP_DBG(" [%i] timeout\n", thr); + else + ODP_DBG(" [%i] message, type %i\n", thr, type); + /* TODO: read tick from tmo metadata */ tick = odp_timer_current_tick(test_timer); @@ -271,7 +280,7 @@ int main(int argc, char *argv[]) pool = odp_buffer_pool_create("msg_pool", pool_base, MSG_POOL_SIZE, sizeof(test_message_t), - ODP_CACHE_LINE_SIZE, ODP_BUFFER_TYPE_RAW); + ODP_CACHE_LINE_SIZE, ODP_BUFFER_TYPE_ANY); if (pool == ODP_BUFFER_POOL_INVALID) { ODP_ERR("Pool create failed.\n");