From patchwork Sat Jan 14 15:40:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 91509 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp685873qgi; Sat, 14 Jan 2017 07:40:38 -0800 (PST) X-Received: by 10.55.126.67 with SMTP id z64mr8239758qkc.133.1484408438215; Sat, 14 Jan 2017 07:40:38 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id z4si10744100qkc.247.2017.01.14.07.40.37; Sat, 14 Jan 2017 07:40:38 -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 50621609A0; Sat, 14 Jan 2017 15:40:37 +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 DBC10608A3; Sat, 14 Jan 2017 15:40:30 +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 63848608A5; Sat, 14 Jan 2017 15:40:28 +0000 (UTC) Received: from mail-oi0-f42.google.com (mail-oi0-f42.google.com [209.85.218.42]) by lists.linaro.org (Postfix) with ESMTPS id 45823608A0 for ; Sat, 14 Jan 2017 15:40:27 +0000 (UTC) Received: by mail-oi0-f42.google.com with SMTP id m124so43125406oif.1 for ; Sat, 14 Jan 2017 07:40:27 -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=5aTt2d/PzXUuEQcpCPYEa/60VS1037RIsZyvqZY44dc=; b=JNtYiHRtk7VtOAreYGUPcV1ofAk9M3mNmhd5sQuDz6fvz3zAA4Z4LNzjWfoLdnkESD z4FsHkZ3k+UbIoCdHXB9Cv/UBZ6tn30kBoJwZ2giYNLU+k9O3wg35FS5xxpOvKJ0A0lP mNWSM4O1ApbYXmyXZmD7tsglarVTPq/tor3M5OEjs9aJo5ZQJz2FDT092hGnw9QlXAjV rEPEWAQl1oDwC6kNChkm9NUmHNvjuK9Z0208nBMZL40jJKZWWudsK1opNyq44WCMed9d MFsL1+aBWxr0mxIxrFE2xDblodY3QB8+uDb66GBwN1vULfcPj8bwTIDAfUP57lkH4FTq TUOw== X-Gm-Message-State: AIkVDXI/ST4XGJqLMgCpxhlTAxhXlIU1bZEDqBIrkJDNqCqxt7nvtUm1YAfwcT0cSCaAZl/Yhg0= X-Received: by 10.202.227.20 with SMTP id a20mr11681564oih.203.1484408426493; Sat, 14 Jan 2017 07:40:26 -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 r84sm7621975oie.24.2017.01.14.07.40.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 14 Jan 2017 07:40:25 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Sat, 14 Jan 2017 09:40:22 -0600 Message-Id: <20170114154022.8150-1-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.9.3 Subject: [lng-odp] [API-NEXT PATCHv2] linux-generic: packet: tune alloc/free performance for non-reference paths 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" As reported in Bug https://bugs.linaro.org/show_bug.cgi?id=2816 packet alloc/free performance for non-references appears significantly degraded after the introduction of packet reference support. Add fastpaths for non-reference packet frees to optimize this. Signed-off-by: Bill Fischofer --- Changes for v2: - Reworked odp_packet_free_multi() to streamline processing for reference and non-reference paths. platform/linux-generic/include/odp_pool_internal.h | 22 ++++- platform/linux-generic/odp_packet.c | 94 ++++++++++++++++++++-- platform/linux-generic/odp_pool.c | 62 ++++---------- 3 files changed, 123 insertions(+), 55 deletions(-) -- 2.9.3 diff --git a/platform/linux-generic/include/odp_pool_internal.h b/platform/linux-generic/include/odp_pool_internal.h index b0805ac..8fdc688 100644 --- a/platform/linux-generic/include/odp_pool_internal.h +++ b/platform/linux-generic/include/odp_pool_internal.h @@ -121,9 +121,29 @@ static inline odp_buffer_hdr_t *buf_hdl_to_hdr(odp_buffer_t buf) return pool_buf_hdl_to_hdr(pool, buf); } +static inline odp_pool_t pool_index_to_handle(uint32_t pool_idx) +{ + return _odp_cast_scalar(odp_pool_t, pool_idx); +} + +static inline uint32_t pool_id_from_buf(odp_buffer_t buf) +{ + odp_buffer_bits_t handle; + + handle.handle = buf; + return handle.pool_id; +} + int buffer_alloc_multi(pool_t *pool, odp_buffer_t buf[], odp_buffer_hdr_t *buf_hdr[], int num); -void buffer_free_multi(const odp_buffer_t buf[], int num_free); +void buffer_free_to_pool(uint32_t pool_id, const odp_buffer_t buf[], int num); + +static inline void buffer_free_multi(const odp_buffer_t buf[], int num_total) +{ + uint32_t pool_id = pool_id_from_buf(buf[0]); + + buffer_free_to_pool(pool_id, buf, num_total); +} #ifdef __cplusplus } diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 170965a..bc5a57c 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -30,7 +30,7 @@ static inline odp_packet_t packet_handle(odp_packet_hdr_t *pkt_hdr) static inline odp_buffer_t buffer_handle(odp_packet_hdr_t *pkt_hdr) { - return pkt_hdr->buf_hdr.handle.handle; + return odp_hdr_to_buf(&pkt_hdr->buf_hdr); } static inline uint32_t packet_ref_inc(odp_packet_hdr_t *pkt_hdr) @@ -599,18 +599,66 @@ int odp_packet_alloc_multi(odp_pool_t pool_hdl, uint32_t len, return num; } -static inline void packet_free(odp_packet_hdr_t *pkt_hdr) +static inline odp_packet_hdr_t *packet_free_to_list(odp_packet_hdr_t *pkt_hdr, + odp_buffer_t buf[], + int nbufs, + int *nfree) { odp_packet_hdr_t *ref_hdr; uint32_t ref_count; + int num_seg, i; do { + ref_count = packet_ref_count(pkt_hdr) - 1; + num_seg = pkt_hdr->buf_hdr.segcount; ref_hdr = pkt_hdr->ref_hdr; + + if (odp_likely((CONFIG_PACKET_MAX_SEGS == 1 || num_seg == 1) && + ref_count == 0)) { + if (*nfree >= nbufs) + break; + + buf[*nfree++] = buffer_handle(pkt_hdr); + } else { + if (*nfree + num_seg >= nbufs) + break; + + for (i = 0; i < num_seg; i++) { + odp_packet_hdr_t *hdr = + pkt_hdr->buf_hdr.seg[i].hdr; + + if (packet_ref_dec(hdr) == 1) + buf[*nfree++] = buffer_handle(hdr); + } + } + + pkt_hdr = ref_hdr; + } while (pkt_hdr); + + return pkt_hdr; +} + +static inline void packet_free(odp_packet_hdr_t *pkt_hdr) +{ + odp_packet_hdr_t *ref_hdr; + uint32_t ref_count; + int num_seg; + + do { ref_count = packet_ref_count(pkt_hdr) - 1; - free_bufs(pkt_hdr, 0, pkt_hdr->buf_hdr.segcount); + num_seg = pkt_hdr->buf_hdr.segcount; + ref_hdr = pkt_hdr->ref_hdr; - if (ref_count == 1) - pkt_hdr->unshared_len = pkt_hdr->frame_len; + if (odp_likely((CONFIG_PACKET_MAX_SEGS == 1 || num_seg == 1) && + ref_count == 0)) { + buffer_free_multi((odp_buffer_t *) + &pkt_hdr->buf_hdr.handle.handle, 1); + } else { + free_bufs(pkt_hdr, 0, num_seg); + + if (ref_count == 1) + pkt_hdr->unshared_len = pkt_hdr->frame_len; + } pkt_hdr = ref_hdr; } while (pkt_hdr); @@ -623,10 +671,40 @@ void odp_packet_free(odp_packet_t pkt) void odp_packet_free_multi(const odp_packet_t pkt[], int num) { - int i; + int nbufs = num * CONFIG_PACKET_MAX_SEGS * 2; + odp_buffer_t buf[nbufs]; + int nfree = 0; + int i = 0; + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt[0]); + uint32_t pool_id = pool_id_from_buf(pkt_hdr->buf_hdr.handle.handle); + uint32_t next_pool; + + while (1) { + pkt_hdr = packet_free_to_list(pkt_hdr, buf, nbufs, &nfree); - for (i = 0; i < num; i++) - packet_free(odp_packet_hdr(pkt[i])); + if (pkt_hdr) { + buffer_free_to_pool(pool_id, buf, nfree); + nfree = 0; + continue; + } + + if (++i == num) + break; + + pkt_hdr = odp_packet_hdr(pkt[i]); + next_pool = pool_id_from_buf(pkt_hdr->buf_hdr.handle.handle); + + if (odp_unlikely(next_pool != pool_id)) { + if (nfree > 0) { + buffer_free_to_pool(pool_id, buf, nfree); + nfree = 0; + } + pool_id = next_pool; + } + } + + if (nfree > 0) + buffer_free_to_pool(pool_id, buf, nfree); } int odp_packet_reset(odp_packet_t pkt, uint32_t len) diff --git a/platform/linux-generic/odp_pool.c b/platform/linux-generic/odp_pool.c index 090a55f..2648068 100644 --- a/platform/linux-generic/odp_pool.c +++ b/platform/linux-generic/odp_pool.c @@ -47,19 +47,6 @@ typedef struct pool_local_t { pool_table_t *pool_tbl; static __thread pool_local_t local; -static inline odp_pool_t pool_index_to_handle(uint32_t pool_idx) -{ - return _odp_cast_scalar(odp_pool_t, pool_idx); -} - -static inline uint32_t pool_id_from_buf(odp_buffer_t buf) -{ - odp_buffer_bits_t handle; - - handle.handle = buf; - return handle.pool_id; -} - int odp_pool_init_global(void) { uint32_t i; @@ -671,8 +658,8 @@ int buffer_alloc_multi(pool_t *pool, odp_buffer_t buf[], return num_ch + num_deq; } -static inline void buffer_free_to_pool(uint32_t pool_id, - const odp_buffer_t buf[], int num) +void buffer_free_to_pool(uint32_t pool_id, + const odp_buffer_t buf[], int num) { pool_t *pool; int i; @@ -732,36 +719,6 @@ static inline void buffer_free_to_pool(uint32_t pool_id, cache->num = cache_num + num; } -void buffer_free_multi(const odp_buffer_t buf[], int num_total) -{ - uint32_t pool_id; - int num; - int i; - int first = 0; - - while (1) { - num = 1; - i = 1; - pool_id = pool_id_from_buf(buf[first]); - - /* 'num' buffers are from the same pool */ - if (num_total > 1) { - for (i = first; i < num_total; i++) - if (pool_id != pool_id_from_buf(buf[i])) - break; - - num = i - first; - } - - buffer_free_to_pool(pool_id, &buf[first], num); - - if (i == num_total) - return; - - first = i; - } -} - odp_buffer_t odp_buffer_alloc(odp_pool_t pool_hdl) { odp_buffer_t buf; @@ -793,7 +750,20 @@ void odp_buffer_free(odp_buffer_t buf) void odp_buffer_free_multi(const odp_buffer_t buf[], int num) { - buffer_free_multi(buf, num); + uint32_t next_pool, pool_id = pool_id_from_buf(buf[0]); + int i, first = 0; + + for (i = 1; i < num; i++) { + next_pool = pool_id_from_buf(buf[i]); + + if (odp_unlikely(next_pool != pool_id)) { + buffer_free_to_pool(pool_id, &buf[first], i - first); + first = i; + pool_id = next_pool; + } + } + + buffer_free_to_pool(pool_id, &buf[first], num - first); } int odp_pool_capability(odp_pool_capability_t *capa)