From patchwork Wed Dec 14 19:59:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 88067 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp385675qgi; Wed, 14 Dec 2016 12:05:13 -0800 (PST) X-Received: by 10.159.35.118 with SMTP id 109mr91091002uae.113.1481745913608; Wed, 14 Dec 2016 12:05:13 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id v19si16084325uav.9.2016.12.14.12.05.13; Wed, 14 Dec 2016 12:05:13 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 25DFB60909; Wed, 14 Dec 2016 20:05:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 2040F60C0A; Wed, 14 Dec 2016 20:01:08 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 1E8E860A38; Wed, 14 Dec 2016 20:01:05 +0000 (UTC) Received: from mail-oi0-f45.google.com (mail-oi0-f45.google.com [209.85.218.45]) by lists.linaro.org (Postfix) with ESMTPS id 2CF0860E18 for ; Wed, 14 Dec 2016 19:59:26 +0000 (UTC) Received: by mail-oi0-f45.google.com with SMTP id b126so31283267oia.2 for ; Wed, 14 Dec 2016 11:59:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Y9lgf8poIatP+dMKnok7WjGS6Xr7sgEBiWQCEqeZ/u4=; b=DEqkwHP9KudBN3UKRO9/XbG2igmkoPUR7xEID8omUfdIeO7A61aHZOBjqm8PCSqMBR 0C32fVKuojWIK2EtinRG3xynBw3zvrT54EBHTta7dhhlsxfbtYl7UQat048DGPU8M8Rx zDI0IYYNGPITSAB6niUY8srqB4VhFpIEFa+wRsdkmPm88v0Nft5zjWdHfR6J3184oI0b g6nyCj02nwep4yZcmARQuFTGYyiuvU+Ojv4upgjDKKnOvbk/NqSdttYRj/JCzVnclZ7L VHW9hmI64CIWK/6skvSwehi3/P0qNtldrGhOyS/dC2pEZxN9KxAk9XMVX6Ue92nOyOMM owCw== X-Gm-Message-State: AKaTC03iYbwLIFuUkrxZjR218Q9n9erjw54FEXm2N1+aYPr467WmZ/B35WWgT4ynLT3zv0LkXDY= X-Received: by 10.157.43.162 with SMTP id u31mr59424070ota.89.1481745565525; Wed, 14 Dec 2016 11:59:25 -0800 (PST) Received: from localhost.localdomain (cpe-70-121-83-241.austin.res.rr.com. [70.121.83.241]) by smtp.gmail.com with ESMTPSA id p47sm21278210otp.25.2016.12.14.11.59.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Dec 2016 11:59:25 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Wed, 14 Dec 2016 13:59:23 -0600 Message-Id: <1481745563-19827-1-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [lng-odp] [API-NEXT PATCH] linux-generic: pool: defer ring allocation until pool creation X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" To avoid excessive memory overhead for pools, defer the allocation of the pool ring until odp_pool_create() is called. This keeps pool memory overhead proportional to the number of pools actually in use rather than the architected maximum number of pools. This patch addresses Bug https://bugs.linaro.org/show_bug.cgi?id=2765 Signed-off-by: Bill Fischofer --- platform/linux-generic/include/odp_pool_internal.h | 3 ++- platform/linux-generic/odp_pool.c | 23 +++++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) -- 2.7.4 diff --git a/platform/linux-generic/include/odp_pool_internal.h b/platform/linux-generic/include/odp_pool_internal.h index 5d7b817..4915bda 100644 --- a/platform/linux-generic/include/odp_pool_internal.h +++ b/platform/linux-generic/include/odp_pool_internal.h @@ -69,7 +69,8 @@ typedef struct pool_t { pool_cache_t local_cache[ODP_THREAD_COUNT_MAX]; - pool_ring_t ring; + odp_shm_t ring_shm; + pool_ring_t *ring; } pool_t; diff --git a/platform/linux-generic/odp_pool.c b/platform/linux-generic/odp_pool.c index 4be3827..c1f479d 100644 --- a/platform/linux-generic/odp_pool.c +++ b/platform/linux-generic/odp_pool.c @@ -143,7 +143,7 @@ static void flush_cache(pool_cache_t *cache, pool_t *pool) uint32_t mask; uint32_t cache_num, i, data; - ring = &pool->ring.hdr; + ring = &pool->ring->hdr; mask = pool->ring_mask; cache_num = cache->num; @@ -172,6 +172,7 @@ static pool_t *reserve_pool(void) { int i; pool_t *pool; + char ring_name[ODP_POOL_NAME_LEN]; for (i = 0; i < ODP_CONFIG_POOLS; i++) { pool = pool_entry(i); @@ -180,6 +181,16 @@ static pool_t *reserve_pool(void) if (pool->reserved == 0) { pool->reserved = 1; UNLOCK(&pool->lock); + sprintf(ring_name, "_odp_pool_ring_%d", i); + pool->ring_shm = + odp_shm_reserve(ring_name, + sizeof(pool_ring_t), + ODP_CACHE_LINE_SIZE, 0); + if (pool->ring_shm == ODP_SHM_INVALID) { + ODP_ERR("Unable to alloc pool ring %d\n", i); + break; + } + pool->ring = odp_shm_addr(pool->ring_shm); return pool; } UNLOCK(&pool->lock); @@ -214,7 +225,7 @@ static void init_buffers(pool_t *pool) int type; uint32_t seg_size; - ring = &pool->ring.hdr; + ring = &pool->ring->hdr; mask = pool->ring_mask; type = pool->params.type; @@ -411,7 +422,7 @@ static odp_pool_t pool_create(const char *name, odp_pool_param_t *params, pool->uarea_base_addr = odp_shm_addr(pool->uarea_shm); } - ring_init(&pool->ring.hdr); + ring_init(&pool->ring->hdr); init_buffers(pool); return pool->pool_hdl; @@ -533,6 +544,8 @@ int odp_pool_destroy(odp_pool_t pool_hdl) odp_shm_free(pool->uarea_shm); pool->reserved = 0; + odp_shm_free(pool->ring_shm); + pool->ring = NULL; UNLOCK(&pool->lock); return 0; @@ -589,7 +602,7 @@ int buffer_alloc_multi(pool_t *pool, odp_buffer_t buf[], pool_cache_t *cache; uint32_t cache_num, num_ch, num_deq, burst; - ring = &pool->ring.hdr; + ring = &pool->ring->hdr; mask = pool->ring_mask; cache = local.cache[pool->pool_idx]; @@ -668,7 +681,7 @@ static inline void buffer_free_to_pool(uint32_t pool_id, cache = local.cache[pool_id]; pool = pool_entry(pool_id); - ring = &pool->ring.hdr; + ring = &pool->ring->hdr; mask = pool->ring_mask; /* Special case of a very large free. Move directly to