From patchwork Sat Nov 22 22:04:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 41373 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3417025AEA for ; Sat, 22 Nov 2014 22:04:44 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id b13sf4162128wgh.1 for ; Sat, 22 Nov 2014 14:04:43 -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=UM0RydoZXeVeFlcqJUAR6MS911MAkhAKTUCoMBpKNJ0=; b=ksANu8Rkx5jDSytUu/fgAJUTMCsVbK4tqKiPgyeDXO8TnovW602ucP3LNZ8fH8WmfN Bo0wtSWVSdHPhZJQ1VyneWBvsVSyi5FBT/weqUxj/H+aA+vLUnp01LkyMXyOiIntuurX e9RGXGdpHkqbMIwPnwujGCUBp59lDm4TJXWh8H8m8zPk2AZB8WuOHYQ6n2xxIlqY4Pi+ sT9bzG2ijl9kjz8XSP2R4LTpDuWBv91Po7PG9voT7lm5Jjy2MFEAs24SZmPmoKsCK2OU uO/pedNKosLJT0nLG6qvAwTBtWpZvlEe4ZB9m9WthHV/bU3MmBVinLWeT0dVueShUjXl /ZKg== X-Gm-Message-State: ALoCoQkDgNyfuGuSlSQqfDxyaSeAfTSq1h2d1nUhRHafUVu52bgp/qyv/o/B7JDWRvLrXJsizn54 X-Received: by 10.181.13.147 with SMTP id ey19mr1772206wid.2.1416693883537; Sat, 22 Nov 2014 14:04:43 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.26.98 with SMTP id k2ls300675lag.15.gmail; Sat, 22 Nov 2014 14:04:42 -0800 (PST) X-Received: by 10.152.5.6 with SMTP id o6mr12692798lao.8.1416693882724; Sat, 22 Nov 2014 14:04:42 -0800 (PST) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id h4si10296691lbd.53.2014.11.22.14.04.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 22 Nov 2014 14:04:42 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by mail-la0-f51.google.com with SMTP id mc6so5998681lab.10 for ; Sat, 22 Nov 2014 14:04:42 -0800 (PST) X-Received: by 10.152.43.79 with SMTP id u15mr8734742lal.29.1416693882530; Sat, 22 Nov 2014 14:04:42 -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 ew9csp65513lbc; Sat, 22 Nov 2014 14:04:41 -0800 (PST) X-Received: by 10.224.80.71 with SMTP id s7mr16758829qak.35.1416693881040; Sat, 22 Nov 2014 14:04:41 -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 f103si11327592qge.32.2014.11.22.14.04.40 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 22 Nov 2014 14:04:41 -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 1XsInG-0006DP-R5; Sat, 22 Nov 2014 22:04:38 +0000 Received: from mail-ob0-f170.google.com ([209.85.214.170]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XsIn7-0006Cj-Bw for lng-odp@lists.linaro.org; Sat, 22 Nov 2014 22:04:29 +0000 Received: by mail-ob0-f170.google.com with SMTP id wp18so5670038obc.1 for ; Sat, 22 Nov 2014 14:04:24 -0800 (PST) X-Received: by 10.202.75.81 with SMTP id y78mr6208997oia.80.1416693863967; Sat, 22 Nov 2014 14:04:23 -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 wk3sm3842495obc.3.2014.11.22.14.04.23 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 22 Nov 2014 14:04:23 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Sat, 22 Nov 2014 16:04:13 -0600 Message-Id: <1416693854-29711-2-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1416693854-29711-1-git-send-email-bill.fischofer@linaro.org> References: <1416693854-29711-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv3 2/3] Buffer pool API Part 2 of 3: changes for 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.51 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 --- Merge parts 1, 2, and 3 of this patch after review. .../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 26e208b..f70db5a 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 6a0a6b2..a599228 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");