From patchwork Thu May 15 13:44:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 30260 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f197.google.com (mail-qc0-f197.google.com [209.85.216.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F251620446 for ; Thu, 15 May 2014 13:41:27 +0000 (UTC) Received: by mail-qc0-f197.google.com with SMTP id w7sf3723661qcr.8 for ; Thu, 15 May 2014 06:41:27 -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=FulPkJ7cR/hM70tP4e9/z0sQ+KNnRmhubQgtGtmfEN8=; b=cg1dnNKH9Gy2rq8Nsga8mRVDGVjWpIerXUwCf87v39mQvZoHuNXxjMaAzYSe4Yviey /bSDp2Ntv1/wjTidRch68xb68z5prVOvAbyKhYfkqB6vM1eBq95y1yU2f4At8pcufZbF /rgZlNKqS5o+TZjZ69bZBpvmZGP0JD8jnWZ6BFLoz/WnfMAOwigprwkkk4JKRxVRnqa0 y7zeaKRuWZQ5PD9JzyWaBhuFXI/Ue42GPZKUnaBXwiW7P6z1Oia5gCZBM76t06urkMLF aZAZZCJE3/5Gg7OtdJ2fVrrxfZB382P0O2UbXYPBHzHA3TMeoIJVJenllXmoU6dqLvdj mDLA== X-Gm-Message-State: ALoCoQlOCRKMxDZjxESRgyMT2fsqj9fPFvtd3cyi2bLWVw9/Jr5YXifgMXMMmGOc5iodiF9LWlg/ X-Received: by 10.236.93.38 with SMTP id k26mr4384548yhf.20.1400161287649; Thu, 15 May 2014 06:41:27 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.25.171 with SMTP id 40ls246035qgt.85.gmail; Thu, 15 May 2014 06:41:27 -0700 (PDT) X-Received: by 10.58.169.97 with SMTP id ad1mr528884vec.45.1400161287579; Thu, 15 May 2014 06:41:27 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id tx7si944299vcb.116.2014.05.15.06.41.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 15 May 2014 06:41:27 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id hr9so4416365vcb.3 for ; Thu, 15 May 2014 06:41:27 -0700 (PDT) X-Received: by 10.220.176.68 with SMTP id bd4mr325470vcb.70.1400161287450; Thu, 15 May 2014 06:41:27 -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 ib8csp323557vcb; Thu, 15 May 2014 06:41:27 -0700 (PDT) X-Received: by 10.140.83.209 with SMTP id j75mr14836086qgd.42.1400161286439; Thu, 15 May 2014 06:41:26 -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 t6si2548932qat.210.2014.05.15.06.41.25 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 15 May 2014 06:41:26 -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 1Wkvtf-0002SR-T3; Thu, 15 May 2014 13:40:31 +0000 Received: from mail-qc0-f171.google.com ([209.85.216.171]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WkvtZ-0002SM-M4 for lng-odp@lists.linaro.org; Thu, 15 May 2014 13:40:25 +0000 Received: by mail-qc0-f171.google.com with SMTP id x13so1769147qcv.16 for ; Thu, 15 May 2014 06:41:13 -0700 (PDT) X-Received: by 10.224.103.129 with SMTP id k1mr13282826qao.62.1400161273543; Thu, 15 May 2014 06:41:13 -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 5sm3177533qgi.45.2014.05.15.06.41.11 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 15 May 2014 06:41:12 -0700 (PDT) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Thu, 15 May 2014 16:44:55 +0300 Message-Id: <1400161495-8614-1-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 1.9.3 X-Topics: patch Subject: [lng-odp] [PATCH v2] 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=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 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 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 ++++++ 7 files changed, 130 insertions(+), 16 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 d79e76d..5bbb445 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; +}