From patchwork Tue Jun 24 14:05:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 32425 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E114A201EF for ; Tue, 24 Jun 2014 14:01:19 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id n3sf497104wiv.8 for ; Tue, 24 Jun 2014 07:01:14 -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=a+rmAp8XwXh08hT8DX7TSC5YPpu6qn/4h/rBzh52gCw=; b=IfV858I2b9pQarzk4gbG9brGsUlrdT1IfWCumHpyR3gCjsfB1bugiHuk1tJSo3Abk9 rV10JbVQQ8rXYJbMhB2B08tUjIIw9WLn0WODOKfyCK9jMTvTFIH+row4FdpTro6IG0uP SVQSDQAqwNKBygAVlvERPswy8uJP7iicKJczEMxOPFvJ4QhLNtdjrc/X4UNpI7/wNfkL 9xMhs9LXDCFSpqo9Dn0IgAbbkQGMBP1XFDnirLEH7CTx0BscgdizoaaHflgUukZnpa0U jjqkOnd1lAcrAQxJpdwq8TvmH8Pf70BjN+z7MyvH/vxcpYIddQ+xzYATPqmsdzBFwXc8 FfXA== X-Gm-Message-State: ALoCoQmMJ/IZeGN1cFLKiCv0UN08eGP4+CChCT24qwAjeRcPpYgt6iCKv5oqxw443Jiut8ca7g9z X-Received: by 10.180.72.230 with SMTP id g6mr289798wiv.3.1403618474616; Tue, 24 Jun 2014 07:01:14 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.91.53 with SMTP id y50ls2250130qgd.8.gmail; Tue, 24 Jun 2014 07:01:14 -0700 (PDT) X-Received: by 10.220.190.197 with SMTP id dj5mr839768vcb.19.1403618474399; Tue, 24 Jun 2014 07:01:14 -0700 (PDT) Received: from mail-ve0-f181.google.com (mail-ve0-f181.google.com [209.85.128.181]) by mx.google.com with ESMTPS id fp5si236181vcb.75.2014.06.24.07.01.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 24 Jun 2014 07:01:14 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.181 as permitted sender) client-ip=209.85.128.181; Received: by mail-ve0-f181.google.com with SMTP id db11so355617veb.40 for ; Tue, 24 Jun 2014 07:01:14 -0700 (PDT) X-Received: by 10.52.101.168 with SMTP id fh8mr757241vdb.34.1403618474304; Tue, 24 Jun 2014 07:01:14 -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.221.37.5 with SMTP id tc5csp213133vcb; Tue, 24 Jun 2014 07:01:13 -0700 (PDT) X-Received: by 10.140.27.23 with SMTP id 23mr1870231qgw.94.1403618473830; Tue, 24 Jun 2014 07:01:13 -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 a7si456038qat.99.2014.06.24.07.01.13 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 24 Jun 2014 07:01:13 -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 1WzRFn-0007cA-TJ; Tue, 24 Jun 2014 13:59:19 +0000 Received: from mail-qc0-f182.google.com ([209.85.216.182]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WzRFi-0007bz-59 for lng-odp@lists.linaro.org; Tue, 24 Jun 2014 13:59:14 +0000 Received: by mail-qc0-f182.google.com with SMTP id m20so301279qcx.13 for ; Tue, 24 Jun 2014 07:01:02 -0700 (PDT) X-Received: by 10.140.47.16 with SMTP id l16mr1990203qga.24.1403618462050; Tue, 24 Jun 2014 07:01:02 -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 u7sm583726qat.2.2014.06.24.07.00.59 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 24 Jun 2014 07:01:00 -0700 (PDT) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Tue, 24 Jun 2014 17:05:46 +0300 Message-Id: <1403618747-28212-1-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.0.0 X-Topics: patch Subject: [lng-odp] [PATCH 1/2] 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.128.181 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 Added 'timeout' and 'any' buffer types. Timer and buffer pool modifications to use those. Signed-off-by: Petri Savolainen --- include/odp_buffer.h | 8 ++- include/odp_packet.h | 2 +- include/odp_timer.h | 31 +++++++-- .../linux-generic/include/odp_timer_internal.h | 78 ++++++++++++++++++++++ platform/linux-generic/source/odp_buffer_pool.c | 19 ++++++ platform/linux-generic/source/odp_timer.c | 29 ++++---- 6 files changed, 147 insertions(+), 20 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..b3d6f4a 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 type */ +#define ODP_BUFFER_TYPE_RAW 1 /**< Raw buffer, no additional 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_packet.h b/include/odp_packet.h index 932b009..59759bb 100644 --- a/include/odp_packet.h +++ b/include/odp_packet.h @@ -24,7 +24,7 @@ extern "C" { /** * ODP packet descriptor */ -typedef uint32_t odp_packet_t; +typedef odp_buffer_t odp_packet_t; /** Invalid packet */ #define ODP_PACKET_INVALID ODP_BUFFER_INVALID diff --git a/include/odp_timer.h b/include/odp_timer.h index 80babd1..01db839 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 odp_buffer_t 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_timer_internal.h b/platform/linux-generic/include/odp_timer_internal.h new file mode 100644 index 0000000..f99a10e --- /dev/null +++ b/platform/linux-generic/include/odp_timer_internal.h @@ -0,0 +1,78 @@ +/* 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 +#include +#include + +struct timeout_t; + +typedef struct timeout_t { + struct timeout_t *next; + int timer_id; + int tick; + uint64_t tmo_tick; + odp_queue_t queue; + odp_buffer_t buf; + odp_buffer_t tmo_buf; +} timeout_t; + + +struct odp_timeout_hdr_t; + +/** + * Timeout notification header + */ +typedef struct odp_timeout_hdr_t { + odp_buffer_hdr_t buf_hdr; + + timeout_t meta; + + 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); + + +/** + * Return timeout header + */ +static inline odp_timeout_hdr_t *odp_timeout_hdr(odp_timeout_t tmo) +{ + return (odp_timeout_hdr_t *)odp_buf_to_hdr((odp_buffer_t)tmo); +} + + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/source/odp_buffer_pool.c b/platform/linux-generic/source/odp_buffer_pool.c index 90214ba..f4aedff 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; @@ -214,6 +224,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); @@ -255,6 +270,10 @@ static void link_bufs(pool_entry_t *pool) hdr_size = sizeof(odp_buffer_hdr_t); else if (buf_type == ODP_BUFFER_TYPE_PACKET) hdr_size = sizeof(odp_packet_hdr_t); + 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); diff --git a/platform/linux-generic/source/odp_timer.c b/platform/linux-generic/source/odp_timer.c index 85369d3..509a890 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 @@ -20,17 +22,6 @@ #define MAX_TICKS 1024 #define RESOLUTION_NS 1000000 -struct timeout_t; - -typedef struct timeout_t { - struct timeout_t *next; - int timer_id; - int tick; - uint64_t tmo_tick; - odp_queue_t queue; - odp_buffer_t buf; - odp_buffer_t tmo_buf; -} timeout_t; typedef struct { odp_spinlock_t lock; @@ -250,6 +241,7 @@ odp_timer_tmo_t odp_timer_absolute_tmo(odp_timer_t timer, uint64_t tmo_tick, uint64_t cur_tick; timeout_t *new_tmo; odp_buffer_t tmo_buf; + odp_timeout_hdr_t *tmo_hdr; id = timer - 1; @@ -273,7 +265,8 @@ odp_timer_tmo_t odp_timer_absolute_tmo(odp_timer_t timer, uint64_t tmo_tick, return ODP_TIMER_TMO_INVALID; } - new_tmo = (timeout_t *)odp_buffer_addr(tmo_buf); + tmo_hdr = odp_timeout_hdr((odp_timeout_t) tmo_buf); + new_tmo = &tmo_hdr->meta; new_tmo->timer_id = id; new_tmo->tick = (int)tick; @@ -330,3 +323,15 @@ 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) buf; +} + +uint64_t odp_timeout_tick(odp_timeout_t tmo) +{ + odp_timeout_hdr_t *tmo_hdr; + tmo_hdr = (odp_timeout_hdr_t *)odp_buf_to_hdr((odp_buffer_t)tmo); + return tmo_hdr->meta.tick; +}