From patchwork Tue Jan 10 15:59:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 90725 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp686609qgi; Tue, 10 Jan 2017 07:59:54 -0800 (PST) X-Received: by 10.55.95.1 with SMTP id t1mr3387152qkb.277.1484063994416; Tue, 10 Jan 2017 07:59:54 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id z125si1598133qke.262.2017.01.10.07.59.53; Tue, 10 Jan 2017 07:59:54 -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 sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id B582B60687; Tue, 10 Jan 2017 15:59:53 +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_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 6C4D160510; Tue, 10 Jan 2017 15:59:47 +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 532B060589; Tue, 10 Jan 2017 15:59:45 +0000 (UTC) Received: from mail-oi0-f52.google.com (mail-oi0-f52.google.com [209.85.218.52]) by lists.linaro.org (Postfix) with ESMTPS id 4FAD66050E for ; Tue, 10 Jan 2017 15:59:44 +0000 (UTC) Received: by mail-oi0-f52.google.com with SMTP id u143so143046095oif.3 for ; Tue, 10 Jan 2017 07:59:44 -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=bc+KwJzIJPfYyRmITmYn/vPk6v8Rfw45A7+9Ji3Q2n4=; b=l28Kf4TJti05i8D0SQW7pvHfOnDpCEArECstR7Q7J6Mfi5JMrqc36tTd9UGtOgkdmY arC3AWhzra55xDLa+UXdTZaPTYhhLQqVxIrbHFDB07A22N9nHvqUHaNkgMNcSKOtG+rW j9zW7UA3qxAqLGLSIm20y1a7PwdNX6Lf+OvQps1WW54l2UKXcV/kAGomi1XWwob8Sc1k KlsTSD+WIyRpKx1+zVZ1gBx3TY2I6PArmzRPi2L170qCs4iD3MbE0OIkW4cL/vPpX2Mb wfAOesiwxPVcU5E7HEQOiLVjDXi8q7H0Q/OLZkdyO2lq54WVcMrxSMjl2QStcwWwiacC RUEg== X-Gm-Message-State: AIkVDXI3H7N8PC5gBe8tP06NxODyZDgvI58AgpL19Ezn9gjjTephzMnorQGFH6MysMrMXIp4d64= X-Received: by 10.157.32.135 with SMTP id x7mr1735356ota.35.1484063983745; Tue, 10 Jan 2017 07:59:43 -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 96sm978134otc.40.2017.01.10.07.59.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Jan 2017 07:59:43 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Tue, 10 Jan 2017 09:59:40 -0600 Message-Id: <20170110155940.7780-1-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.9.3 Subject: [lng-odp] [API-NEXT PATCHv4] 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 --- Changes for v4: - Change ring name per Maxim's suggestion - Add lock/unlock calls around setting pool->reserved back to 0 per Petri Changes for v3: - Do not reference pool ring on buffer alloc/free if cache can satisfy request Changes for v2: - Reset reserved to 0 if ring allocation fails to recover properly platform/linux-generic/include/odp_pool_internal.h | 3 +- platform/linux-generic/odp_pool.c | 33 +++++++++++++++++----- 2 files changed, 28 insertions(+), 8 deletions(-) -- 2.9.3 Reviewed-by: Petri Savolainen 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 cae2759..932efe3 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,19 @@ static pool_t *reserve_pool(void) if (pool->reserved == 0) { pool->reserved = 1; UNLOCK(&pool->lock); + sprintf(ring_name, "pool_ring_%d", i); + pool->ring_shm = + odp_shm_reserve(ring_name, + sizeof(pool_ring_t), + ODP_CACHE_LINE_SIZE, 0); + if (odp_unlikely(pool->ring_shm == ODP_SHM_INVALID)) { + ODP_ERR("Unable to alloc pool ring %d\n", i); + LOCK(&pool->lock); + pool->reserved = 0; + UNLOCK(&pool->lock); + break; + } + pool->ring = odp_shm_addr(pool->ring_shm); return pool; } UNLOCK(&pool->lock); @@ -214,7 +228,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 +425,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; @@ -536,6 +550,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; @@ -592,8 +608,6 @@ 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; - mask = pool->ring_mask; cache = local.cache[pool->pool_idx]; cache_num = cache->num; @@ -620,6 +634,8 @@ int buffer_alloc_multi(pool_t *pool, odp_buffer_t buf[], * and not uint32_t. */ uint32_t data[burst]; + ring = &pool->ring->hdr; + mask = pool->ring_mask; burst = ring_deq_multi(ring, mask, data, burst); cache_num = burst - num_deq; @@ -671,12 +687,12 @@ 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; - mask = pool->ring_mask; /* Special case of a very large free. Move directly to * the global pool. */ if (odp_unlikely(num > CONFIG_POOL_CACHE_SIZE)) { + ring = &pool->ring->hdr; + mask = pool->ring_mask; for (i = 0; i < num; i++) ring_enq(ring, mask, (uint32_t)(uintptr_t)buf[i]); @@ -691,6 +707,9 @@ static inline void buffer_free_to_pool(uint32_t pool_id, uint32_t index; int burst = CACHE_BURST; + ring = &pool->ring->hdr; + mask = pool->ring_mask; + if (odp_unlikely(num > CACHE_BURST)) burst = num;