From patchwork Thu Nov 20 23:27:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 41263 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3ADF223C27 for ; Thu, 20 Nov 2014 23:27:34 +0000 (UTC) Received: by mail-la0-f69.google.com with SMTP id gd6sf2371216lab.8 for ; Thu, 20 Nov 2014 15:27:33 -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=VE/LhuuunJrMl641GjUOS4G1HnhFrQewSjmXOWn0310=; b=gP7f+VqdhKGO1SGWSY8EFIA/5s0qsS3hYXwm1h7nB5Zv6MjF/LgeDqSpRk7L5JQ0Ig quB7+wgXmLUeXMAZ6zIenN0cyHvmXjOVqpOqDdy/uG1QWlygTt3pRcxf1JHWLO0AyABX eo/4G6o3gc6a0M4EC0MdmCsESP7hlbwXSFVsJpF/wgx5dj1AsgtKeZ08pzZcWOR3kBdk 85uvFOG9ymTCG66jsnAYoydZSnJbWeeSxkvS4R7IVmfWTIBskLYk/xsMnEn0fIpaQ2nU LqN+0ryK6vnbjXBUHbtqsEf68XCxFzbrIAiO6XA31jY1RqMnFSLep0bMMMJbO6wpwjaE RB4A== X-Gm-Message-State: ALoCoQkm2LT0ow8UDClAlgo21la4DC5Sxb7eOwifFlhZRWjkkAx/26YiHJyiHZcyxN4qxrSskspz X-Received: by 10.195.17.134 with SMTP id ge6mr355087wjd.2.1416526053189; Thu, 20 Nov 2014 15:27:33 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.44.194 with SMTP id g2ls134575lam.3.gmail; Thu, 20 Nov 2014 15:27:32 -0800 (PST) X-Received: by 10.112.159.229 with SMTP id xf5mr913363lbb.64.1416526052838; Thu, 20 Nov 2014 15:27:32 -0800 (PST) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id jj7si3368461lbc.65.2014.11.20.15.27.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Nov 2014 15:27:32 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by mail-la0-f47.google.com with SMTP id hz20so3364720lab.34 for ; Thu, 20 Nov 2014 15:27:32 -0800 (PST) X-Received: by 10.152.6.228 with SMTP id e4mr817843laa.71.1416526052700; Thu, 20 Nov 2014 15:27:32 -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.184.201 with SMTP id ew9csp358234lbc; Thu, 20 Nov 2014 15:27:31 -0800 (PST) X-Received: by 10.52.170.176 with SMTP id an16mr1134729vdc.32.1416526051361; Thu, 20 Nov 2014 15:27:31 -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 bh5si1603905vcb.56.2014.11.20.15.27.30 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 20 Nov 2014 15:27:31 -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 1Xrb8L-0000yg-6o; Thu, 20 Nov 2014 23:27:29 +0000 Received: from mail-oi0-f44.google.com ([209.85.218.44]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xrb8A-0000yB-T5 for lng-odp@lists.linaro.org; Thu, 20 Nov 2014 23:27:18 +0000 Received: by mail-oi0-f44.google.com with SMTP id e131so2892158oig.3 for ; Thu, 20 Nov 2014 15:27:13 -0800 (PST) X-Received: by 10.202.57.2 with SMTP id g2mr862731oia.16.1416526033563; Thu, 20 Nov 2014 15:27:13 -0800 (PST) Received: from localhost.localdomain (cpe-24-28-70-239.austin.res.rr.com. [24.28.70.239]) by mx.google.com with ESMTPSA id e5sm1462015oic.16.2014.11.20.15.27.12 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Nov 2014 15:27:13 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Thu, 20 Nov 2014 17:27:03 -0600 Message-Id: <1416526024-26384-2-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1416526024-26384-1-git-send-email-bill.fischofer@linaro.org> References: <1416526024-26384-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 2/3] Changes for v1.0 buffer pool APIs 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: bill.fischofer@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.47 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 Signed-off-by: Bill Fischofer --- .../linux-generic/include/api/odp_platform_types.h | 9 ++ .../linux-generic/include/api/odp_shared_memory.h | 10 +-- .../include/odp_buffer_pool_internal.h | 8 ++ platform/linux-generic/odp_buffer_pool.c | 98 +++++++++++++++++++--- platform/linux-generic/odp_schedule.c | 20 ++--- 5 files changed, 111 insertions(+), 34 deletions(-) diff --git a/platform/linux-generic/include/api/odp_platform_types.h b/platform/linux-generic/include/api/odp_platform_types.h index 4db47d3..b9b3aea 100644 --- a/platform/linux-generic/include/api/odp_platform_types.h +++ b/platform/linux-generic/include/api/odp_platform_types.h @@ -65,6 +65,15 @@ typedef uint32_t odp_pktio_t; #define ODP_PKTIO_ANY ((odp_pktio_t)~0) /** + * ODP shared memory block + */ +typedef uint32_t odp_shm_t; + +/** Invalid shared memory block */ +#define ODP_SHM_INVALID 0 +#define ODP_SHM_NULL ODP_SHM_INVALID /**< Synonym for buffer pool use */ + +/** * @} */ diff --git a/platform/linux-generic/include/api/odp_shared_memory.h b/platform/linux-generic/include/api/odp_shared_memory.h index ff6f9a9..b681860 100644 --- a/platform/linux-generic/include/api/odp_shared_memory.h +++ b/platform/linux-generic/include/api/odp_shared_memory.h @@ -20,6 +20,7 @@ extern "C" { #include +#include /** @defgroup odp_shared_memory ODP SHARED MEMORY * Operations on shared memory. @@ -38,15 +39,6 @@ extern "C" { #define ODP_SHM_PROC 0x2 /**< Share with external processes */ /** - * ODP shared memory block - */ -typedef uint32_t odp_shm_t; - -/** Invalid shared memory block */ -#define ODP_SHM_INVALID 0 - - -/** * Shared memory block info */ typedef struct odp_shm_info_t { diff --git a/platform/linux-generic/include/odp_buffer_pool_internal.h b/platform/linux-generic/include/odp_buffer_pool_internal.h index e0210bd..a1c0990 100644 --- a/platform/linux-generic/include/odp_buffer_pool_internal.h +++ b/platform/linux-generic/include/odp_buffer_pool_internal.h @@ -56,6 +56,14 @@ struct pool_entry_s { size_t buf_size; size_t buf_offset; uint64_t num_bufs; + odp_shm_t pool_shm; + union { + uint32_t all; + struct { + uint32_t has_name:1; + uint32_t user_supplied_shm:1; + }; + } flags; void *pool_base_addr; uint64_t pool_size; size_t user_size; diff --git a/platform/linux-generic/odp_buffer_pool.c b/platform/linux-generic/odp_buffer_pool.c index a48d7d6..b2d5658 100644 --- a/platform/linux-generic/odp_buffer_pool.c +++ b/platform/linux-generic/odp_buffer_pool.c @@ -369,16 +369,19 @@ static void link_bufs(pool_entry_t *pool) } } - odp_buffer_pool_t odp_buffer_pool_create(const char *name, - void *base_addr, uint64_t size, - size_t buf_size, size_t buf_align, - int buf_type) + odp_shm_t shm, + odp_buffer_pool_param_t *params) { odp_buffer_pool_t pool_hdl = ODP_BUFFER_POOL_INVALID; pool_entry_t *pool; + void *base_addr; + size_t base_size; uint32_t i; + if (params == NULL) + return ODP_BUFFER_POOL_INVALID; + for (i = 0; i < ODP_CONFIG_BUFFER_POOLS; i++) { pool = get_pool_entry(i); @@ -386,15 +389,48 @@ odp_buffer_pool_t odp_buffer_pool_create(const char *name, if (pool->s.buf_base == 0) { /* found free pool */ + pool->s.flags.all = 0; + + if (name == NULL) { + pool->s.name[0] = 0; + } else { + strncpy(pool->s.name, name, + ODP_BUFFER_POOL_NAME_LEN - 1); + pool->s.name[ODP_BUFFER_POOL_NAME_LEN - 1] = 0; + pool->s.flags.has_name = 1; + } + + if (shm == ODP_SHM_NULL) { + base_size = + ODP_PAGE_SIZE_ROUNDUP( + params->buf_size * + params->num_bufs); + shm = odp_shm_reserve(pool->s.name, + base_size, + ODP_PAGE_SIZE, 0); + if (shm == ODP_SHM_INVALID) { + UNLOCK(&pool->s.lock); + return ODP_BUFFER_INVALID; + } + } else { + odp_shm_info_t info; + if (odp_shm_info(shm, &info) != 0) { + UNLOCK(&pool->s.lock); + return ODP_BUFFER_POOL_INVALID; + } + base_size = info.size; + pool->s.flags.user_supplied_shm = 1; + } + + pool->s.pool_shm = shm; + base_addr = odp_shm_addr(shm); - strncpy(pool->s.name, name, - ODP_BUFFER_POOL_NAME_LEN - 1); - pool->s.name[ODP_BUFFER_POOL_NAME_LEN - 1] = 0; pool->s.pool_base_addr = base_addr; - pool->s.pool_size = size; - pool->s.user_size = buf_size; - pool->s.user_align = buf_align; - pool->s.buf_type = buf_type; + pool->s.pool_size = base_size; + pool->s.user_size = params->buf_size; + pool->s.user_align = params->buf_align == 0 ? + ODP_CACHE_LINE_SIZE : params->buf_align; + pool->s.buf_type = params->buf_type; link_bufs(pool); @@ -431,6 +467,46 @@ odp_buffer_pool_t odp_buffer_pool_lookup(const char *name) return ODP_BUFFER_POOL_INVALID; } +int odp_buffer_pool_info(odp_buffer_pool_t pool_hdl, + odp_shm_t *shm, + odp_buffer_pool_info_t *info) +{ + uint32_t pool_id = pool_handle_to_index(pool_hdl); + pool_entry_t *pool = get_pool_entry(pool_id); + + if (pool == NULL || info == NULL) + return -1; + + *shm = pool->s.flags.user_supplied_shm ? + pool->s.pool_shm : ODP_SHM_NULL; + info->name = pool->s.name; + info->params.buf_size = pool->s.buf_size; + info->params.buf_align = pool->s.user_align; + info->params.num_bufs = pool->s.num_bufs; + info->params.buf_type = pool->s.buf_type; + + return 0; +} + +int odp_buffer_pool_destroy(odp_buffer_pool_t pool_hdl) +{ + uint32_t pool_id = pool_handle_to_index(pool_hdl); + pool_entry_t *pool = get_pool_entry(pool_id); + + if (pool == NULL) + return -1; + + LOCK(&pool->s.lock); + + if (!pool->s.flags.user_supplied_shm) + odp_shm_free(pool->s.pool_shm); + + pool->s.buf_base = 0; + UNLOCK(&pool->s.lock); + + return 0; +} + odp_buffer_t odp_buffer_alloc(odp_buffer_pool_t pool_hdl) { diff --git a/platform/linux-generic/odp_schedule.c b/platform/linux-generic/odp_schedule.c index 1bf819b..85e249f 100644 --- a/platform/linux-generic/odp_schedule.c +++ b/platform/linux-generic/odp_schedule.c @@ -83,8 +83,8 @@ int odp_schedule_init_global(void) { odp_shm_t shm; odp_buffer_pool_t pool; - void *pool_base; int i, j; + odp_buffer_pool_param_t params; ODP_DBG("Schedule init ... "); @@ -99,20 +99,12 @@ int odp_schedule_init_global(void) return -1; } - shm = odp_shm_reserve("odp_sched_pool", - SCHED_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); + params.buf_size = sizeof(queue_desc_t); + params.buf_align = ODP_CACHE_LINE_SIZE; + params.num_bufs = SCHED_POOL_SIZE/sizeof(queue_desc_t); + params.buf_type = ODP_BUFFER_TYPE_RAW; - pool_base = odp_shm_addr(shm); - - if (pool_base == NULL) { - ODP_ERR("Schedule init: Shm reserve failed.\n"); - return -1; - } - - pool = odp_buffer_pool_create("odp_sched_pool", pool_base, - SCHED_POOL_SIZE, sizeof(queue_desc_t), - ODP_CACHE_LINE_SIZE, - ODP_BUFFER_TYPE_RAW); + pool = odp_buffer_pool_create("odp_sched_pool", ODP_SHM_NULL, ¶ms); if (pool == ODP_BUFFER_POOL_INVALID) { ODP_ERR("Schedule init: Pool create failed.\n");