From patchwork Thu Jul 20 17:59:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 108427 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2444688qge; Thu, 20 Jul 2017 11:02:18 -0700 (PDT) X-Received: by 10.55.16.6 with SMTP id a6mr5649153qkh.205.1500573738234; Thu, 20 Jul 2017 11:02:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500573738; cv=none; d=google.com; s=arc-20160816; b=AMBfW1I2gprVtj4YwQU8bUBmJKx4gUBZ3p0qvcUWlRB09Dj5vUue1EyE8UWU1PDkNB KJ46SSbpA3XfxAPMQ2AepH8Bl6haLN63LAibmaZ8nbInszzMd6FbKG8om6pgMElOB1C4 Mew0h+cp0K+5nrmrg32OOaEdKDX4xu3eK2GEEZC+1GkZRuiNCuvPn2K+Ihc1Gv8OJFeO ybf9C1xU9Jhg6abNPYNu6pIcJg25ZZz6hvkhR7I5UAibViBrE3i+Q1YMV6lw1zaRFX06 gehKaScyjpVnIGCwvvNSsq14EPqWrtvMMEppFqzvq1Kn871bUcJVct11mmvoPFh2Zhcl rADg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=kZnR3m+FOmG65e0uNJUBN8MdB/Pux3kMqyV8wBRMFH8=; b=LBULcoFe6EvHIAj75/gxqpx2illt5Y5wrylAkg1m9LKn5vUuUU2Sl+FtfAwf+0auvC xIpwmBEXJD7XAPBtP7bvbW0puLNK/ckgp4krJO2OUpuExnBh6B/MxWCSGcZiwXoe9pOa l1eB3ErIF1htDUV37iNkKhOURpMbgHKPICqZXukYN6sf6n2umpfla9aDaCnYHI+3HUb+ 6HdbGKfzJ7syzzMy5iEQC0Gai7ywtmljAaOsaCn7PG9DPB/nQgtXXDA80cpOsyoi1gKh LulYXq1mAD4ei+F8qROm/ER9g5QxqTc1DfprvtGv/U3Mt2UHfXtOLhINwyyXYicCoCcN nriw== ARC-Authentication-Results: i=1; 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id g32si428568qtd.209.2017.07.20.11.02.17; Thu, 20 Jul 2017 11:02:18 -0700 (PDT) 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id CF8DD635F8; Thu, 20 Jul 2017 18:02:17 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 F3E5C607CD; Thu, 20 Jul 2017 18:00:31 +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 8FAD26358D; Thu, 20 Jul 2017 18:00:21 +0000 (UTC) Received: from forward4j.cmail.yandex.net (forward4j.cmail.yandex.net [5.255.227.22]) by lists.linaro.org (Postfix) with ESMTPS id 4EE3660CB2 for ; Thu, 20 Jul 2017 18:00:14 +0000 (UTC) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [IPv6:2a02:6b8:0:1402::15:6]) by forward4j.cmail.yandex.net (Yandex) with ESMTP id 8E3852049A for ; Thu, 20 Jul 2017 21:00:11 +0300 (MSK) Received: from smtp4p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp4p.mail.yandex.net (Yandex) with ESMTP id 63CC36501184 for ; Thu, 20 Jul 2017 21:00:10 +0300 (MSK) Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id a46hdQ3693-0AaSFnKD; Thu, 20 Jul 2017 21:00:10 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 20 Jul 2017 20:59:58 +0300 Message-Id: <1500573607-18783-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> References: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 82 Subject: [lng-odp] [PATCH v3 1/10] linux-generic: packet: restructure inline routines to use macros 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" From: Bill Fischofer Use an internal macro for accessing inline fields in preparation for introducing packet reference support. Signed-off-by: Bill Fischofer --- /** Email created from pull request 82 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/82 ** Patch: https://github.com/Linaro/odp/pull/82.patch ** Base sha: 95ba4b394009d92c29c2e22f0776e90bb4c6edec ** Merge commit sha: 01d093d362af5a52e079c622a99ae3495f68b64c **/ .../include/odp/api/plat/packet_flag_inlines.h | 7 +++- .../include/odp/api/plat/packet_inlines.h | 44 +++++++++------------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/platform/linux-generic/include/odp/api/plat/packet_flag_inlines.h b/platform/linux-generic/include/odp/api/plat/packet_flag_inlines.h index 2de04c81..738fced3 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_flag_inlines.h +++ b/platform/linux-generic/include/odp/api/plat/packet_flag_inlines.h @@ -16,14 +16,17 @@ #include #include +/** @internal Packet field accessor */ +#define _odp_pkt_get(pkt, cast, field) \ + (*(cast *)(uintptr_t)((uint8_t *)pkt + _odp_packet_inline.field)) + /** @internal Inline function offsets */ extern const _odp_packet_inline_offset_t _odp_packet_inline; /** @internal Inline function @param pkt @return */ static inline uint64_t _odp_packet_input_flags(odp_packet_t pkt) { - return *(uint64_t *)(uintptr_t)((uint8_t *)pkt + - _odp_packet_inline.input_flags); + return _odp_pkt_get(pkt, uint64_t, input_flags); } /** @internal Inline function @param pkt @return */ diff --git a/platform/linux-generic/include/odp/api/plat/packet_inlines.h b/platform/linux-generic/include/odp/api/plat/packet_inlines.h index 3dd643fe..14cc86c8 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_inlines.h +++ b/platform/linux-generic/include/odp/api/plat/packet_inlines.h @@ -18,6 +18,10 @@ #include #include +/** @internal Packet field accessor */ +#define _odp_pkt_get(pkt, cast, field) \ + (*(cast *)(uintptr_t)((uint8_t *)pkt + _odp_packet_inline.field)) + /** @internal Inline function offsets */ extern const _odp_packet_inline_offset_t _odp_packet_inline; @@ -38,91 +42,79 @@ static inline odp_packet_seg_t _odp_packet_seg_from_ndx(uint32_t ndx) /** @internal Inline function @param pkt @return */ static inline void *_odp_packet_data(odp_packet_t pkt) { - return *(void **)(uintptr_t)((uint8_t *)pkt + _odp_packet_inline.data); + return _odp_pkt_get(pkt, void *, data); } /** @internal Inline function @param pkt @return */ static inline uint32_t _odp_packet_seg_len(odp_packet_t pkt) { - return *(uint32_t *)(uintptr_t)((uint8_t *)pkt + - _odp_packet_inline.seg_len); + return _odp_pkt_get(pkt, uint32_t, seg_len); } /** @internal Inline function @param pkt @return */ static inline uint32_t _odp_packet_len(odp_packet_t pkt) { - return *(uint32_t *)(uintptr_t)((uint8_t *)pkt + - _odp_packet_inline.frame_len); + return _odp_pkt_get(pkt, uint32_t, frame_len); } /** @internal Inline function @param pkt @return */ static inline uint32_t _odp_packet_headroom(odp_packet_t pkt) { - return *(uint32_t *)(uintptr_t)((uint8_t *)pkt + - _odp_packet_inline.headroom); + return _odp_pkt_get(pkt, uint32_t, headroom); } /** @internal Inline function @param pkt @return */ static inline uint32_t _odp_packet_tailroom(odp_packet_t pkt) { - return *(uint32_t *)(uintptr_t)((uint8_t *)pkt + - _odp_packet_inline.tailroom); + return _odp_pkt_get(pkt, uint32_t, tailroom); } /** @internal Inline function @param pkt @return */ static inline odp_pool_t _odp_packet_pool(odp_packet_t pkt) { - return *(odp_pool_t *)(uintptr_t)((uint8_t *)pkt + - _odp_packet_inline.pool); + return _odp_pkt_get(pkt, odp_pool_t, pool); } /** @internal Inline function @param pkt @return */ static inline odp_pktio_t _odp_packet_input(odp_packet_t pkt) { - return *(odp_pktio_t *)(uintptr_t)((uint8_t *)pkt + - _odp_packet_inline.input); + return _odp_pkt_get(pkt, odp_pktio_t, input); } /** @internal Inline function @param pkt @return */ static inline int _odp_packet_num_segs(odp_packet_t pkt) { - return *(uint8_t *)(uintptr_t)((uint8_t *)pkt + - _odp_packet_inline.segcount); + return _odp_pkt_get(pkt, uint8_t, segcount); } /** @internal Inline function @param pkt @return */ static inline void *_odp_packet_user_ptr(odp_packet_t pkt) { - return *(void **)(uintptr_t)((uint8_t *)pkt + - _odp_packet_inline.user_ptr); + return _odp_pkt_get(pkt, void *, user_ptr); } /** @internal Inline function @param pkt @return */ static inline void *_odp_packet_user_area(odp_packet_t pkt) { - return *(void **)(uintptr_t)((uint8_t *)pkt + - _odp_packet_inline.user_area); + return _odp_pkt_get(pkt, void *, user_area); } /** @internal Inline function @param pkt @return */ static inline uint32_t _odp_packet_user_area_size(odp_packet_t pkt) { - return *(uint32_t *)(uintptr_t)((uint8_t *)pkt + - _odp_packet_inline.user_area_size); + return _odp_pkt_get(pkt, uint32_t, user_area_size); } /** @internal Inline function @param pkt @return */ static inline uint32_t _odp_packet_flow_hash(odp_packet_t pkt) { - return *(uint32_t *)(uintptr_t)((uint8_t *)pkt + - _odp_packet_inline.flow_hash); + return _odp_pkt_get(pkt, uint32_t, flow_hash); } /** @internal Inline function @param pkt @return */ static inline odp_time_t _odp_packet_ts(odp_packet_t pkt) { - return *(odp_time_t *)(uintptr_t)((uint8_t *)pkt + - _odp_packet_inline.timestamp); + return _odp_pkt_get(pkt, odp_time_t, timestamp); } /** @internal Inline function @param pkt @return */ @@ -134,7 +126,7 @@ static inline void *_odp_packet_head(odp_packet_t pkt) /** @internal Inline function @param pkt @return */ static inline int _odp_packet_is_segmented(odp_packet_t pkt) { - return _odp_packet_num_segs(pkt) > 1; + return _odp_pkt_get(pkt, uint8_t, segcount) > 1; } /** @internal Inline function @param pkt @return */ From patchwork Thu Jul 20 17:59:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 108425 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2443427qge; Thu, 20 Jul 2017 11:01:09 -0700 (PDT) X-Received: by 10.233.216.1 with SMTP id u1mr5561747qkf.10.1500573669342; Thu, 20 Jul 2017 11:01:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500573669; cv=none; d=google.com; s=arc-20160816; b=IRn1Qbnhn2/7QT78mTfzzitLMOBvnsLM3PglQ2/la+9WcgbvoLvZnNI3rFKAkiE4Dm 0qoe6YLxlxlO0EE80M2eXFVNBuk+gVJWkyMnCtzoKzNKGDQeP5mqs03fhU9bYS6SSg9r tDn90r6rk2aaX774VLsyHfbDrdew8db1L2EPfzEx5CUxVhL8LIzXvEN+t+rLQ70sEv1Q xEs4GfBI5xKwHSSC6ZdPnj5dgtdPpOWehcr+8smjC1/hRd+zdHNxkAvrYFemTERdGI5T zGL+RYBpY2PD8sSoYZAkZG/iS0+Ih9uUAn8OpLsrLT2a24TeDXodNXVYC2gyJfW+qe3f Xkbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=zruOFqf3+t2xWHUGD27vYxS+aoQ0UIso+53Fmt4g02A=; b=EWNzvE3hXkfLX7FBeQBuZoxz09b/dlHaKGuddCyNbWlW7iDiGMJQcGOHDJF8AWmyqC 14JTp3+jIpdVECcqyk0Mimr5Wwpz2AZMqwHo+MhM/y6UrtBnaGKsLv90Vpe8L+uemdcd fcaUOuF38Qrx7gT7xmN2MWzXdhaLMygE72ssKkHbN07ohJmAjryZILXFB52Geo2HAGO+ v52QEkVRBVatl1xd/69l8FmE9FjAN7xsk0qzIt3MxUPplPwSKTNzWsRyV3kDuExL9Lqd 1dLl2CBaVQ3/G1JY/mB3BWhWMMwZS5dXDoU7B2GKTYW/wHMnzK7JIQKiwCMqgBMpDnLe d+Bg== ARC-Authentication-Results: i=1; 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id n63si2309138qkd.293.2017.07.20.11.01.09; Thu, 20 Jul 2017 11:01:09 -0700 (PDT) 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 02158644FC; Thu, 20 Jul 2017 18:01:08 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 5285162D06; Thu, 20 Jul 2017 18:00:24 +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 B0A2B60CE0; Thu, 20 Jul 2017 18:00:15 +0000 (UTC) Received: from forward4j.cmail.yandex.net (forward4j.cmail.yandex.net [5.255.227.22]) by lists.linaro.org (Postfix) with ESMTPS id 4AF6960C5D for ; Thu, 20 Jul 2017 18:00:14 +0000 (UTC) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [IPv6:2a02:6b8:0:1402::15:6]) by forward4j.cmail.yandex.net (Yandex) with ESMTP id E21A420754 for ; Thu, 20 Jul 2017 21:00:12 +0300 (MSK) Received: from smtp4p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp4p.mail.yandex.net (Yandex) with ESMTP id ACF716501192 for ; Thu, 20 Jul 2017 21:00:11 +0300 (MSK) Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id a46hdQ3693-0BaqD1Lr; Thu, 20 Jul 2017 21:00:11 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 20 Jul 2017 20:59:59 +0300 Message-Id: <1500573607-18783-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> References: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 82 Subject: [lng-odp] [PATCH v3 2/10] linux-generic: packet: add packet fields needed for references 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" From: Bill Fischofer Add new fields to the odp_packet_hdr_t used for support of zero-copy references. Also added are the offsets needed to access them from inlined functions. Signed-off-by: Bill Fischofer --- /** Email created from pull request 82 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/82 ** Patch: https://github.com/Linaro/odp/pull/82.patch ** Base sha: 95ba4b394009d92c29c2e22f0776e90bb4c6edec ** Merge commit sha: 01d093d362af5a52e079c622a99ae3495f68b64c **/ platform/linux-generic/include/odp/api/plat/packet_types.h | 8 ++++++++ platform/linux-generic/include/odp_packet_internal.h | 9 ++++++++- platform/linux-generic/odp_packet.c | 4 ++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/platform/linux-generic/include/odp/api/plat/packet_types.h b/platform/linux-generic/include/odp/api/plat/packet_types.h index a209c759..dd0d94b7 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_types.h +++ b/platform/linux-generic/include/odp/api/plat/packet_types.h @@ -80,6 +80,14 @@ typedef struct _odp_packet_inline_offset_t { /** @internal field offset */ size_t tailroom; /** @internal field offset */ + size_t unshared_len; + /** @internal field offset */ + size_t ref_hdr; + /** @internal field offset */ + size_t ref_offset; + /** *internal field offset */ + size_t ref_len; + /** @internal field offset */ size_t pool; /** @internal field offset */ size_t input; diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index f77987c8..9c013d8f 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -106,7 +106,7 @@ typedef struct { * packet_init(). Because of this any new fields added must be reviewed for * initialization requirements. */ -typedef struct { +typedef struct odp_packet_hdr_t { /* common buffer header */ odp_buffer_hdr_t buf_hdr; @@ -122,6 +122,13 @@ typedef struct { uint32_t headroom; uint32_t tailroom; + /* Fields used to support packet references */ + uint32_t unshared_len; + struct odp_packet_hdr_t *ref_hdr; + uint32_t ref_offset; + uint32_t ref_len; + odp_atomic_u32_t ref_count; + /* * Members below are not initialized by packet_init() */ diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index dbde7280..af8c442e 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -33,6 +33,10 @@ const _odp_packet_inline_offset_t _odp_packet_inline ODP_ALIGNED_CACHE = { .frame_len = offsetof(odp_packet_hdr_t, frame_len), .headroom = offsetof(odp_packet_hdr_t, headroom), .tailroom = offsetof(odp_packet_hdr_t, tailroom), + .unshared_len = offsetof(odp_packet_hdr_t, unshared_len), + .ref_hdr = offsetof(odp_packet_hdr_t, ref_hdr), + .ref_offset = offsetof(odp_packet_hdr_t, ref_offset), + .ref_len = offsetof(odp_packet_hdr_t, ref_len), .pool = offsetof(odp_packet_hdr_t, buf_hdr.pool_hdl), .input = offsetof(odp_packet_hdr_t, input), .segcount = offsetof(odp_packet_hdr_t, buf_hdr.segcount), From patchwork Thu Jul 20 18:00:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 108426 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2444123qge; Thu, 20 Jul 2017 11:01:44 -0700 (PDT) X-Received: by 10.200.3.171 with SMTP id t43mr5983434qtg.232.1500573704670; Thu, 20 Jul 2017 11:01:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500573704; cv=none; d=google.com; s=arc-20160816; b=rB60qfHVfiswh270GuiD8U+iDnRhIGAnRGma5LqpJXL/VLRcz9rA3GpUAyEpEN2BX/ vV55eRJn1qWyf3ZhSU2W5WAjo9HoOP2mQxajKl81VkrTjX6mslB0dQEpVCrofsPq9vg0 IR+IZ7mJWhsfxZr101556/2jT3oOFc9G8xhdXxqAGPLAzXyV2PzOHTawAdXqZeHhvu2D zZkLXL7li+w4De5f+fUUk6GYqW4KJvpFu3oMO+meuNxTmKNqumJAEKhdo3NrfFZgH3EP BOgCVrwfKI2P4xkqZ/lPU/Uu0PxwQBMeaTphNBgVdI/CNOXrXziPRhLAruBdSNjFqGJm nuEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=M3CGPFwfD1bevmb10baqwWWcdECMPCZTLbfjfRpX3qA=; b=uNJe3miUG+8ampIihQJ83JSglRIQfkQaCIgdkWFM90Ve/6znGSyvPV8MgLRM/BYn5V jdJ/IewrlGJzM/32aDhwKPuMIhBPelkipy8fHoMqB7kf9l4xbBgKYJ4ogVKY5zb+AZNl LuWhTVVyxIAWVKCGMLCZSGG0p8fd7kjGisx+ZvYTEVYtYyHmy90voH8HPmumVLKh7Nmx +Gd0BcyLwA67bw+pYdrutHXqK1sTIiXlSJwTlW1JO4Y4qc2CgPrIxdSnOiF0g1euVkbD WfDC6OxFyLDIK20xv61VwgikSK16qBQpiUwO8n8P8dPnyjABWxwRwG/q5unDsiChlC1d AMbQ== ARC-Authentication-Results: i=1; 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id d189si2362595qkc.170.2017.07.20.11.01.44; Thu, 20 Jul 2017 11:01:44 -0700 (PDT) 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 4139A646DE; Thu, 20 Jul 2017 18:01:44 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 A803F635F8; Thu, 20 Jul 2017 18:00:26 +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 22F8E60CEE; Thu, 20 Jul 2017 18:00:19 +0000 (UTC) Received: from forward3j.cmail.yandex.net (forward3j.cmail.yandex.net [5.255.227.21]) by lists.linaro.org (Postfix) with ESMTPS id B668360C47 for ; Thu, 20 Jul 2017 18:00:15 +0000 (UTC) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [95.108.252.166]) by forward3j.cmail.yandex.net (Yandex) with ESMTP id 26A652071A for ; Thu, 20 Jul 2017 21:00:14 +0300 (MSK) Received: from smtp4p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp4p.mail.yandex.net (Yandex) with ESMTP id D846065011AE for ; Thu, 20 Jul 2017 21:00:13 +0300 (MSK) Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id a46hdQ3693-0CamRQNj; Thu, 20 Jul 2017 21:00:12 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 20 Jul 2017 21:00:00 +0300 Message-Id: <1500573607-18783-4-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> References: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 82 Subject: [lng-odp] [PATCH v3 3/10] linux-generic: packet: add routines for manipulating reference counts 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" From: Bill Fischofer Signed-off-by: Bill Fischofer --- /** Email created from pull request 82 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/82 ** Patch: https://github.com/Linaro/odp/pull/82.patch ** Base sha: 95ba4b394009d92c29c2e22f0776e90bb4c6edec ** Merge commit sha: 01d093d362af5a52e079c622a99ae3495f68b64c **/ platform/linux-generic/include/odp_packet_internal.h | 19 +++++++++++++++++++ platform/linux-generic/odp_packet.c | 10 ++++++++++ 2 files changed, 29 insertions(+) diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index 9c013d8f..396d8cb5 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -248,6 +248,25 @@ static inline uint32_t packet_len(odp_packet_hdr_t *pkt_hdr) return pkt_hdr->frame_len; } +static inline uint32_t packet_ref_count(odp_packet_hdr_t *pkt_hdr) +{ + /* Breach the atomic type to do a peek at the ref count. This + * is used to bypass atomic operations if ref_count == 1 for + * performance reasons. + */ + return pkt_hdr->ref_count.v; +} + +static inline void packet_ref_count_set(odp_packet_hdr_t *pkt_hdr, uint32_t n) +{ + /* Only used during init when there are no other possible + * references to this pkt, so avoid the "atomic" overhead by + * a controlled breach of the atomic type here. This saves + * over 10% of the pathlength in routines like packet_alloc(). + */ + pkt_hdr->ref_count.v = n; +} + static inline void packet_set_len(odp_packet_hdr_t *pkt_hdr, uint32_t len) { pkt_hdr->frame_len = len; diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index af8c442e..38879a7f 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -61,6 +61,16 @@ static inline odp_buffer_t buffer_handle(odp_packet_hdr_t *pkt_hdr) return (odp_buffer_t)pkt_hdr; } +static inline uint32_t packet_ref_inc(odp_packet_hdr_t *pkt_hdr) +{ + return odp_atomic_fetch_inc_u32(&pkt_hdr->ref_count); +} + +static inline uint32_t packet_ref_dec(odp_packet_hdr_t *pkt_hdr) +{ + return odp_atomic_fetch_dec_u32(&pkt_hdr->ref_count); +} + static inline odp_packet_hdr_t *buf_to_packet_hdr(odp_buffer_t buf) { return (odp_packet_hdr_t *)buf_hdl_to_hdr(buf); From patchwork Thu Jul 20 18:00:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 108428 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2445667qge; Thu, 20 Jul 2017 11:03:07 -0700 (PDT) X-Received: by 10.55.19.29 with SMTP id d29mr6123375qkh.296.1500573787695; Thu, 20 Jul 2017 11:03:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500573787; cv=none; d=google.com; s=arc-20160816; b=ABg8jTIflM4YP6xYB5FkvhJV8BAXG4TqImV4ipeWzOfEn8bX97saiqvMvdAjpzmjLn JfYNgl+7XU84Tfs468z5fCeCOjzlx68spCS0WBGuWcTBws6usC4ns34tag0UUjVvJw11 fUWHyT3yEcKxRjf/SqKTr6OMJgXNn4bCYAiwDuO/3ydD1Ae9wAkCfg7WLHy+p2gyB+8+ YzTZsBdCNxi2m4E9RmCbOBCI9cOmIhioHflppdhpWsGgDos98Z4MALlMzbyV63vG/Ef+ ExWkGRc/MPLyuC01Nf7K7tMgEB7z1fSe8LClZTWP3OntQCb31S4r+srxpUyxZXarMllb +q2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=VkFFlEpDGeg2kH0SikVeVdZNnPeHWds/uO9DJTodVhc=; b=sT32SxG03C7mKDDz513PD7m2MtowQrP5RavRN9Gib1bDgRll1yYMSBFXXxKDd+JQwJ XuGWjnjKXx1s60j2C0/pPgsWorQ0PfcmWmdb2x8Hdu0A3lF3GpYp4bx7wz52ohZw/obP FwjRO18Fx1HBTOo4MzSZlD/duEJl2y7iU7N+I02u//0cQ3Knl6B8gBQtysXrC15DiOgi bdqeV94jqOZYoSJCwswul+QUHSo2TN8cesC6NlvQOeqSjj5pJWxv6gsCDj5LGHTbcxPG EWRLT8/svGktjHH8Xo/As6wkv2ol9PUMl3xUdf7A4EQg0F89HD/tRSYCzDToOW9a8q0s bUlg== ARC-Authentication-Results: i=1; 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id o62si2338760qka.244.2017.07.20.11.03.07; Thu, 20 Jul 2017 11:03:07 -0700 (PDT) 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 5CB02636AA; Thu, 20 Jul 2017 18:03:07 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 56D7860804; Thu, 20 Jul 2017 18:00:35 +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 4A71F63505; Thu, 20 Jul 2017 18:00:22 +0000 (UTC) Received: from forward3o.cmail.yandex.net (forward3o.cmail.yandex.net [37.9.109.247]) by lists.linaro.org (Postfix) with ESMTPS id D5D8760CE0 for ; Thu, 20 Jul 2017 18:00:16 +0000 (UTC) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [95.108.252.166]) by forward3o.cmail.yandex.net (Yandex) with ESMTP id 62F63203BD for ; Thu, 20 Jul 2017 21:00:15 +0300 (MSK) Received: from smtp4p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp4p.mail.yandex.net (Yandex) with ESMTP id 1C6C66500E80 for ; Thu, 20 Jul 2017 21:00:14 +0300 (MSK) Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id a46hdQ3693-0EaGqxxJ; Thu, 20 Jul 2017 21:00:14 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 20 Jul 2017 21:00:01 +0300 Message-Id: <1500573607-18783-5-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> References: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 82 Subject: [lng-odp] [PATCH v3 4/10] linux-generic: packet: add initializations for new hdr fields 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" From: Bill Fischofer Add initializations for new packet hdr fields needed to support packet references. Signed-off-by: Bill Fischofer --- /** Email created from pull request 82 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/82 ** Patch: https://github.com/Linaro/odp/pull/82.patch ** Base sha: 95ba4b394009d92c29c2e22f0776e90bb4c6edec ** Merge commit sha: 01d093d362af5a52e079c622a99ae3495f68b64c **/ platform/linux-generic/include/odp_packet_internal.h | 4 ++++ platform/linux-generic/odp_packet.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index 396d8cb5..e5887c9b 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -216,6 +216,10 @@ static inline void packet_init(odp_packet_hdr_t *pkt_hdr, uint32_t len) CONFIG_PACKET_TAILROOM; pkt_hdr->input = ODP_PKTIO_INVALID; + + /* By default packet has no references */ + pkt_hdr->unshared_len = len; + pkt_hdr->ref_hdr = NULL; } static inline void copy_packet_parser_metadata(odp_packet_hdr_t *src_hdr, diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 38879a7f..8806be8a 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -253,6 +253,9 @@ void packet_parse_reset(odp_packet_hdr_t *pkt_hdr) pkt_hdr->p.l2_offset = 0; pkt_hdr->p.l3_offset = ODP_PACKET_OFFSET_INVALID; pkt_hdr->p.l4_offset = ODP_PACKET_OFFSET_INVALID; + + /* Ensure dummy pkt hdrs used in I/O recv classification are valid */ + pkt_hdr->ref_hdr = NULL; } static inline void init_segments(odp_packet_hdr_t *pkt_hdr[], int num) @@ -265,6 +268,7 @@ static inline void init_segments(odp_packet_hdr_t *pkt_hdr[], int num) hdr->buf_hdr.seg[0].data = hdr->buf_hdr.base_data; hdr->buf_hdr.seg[0].len = BASE_LEN; + packet_ref_count_set(hdr, 1); /* Link segments */ if (CONFIG_PACKET_MAX_SEGS != 1) { @@ -274,6 +278,7 @@ static inline void init_segments(odp_packet_hdr_t *pkt_hdr[], int num) for (i = 1; i < num; i++) { odp_buffer_hdr_t *buf_hdr; + packet_ref_count_set(pkt_hdr[i], 1); buf_hdr = &pkt_hdr[i]->buf_hdr; hdr->buf_hdr.seg[i].hdr = buf_hdr; hdr->buf_hdr.seg[i].data = buf_hdr->base_data; From patchwork Thu Jul 20 18:00:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 108429 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2446527qge; Thu, 20 Jul 2017 11:03:52 -0700 (PDT) X-Received: by 10.237.32.70 with SMTP id 64mr5880006qta.218.1500573832533; Thu, 20 Jul 2017 11:03:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500573832; cv=none; d=google.com; s=arc-20160816; b=HqSIqRrQ3M7A3FsxLr2+6JgvJY3ibsrqcSx38VHL39H8OIRdj4DxYbh+A2nX6QMt0l k+K4/V2WHMupRMt+0ln9JTmHIWwsPJ+3txNKbXJJauA7lnnQVy7TN9qYJ+luYRxkNq1j DUMZhyVXArPnBoshQ7xEVkgydjTT2WGGvCgsxjoR0gph1rRYu3eihCE0M4BF3fZrUbDX eFrsZwEVFAO9J7Q3CaWNJUOXHXHreNBjzjxF1ENhZXLL9VLqPTwfsfMdYKcQj+SNx+ny X9x7GktoWbZo0CpYte9g1X4P2mRTrSlAwryeALXUBC4fdMiz+kEzA3XGs3Tsp7myIPVk CDQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=ZfswXQcnD5T8+Gd/qM2GBP6Ag8OvtxOwV3Spd5U6HsE=; b=rruyC5KrYPWWqWnoQGhFYg/i64LRPP/VxieblFNR7zcwYv/RtSBiWZRIlC5p+f9+Np QICxYz71pn4dJ1ICQPuYADhAEkVcnX5C6pLo8suERIC63RjomBWtfvnLrhXIzSoMts0G uDuUl9Dbh41gjm5PBdsGmIz6qK7hT7ooUBC+l391lagX5XqREovhRHI5yDZ9G8uMRkaM LpRplUWehiR7+E0pcwkQZHiyiKsYFALHouyj+V9AikHQ3m7vLHljF52aZhdrPmqbBusk 5NxiSRxcmFEEqvelfxXjm+xPGtrzkJ6K3Zf5E1OJOmKlrYdj6+6V9+OlXXETaMiiPb2Y W/WQ== ARC-Authentication-Results: i=1; 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id l186si2321242qkb.73.2017.07.20.11.03.52; Thu, 20 Jul 2017 11:03:52 -0700 (PDT) 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 333936081B; Thu, 20 Jul 2017 18:03:52 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 9500060CEE; Thu, 20 Jul 2017 18:00:39 +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 97EC263505; Thu, 20 Jul 2017 18:00:23 +0000 (UTC) Received: from forward3m.cmail.yandex.net (forward3m.cmail.yandex.net [5.255.216.21]) by lists.linaro.org (Postfix) with ESMTPS id 53A3B60CE2 for ; Thu, 20 Jul 2017 18:00:18 +0000 (UTC) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [IPv6:2a02:6b8:0:1402::15:6]) by forward3m.cmail.yandex.net (Yandex) with ESMTP id A122A20F37 for ; Thu, 20 Jul 2017 21:00:16 +0300 (MSK) Received: from smtp4p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp4p.mail.yandex.net (Yandex) with ESMTP id 7D90C6501177 for ; Thu, 20 Jul 2017 21:00:15 +0300 (MSK) Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id a46hdQ3693-0FaevbAH; Thu, 20 Jul 2017 21:00:15 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 20 Jul 2017 21:00:02 +0300 Message-Id: <1500573607-18783-6-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> References: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 82 Subject: [lng-odp] [PATCH v3 5/10] linux-generic: packet: unshared_len maintenance 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" From: Bill Fischofer Add code to initialize and maintain unshared_len packet metadata Signed-off-by: Bill Fischofer --- /** Email created from pull request 82 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/82 ** Patch: https://github.com/Linaro/odp/pull/82.patch ** Base sha: 95ba4b394009d92c29c2e22f0776e90bb4c6edec ** Merge commit sha: 01d093d362af5a52e079c622a99ae3495f68b64c **/ .../linux-generic/include/odp_packet_internal.h | 5 +++ platform/linux-generic/odp_packet.c | 40 ++++++++++++++++------ 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index e5887c9b..244f678b 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -19,6 +19,7 @@ extern "C" { #include #include +#include #include #include #include @@ -244,6 +245,7 @@ static inline void pull_tail(odp_packet_hdr_t *pkt_hdr, uint32_t len) pkt_hdr->tailroom += len; pkt_hdr->frame_len -= len; + pkt_hdr->unshared_len -= len; pkt_hdr->buf_hdr.seg[last].len -= len; } @@ -273,7 +275,10 @@ static inline void packet_ref_count_set(odp_packet_hdr_t *pkt_hdr, uint32_t n) static inline void packet_set_len(odp_packet_hdr_t *pkt_hdr, uint32_t len) { + ODP_ASSERT(packet_ref_count(pkt_hdr) == 1); + pkt_hdr->frame_len = len; + pkt_hdr->unshared_len = len; } /* Forward declarations */ diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 8806be8a..dfe94fb7 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -152,6 +152,7 @@ static inline void push_head(odp_packet_hdr_t *pkt_hdr, uint32_t len) { pkt_hdr->headroom -= len; pkt_hdr->frame_len += len; + pkt_hdr->unshared_len += len; pkt_hdr->buf_hdr.seg[0].data -= len; pkt_hdr->buf_hdr.seg[0].len += len; } @@ -160,6 +161,7 @@ static inline void pull_head(odp_packet_hdr_t *pkt_hdr, uint32_t len) { pkt_hdr->headroom += len; pkt_hdr->frame_len -= len; + pkt_hdr->unshared_len -= len; pkt_hdr->buf_hdr.seg[0].data += len; pkt_hdr->buf_hdr.seg[0].len -= len; } @@ -170,6 +172,7 @@ static inline void push_tail(odp_packet_hdr_t *pkt_hdr, uint32_t len) pkt_hdr->tailroom -= len; pkt_hdr->frame_len += len; + pkt_hdr->unshared_len += len; pkt_hdr->buf_hdr.seg[last].len += len; } @@ -197,6 +200,10 @@ static inline void packet_seg_copy_md(odp_packet_hdr_t *dst, dst->buf_hdr.uarea_addr = src->buf_hdr.uarea_addr; dst->buf_hdr.uarea_size = src->buf_hdr.uarea_size; + /* reference related metadata */ + dst->ref_len = src->ref_len; + dst->unshared_len = src->unshared_len; + /* segmentation data is not copied: * buf_hdr.seg[] * buf_hdr.segcount @@ -396,9 +403,10 @@ static inline odp_packet_hdr_t *add_segments(odp_packet_hdr_t *pkt_hdr, new_hdr->buf_hdr.seg[0].len = seg_len; packet_seg_copy_md(new_hdr, pkt_hdr); - new_hdr->frame_len = pkt_hdr->frame_len + len; - new_hdr->headroom = pool->headroom + offset; - new_hdr->tailroom = pkt_hdr->tailroom; + new_hdr->frame_len = pkt_hdr->frame_len + len; + new_hdr->unshared_len = pkt_hdr->unshared_len + len; + new_hdr->headroom = pool->headroom + offset; + new_hdr->tailroom = pkt_hdr->tailroom; pkt_hdr = new_hdr; } else { @@ -411,8 +419,9 @@ static inline odp_packet_hdr_t *add_segments(odp_packet_hdr_t *pkt_hdr, last = packet_last_seg(pkt_hdr); pkt_hdr->buf_hdr.seg[last].len = seg_len; - pkt_hdr->frame_len += len; - pkt_hdr->tailroom = pool->tailroom + offset; + pkt_hdr->frame_len += len; + pkt_hdr->unshared_len += len; + pkt_hdr->tailroom = pool->tailroom + offset; } return pkt_hdr; @@ -450,9 +459,10 @@ static inline odp_packet_hdr_t *free_segments(odp_packet_hdr_t *pkt_hdr, packet_seg_copy_md(new_hdr, pkt_hdr); /* Tailroom not changed */ - new_hdr->tailroom = pkt_hdr->tailroom; - new_hdr->headroom = seg_headroom(new_hdr, 0); - new_hdr->frame_len = pkt_hdr->frame_len - free_len; + new_hdr->tailroom = pkt_hdr->tailroom; + new_hdr->headroom = seg_headroom(new_hdr, 0); + new_hdr->frame_len = pkt_hdr->frame_len - free_len; + new_hdr->unshared_len = pkt_hdr->unshared_len - free_len; pull_head(new_hdr, pull_len); @@ -467,6 +477,7 @@ static inline odp_packet_hdr_t *free_segments(odp_packet_hdr_t *pkt_hdr, * of the metadata. */ pkt_hdr->buf_hdr.segcount = num_remain; pkt_hdr->frame_len -= free_len; + pkt_hdr->unshared_len -= free_len; pkt_hdr->tailroom = seg_tailroom(pkt_hdr, num_remain - 1); pull_tail(pkt_hdr, pull_len); @@ -912,6 +923,7 @@ int odp_packet_extend_head(odp_packet_t *pkt, uint32_t len, pkt_hdr->buf_hdr.segcount = segs; pkt_hdr->frame_len = frame_len; + pkt_hdr->unshared_len = frame_len; pkt_hdr->headroom = offset + pool->headroom; pkt_hdr->tailroom = pool->tailroom; @@ -953,6 +965,8 @@ void *odp_packet_pull_head(odp_packet_t pkt, uint32_t len) if (len > pkt_hdr->frame_len) return NULL; + ODP_ASSERT(len <= pkt_hdr->unshared_len); + pull_head(pkt_hdr, len); return packet_data(pkt_hdr); } @@ -1319,6 +1333,8 @@ int odp_packet_add_data(odp_packet_t *pkt_ptr, uint32_t offset, uint32_t len) if (offset > pktlen) return -1; + ODP_ASSERT(odp_packet_unshared_len(*pkt_ptr) >= offset); + newpkt = odp_packet_alloc(pool->pool_hdl, pktlen + len); if (newpkt == ODP_PACKET_INVALID) @@ -1439,8 +1455,9 @@ int odp_packet_concat(odp_packet_t *dst, odp_packet_t src) add_all_segs(dst_hdr, src_hdr); - dst_hdr->frame_len = dst_len + src_len; - dst_hdr->tailroom = src_hdr->tailroom; + dst_hdr->frame_len = dst_len + src_len; + dst_hdr->unshared_len = dst_len + src_len; + dst_hdr->tailroom = src_hdr->tailroom; /* Data was not moved in memory */ return 0; @@ -1453,6 +1470,7 @@ int odp_packet_split(odp_packet_t *pkt, uint32_t len, odp_packet_t *tail) if (len >= pktlen || tail == NULL) return -1; + ODP_ASSERT(odp_packet_unshared_len(*pkt) >= len); *tail = odp_packet_copy_part(*pkt, len, pktlen - len, odp_packet_pool(*pkt)); @@ -1538,6 +1556,8 @@ int odp_packet_copy_from_mem(odp_packet_t pkt, uint32_t offset, if (offset + len > pkt_hdr->frame_len) return -1; + ODP_ASSERT(odp_packet_unshared_len(pkt) >= offset + len); + while (len > 0) { mapaddr = packet_map(pkt_hdr, offset, &seglen, NULL); cpylen = len > seglen ? seglen : len; From patchwork Thu Jul 20 18:00:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 108430 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2447605qge; Thu, 20 Jul 2017 11:04:45 -0700 (PDT) X-Received: by 10.237.43.35 with SMTP id p32mr6313063qtd.86.1500573885450; Thu, 20 Jul 2017 11:04:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500573885; cv=none; d=google.com; s=arc-20160816; b=kFE4tpa6NCsvJhIm0+Mnj+nNH/SnCskB3gKzntjtPWQ82je8UsQsMQAeqsTIc9XhOj /vW9EdagBIN1X+Zkvm2rwCZhq4+mO4CZjudwsK/dMI3KfYFYagwtFZ8Fp7JDT5enNTCY tVpqdl6flAP8rhCXbdZw6Kv6JgOXbowlnZkoKki/JZp3g1ldOHHdeo010Ng5mOpIXhnr OxyPTlu6G+XtGp1qPko198S0LX9O2KBTmVJMhOss298WqTtpnWbFyHvSBT6ULqMY6R54 g7hMKE5B0iB4O9YGbe2Fi2eaWUXkJiEKoyEFuAapWiZDv8Q8Mid8bXNx2jCBsXaRde4f u7/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=+av5x3cO85nLTBmPeP7Pzn5LbvOddmMikfMCeIWvK00=; b=s6o57pX2HSAmX5Q9tSq+vDLkchUzAm0rBBq/yIKFpgwtOQih3YM8vHoNoNetlxKpB5 L/yn3BrrLfbQ0SSxf9M90rWEK9bNcFRMLQzcU8TYffzmEIizwOjPETu3r9uGRTyG3mGo pkmGZt/knFCwb0Ynm9o5ioJU9ZZnLMrYXVBjHX1vUv8rnga9Pv61+6wss7U2zGcznu8k GXBRPoVNg29SO6FBYonLmuxTNWWr6Y7n9HaHotHya6RsKBnNxLX5hBTa4BT97NxUT0ST cXOz6ADF3jLbpqvEcFtdomS389ql9yOw8xTZB6d1CQMSrS9fRvrdByOy1QiWR7fCAyPy OY8g== ARC-Authentication-Results: i=1; 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 41si2448547qtg.277.2017.07.20.11.04.45; Thu, 20 Jul 2017 11:04:45 -0700 (PDT) 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 103D260C5D; Thu, 20 Jul 2017 18:04:45 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 EBB3A636A2; Thu, 20 Jul 2017 18:00:44 +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 778D86065D; Thu, 20 Jul 2017 18:00:27 +0000 (UTC) Received: from forward1h.cmail.yandex.net (forward1h.cmail.yandex.net [87.250.230.16]) by lists.linaro.org (Postfix) with ESMTPS id 3040160C47 for ; Thu, 20 Jul 2017 18:00:19 +0000 (UTC) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [95.108.252.166]) by forward1h.cmail.yandex.net (Yandex) with ESMTP id BC17520F5B for ; Thu, 20 Jul 2017 21:00:17 +0300 (MSK) Received: from smtp4p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp4p.mail.yandex.net (Yandex) with ESMTP id 965386501184 for ; Thu, 20 Jul 2017 21:00:17 +0300 (MSK) Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id a46hdQ3693-0GaSBEQ0; Thu, 20 Jul 2017 21:00:16 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 20 Jul 2017 21:00:03 +0300 Message-Id: <1500573607-18783-7-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> References: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 82 Subject: [lng-odp] [PATCH v3 6/10] linux-generic: packet: segment manipulation with references 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" From: Bill Fischofer Add support for segment operation with references Signed-off-by: Bill Fischofer --- /** Email created from pull request 82 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/82 ** Patch: https://github.com/Linaro/odp/pull/82.patch ** Base sha: 95ba4b394009d92c29c2e22f0776e90bb4c6edec ** Merge commit sha: 01d093d362af5a52e079c622a99ae3495f68b64c **/ .../include/odp/api/plat/packet_inlines.h | 40 ++--- .../include/odp/api/plat/packet_inlines_api.h | 16 -- .../linux-generic/include/odp_packet_internal.h | 55 ++++++- platform/linux-generic/odp_packet.c | 170 +++++++++++++++++---- 4 files changed, 212 insertions(+), 69 deletions(-) diff --git a/platform/linux-generic/include/odp/api/plat/packet_inlines.h b/platform/linux-generic/include/odp/api/plat/packet_inlines.h index 14cc86c8..11ce58c0 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_inlines.h +++ b/platform/linux-generic/include/odp/api/plat/packet_inlines.h @@ -54,7 +54,19 @@ static inline uint32_t _odp_packet_seg_len(odp_packet_t pkt) /** @internal Inline function @param pkt @return */ static inline uint32_t _odp_packet_len(odp_packet_t pkt) { - return _odp_pkt_get(pkt, uint32_t, frame_len); + uint32_t pkt_len = _odp_pkt_get(pkt, uint32_t, frame_len); + void *ref_nxt = _odp_pkt_get(pkt, void *, ref_hdr); + void *ref_pkt = (void *)pkt; + + while (ref_nxt) { + pkt_len += _odp_pkt_get(ref_pkt, uint32_t, ref_len) - + _odp_pkt_get(ref_pkt, uint32_t, ref_offset); + + ref_pkt = ref_nxt; + ref_nxt = _odp_pkt_get(ref_nxt, void *, ref_hdr); + } + + return pkt_len; } /** @internal Inline function @param pkt @return */ @@ -82,12 +94,6 @@ static inline odp_pktio_t _odp_packet_input(odp_packet_t pkt) } /** @internal Inline function @param pkt @return */ -static inline int _odp_packet_num_segs(odp_packet_t pkt) -{ - return _odp_pkt_get(pkt, uint8_t, segcount); -} - -/** @internal Inline function @param pkt @return */ static inline void *_odp_packet_user_ptr(odp_packet_t pkt) { return _odp_pkt_get(pkt, void *, user_ptr); @@ -126,7 +132,8 @@ static inline void *_odp_packet_head(odp_packet_t pkt) /** @internal Inline function @param pkt @return */ static inline int _odp_packet_is_segmented(odp_packet_t pkt) { - return _odp_pkt_get(pkt, uint8_t, segcount) > 1; + return _odp_pkt_get(pkt, uint8_t, segcount) > 1 || + _odp_pkt_get(pkt, void *, ref_hdr) != NULL; } /** @internal Inline function @param pkt @return */ @@ -137,23 +144,6 @@ static inline odp_packet_seg_t _odp_packet_first_seg(odp_packet_t pkt) return _odp_packet_seg_from_ndx(0); } -/** @internal Inline function @param pkt @return */ -static inline odp_packet_seg_t _odp_packet_last_seg(odp_packet_t pkt) -{ - return _odp_packet_seg_from_ndx(_odp_packet_num_segs(pkt) - 1); -} - -/** @internal Inline function @param pkt @param seg @return */ -static inline odp_packet_seg_t _odp_packet_next_seg(odp_packet_t pkt, - odp_packet_seg_t seg) -{ - if (odp_unlikely(_odp_packet_seg_to_ndx(seg) >= - _odp_packet_seg_to_ndx(_odp_packet_last_seg(pkt)))) - return ODP_PACKET_SEG_INVALID; - - return seg + 1; -} - /** @internal Inline function @param pkt @param offset @param len */ static inline void _odp_packet_prefetch(odp_packet_t pkt, uint32_t offset, uint32_t len) diff --git a/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h b/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h index 233bc876..f818f820 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h +++ b/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h @@ -48,11 +48,6 @@ _ODP_INLINE odp_pktio_t odp_packet_input(odp_packet_t pkt) return _odp_packet_input(pkt); } -_ODP_INLINE int odp_packet_num_segs(odp_packet_t pkt) -{ - return _odp_packet_num_segs(pkt); -} - _ODP_INLINE void *odp_packet_user_ptr(odp_packet_t pkt) { return _odp_packet_user_ptr(pkt); @@ -93,17 +88,6 @@ _ODP_INLINE odp_packet_seg_t odp_packet_first_seg(odp_packet_t pkt) return _odp_packet_first_seg(pkt); } -_ODP_INLINE odp_packet_seg_t odp_packet_last_seg(odp_packet_t pkt) -{ - return _odp_packet_last_seg(pkt); -} - -_ODP_INLINE odp_packet_seg_t odp_packet_next_seg(odp_packet_t pkt, - odp_packet_seg_t seg) -{ - return _odp_packet_next_seg(pkt, seg); -} - _ODP_INLINE void odp_packet_prefetch(odp_packet_t pkt, uint32_t offset, uint32_t len) { diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index 244f678b..2829842c 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -165,6 +165,50 @@ static inline odp_packet_hdr_t *odp_packet_hdr(odp_packet_t pkt) return (odp_packet_hdr_t *)(uintptr_t)pkt; } +static inline odp_packet_hdr_t *packet_last_hdr(odp_packet_t pkt, + uint32_t *offset) +{ + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *prev_hdr = pkt_hdr; + uint32_t ref_offset = 0; + + while (pkt_hdr->ref_hdr) { + ref_offset = pkt_hdr->ref_offset; + prev_hdr = pkt_hdr; + pkt_hdr = pkt_hdr->ref_hdr; + } + + if (offset) { + if (prev_hdr != pkt_hdr) + ref_offset += pkt_hdr->frame_len - prev_hdr->ref_len; + *offset = ref_offset; + } + + return pkt_hdr; +} + +static inline odp_packet_hdr_t *packet_prev_hdr(odp_packet_hdr_t *pkt_hdr, + odp_packet_hdr_t *cur_hdr, + uint32_t *offset) +{ + uint32_t ref_offset = 0; + odp_packet_hdr_t *prev_hdr = pkt_hdr; + + while (pkt_hdr->ref_hdr != cur_hdr) { + ref_offset = pkt_hdr->ref_offset; + prev_hdr = pkt_hdr; + pkt_hdr = pkt_hdr->ref_hdr; + } + + if (offset) { + if (prev_hdr != pkt_hdr) + ref_offset += pkt_hdr->frame_len - prev_hdr->ref_len; + *offset = ref_offset; + } + + return pkt_hdr; +} + static inline odp_packet_t packet_handle(odp_packet_hdr_t *pkt_hdr) { return (odp_packet_t)pkt_hdr; @@ -251,7 +295,16 @@ static inline void pull_tail(odp_packet_hdr_t *pkt_hdr, uint32_t len) static inline uint32_t packet_len(odp_packet_hdr_t *pkt_hdr) { - return pkt_hdr->frame_len; + uint32_t pkt_len = pkt_hdr->frame_len; + odp_packet_hdr_t *ref_hdr = pkt_hdr->ref_hdr; + + while (ref_hdr) { + pkt_len += (pkt_hdr->ref_len - pkt_hdr->ref_offset); + pkt_hdr = ref_hdr; + ref_hdr = ref_hdr->ref_hdr; + } + + return pkt_len; } static inline uint32_t packet_ref_count(odp_packet_hdr_t *pkt_hdr) diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index dfe94fb7..b31d1d78 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -92,12 +92,13 @@ static inline uint32_t packet_seg_len(odp_packet_hdr_t *pkt_hdr, return pkt_hdr->buf_hdr.seg[seg_idx].len; } -static inline void *packet_seg_data(odp_packet_hdr_t *pkt_hdr, uint32_t seg_idx) +static inline uint8_t *packet_seg_data(odp_packet_hdr_t *pkt_hdr, + uint32_t seg_idx) { return pkt_hdr->buf_hdr.seg[seg_idx].data; } -static inline int packet_last_seg(odp_packet_hdr_t *pkt_hdr) +static inline uint32_t packet_last_seg(odp_packet_hdr_t *pkt_hdr) { if (CONFIG_PACKET_MAX_SEGS == 1) return 0; @@ -218,7 +219,15 @@ static inline void *packet_map(odp_packet_hdr_t *pkt_hdr, int seg = 0; int seg_count = pkt_hdr->buf_hdr.segcount; - if (odp_unlikely(offset >= pkt_hdr->frame_len)) + /* Special processing for references */ + while (offset >= pkt_hdr->frame_len && pkt_hdr->ref_hdr) { + offset -= (pkt_hdr->frame_len - pkt_hdr->ref_offset); + offset += (pkt_hdr->ref_hdr->frame_len - pkt_hdr->ref_len); + pkt_hdr = pkt_hdr->ref_hdr; + seg_count = pkt_hdr->buf_hdr.segcount; + } + + if (odp_unlikely(offset > pkt_hdr->frame_len)) return NULL; if (odp_likely(CONFIG_PACKET_MAX_SEGS == 1 || seg_count == 1)) { @@ -670,13 +679,47 @@ odp_event_t odp_packet_to_event(odp_packet_t pkt) uint32_t odp_packet_buf_len(odp_packet_t pkt) { odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); + uint32_t buf_len = 0; - return pkt_hdr->buf_hdr.size * pkt_hdr->buf_hdr.segcount; + do { + buf_len += pkt_hdr->buf_hdr.size * pkt_hdr->buf_hdr.segcount; + pkt_hdr = pkt_hdr->ref_hdr; + } while (pkt_hdr); + + return buf_len; } -void *odp_packet_tail(odp_packet_t pkt) +uint32_t odp_packet_unshared_len(odp_packet_t pkt) { odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); + uint32_t pkt_len = 0, offset = 0; + + if (packet_ref_count(pkt_hdr) == 1) + pkt_hdr->unshared_len = pkt_hdr->frame_len; + + do { + if (packet_ref_count(pkt_hdr) > 1) { + if (offset == 0) + pkt_len += pkt_hdr->unshared_len; + break; + } + + pkt_len += pkt_hdr->frame_len - offset; + offset = pkt_hdr->ref_offset; + + if (pkt_hdr->ref_hdr) + offset += (pkt_hdr->ref_hdr->frame_len - + pkt_hdr->ref_len); + + pkt_hdr = pkt_hdr->ref_hdr; + } while (pkt_hdr); + + return pkt_len; +} + +void *odp_packet_tail(odp_packet_t pkt) +{ + odp_packet_hdr_t *pkt_hdr = packet_last_hdr(pkt, NULL); return packet_tail(pkt_hdr); } @@ -1286,6 +1329,46 @@ void odp_packet_ts_set(odp_packet_t pkt, odp_time_t timestamp) pkt_hdr->p.input_flags.timestamp = 1; } +int odp_packet_num_segs(odp_packet_t pkt) +{ + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); + uint32_t segcount = 0, i; + uint32_t seg_offset = 0, offset; + + do { + segcount += pkt_hdr->buf_hdr.segcount - seg_offset; + offset = pkt_hdr->ref_offset; + pkt_hdr = pkt_hdr->ref_hdr; + if (pkt_hdr) { + for (i = 0, seg_offset = 0; + i < pkt_hdr->buf_hdr.segcount; + i++, seg_offset++) { + if (offset < pkt_hdr->buf_hdr.seg[i].len) + break; + offset -= pkt_hdr->buf_hdr.seg[i].len; + } + } + } while (pkt_hdr); + + return segcount; +} + +odp_packet_seg_t odp_packet_last_seg(odp_packet_t pkt) +{ + return _odp_packet_seg_from_ndx(odp_packet_num_segs(pkt) - 1); +} + +odp_packet_seg_t odp_packet_next_seg(odp_packet_t pkt, odp_packet_seg_t seg) +{ + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); + + if (odp_unlikely(_odp_packet_seg_to_ndx(seg) >= + packet_last_seg(pkt_hdr))) + return ODP_PACKET_SEG_INVALID; + + return seg + 1; +} + /* * * Segment level @@ -1296,23 +1379,53 @@ void odp_packet_ts_set(odp_packet_t pkt, odp_time_t timestamp) void *odp_packet_seg_data(odp_packet_t pkt, odp_packet_seg_t seg) { odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); + uint32_t seg_offset = 0, offset = 0, i; + uint32_t seg_ndx = _odp_packet_seg_to_ndx(seg); + + while (seg_ndx >= pkt_hdr->buf_hdr.segcount - seg_offset && + pkt_hdr->ref_hdr) { + seg_ndx -= (pkt_hdr->buf_hdr.segcount - seg_offset); + offset = pkt_hdr->ref_offset; + pkt_hdr = pkt_hdr->ref_hdr; + for (i = 0, seg_offset = 0; + i < pkt_hdr->buf_hdr.segcount; + i++, seg_offset++) { + if (offset < pkt_hdr->buf_hdr.seg[i].len) + break; + offset -= pkt_hdr->buf_hdr.seg[i].len; + } + } - if (odp_unlikely(_odp_packet_seg_to_ndx(seg) >= - pkt_hdr->buf_hdr.segcount)) + if (odp_unlikely(seg_ndx + seg_offset >= pkt_hdr->buf_hdr.segcount)) return NULL; - return packet_seg_data(pkt_hdr, _odp_packet_seg_to_ndx(seg)); + return packet_seg_data(pkt_hdr, seg_ndx + seg_offset) + offset; } uint32_t odp_packet_seg_data_len(odp_packet_t pkt, odp_packet_seg_t seg) { odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); + uint32_t seg_offset = 0, offset = 0, i; + uint32_t seg_ndx = _odp_packet_seg_to_ndx(seg); + + while (seg_ndx >= pkt_hdr->buf_hdr.segcount - seg_offset && + pkt_hdr->ref_hdr) { + seg_ndx -= (pkt_hdr->buf_hdr.segcount - seg_offset); + offset = pkt_hdr->ref_offset; + pkt_hdr = pkt_hdr->ref_hdr; + for (i = 0, seg_offset = 0; + i < pkt_hdr->buf_hdr.segcount; + i++, seg_offset++) { + if (offset < pkt_hdr->buf_hdr.seg[i].len) + break; + offset -= pkt_hdr->buf_hdr.seg[i].len; + } + } - if (odp_unlikely(_odp_packet_seg_to_ndx(seg) >= - pkt_hdr->buf_hdr.segcount)) + if (odp_unlikely(seg_ndx + seg_offset >= pkt_hdr->buf_hdr.segcount)) return 0; - return packet_seg_len(pkt_hdr, _odp_packet_seg_to_ndx(seg)); + return packet_seg_len(pkt_hdr, seg_ndx + seg_offset) - offset; } /* @@ -1358,13 +1471,15 @@ int odp_packet_rem_data(odp_packet_t *pkt_ptr, uint32_t offset, uint32_t len) { odp_packet_t pkt = *pkt_ptr; odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); - uint32_t pktlen = pkt_hdr->frame_len; + uint32_t pktlen = packet_len(pkt_hdr); pool_t *pool = pkt_hdr->buf_hdr.pool_ptr; odp_packet_t newpkt; - if (offset > pktlen || offset + len > pktlen) + if (offset + len > pktlen) return -1; + ODP_ASSERT(odp_packet_unshared_len(*pkt_ptr) >= offset + len); + newpkt = odp_packet_alloc(pool->pool_hdl, pktlen - len); if (newpkt == ODP_PACKET_INVALID) @@ -1398,6 +1513,8 @@ int odp_packet_align(odp_packet_t *pkt, uint32_t offset, uint32_t len, if (align > ODP_CACHE_LINE_SIZE) return -1; + ODP_ASSERT(odp_packet_has_ref(*pkt) == 0); + if (seglen >= len) { misalign = align <= 1 ? 0 : ROUNDUP_ALIGN(uaddr, align) - uaddr; @@ -1437,10 +1554,13 @@ int odp_packet_concat(odp_packet_t *dst, odp_packet_t src) uint32_t dst_len = dst_hdr->frame_len; uint32_t src_len = src_hdr->frame_len; + ODP_ASSERT(packet_ref_count(dst_hdr) == 1); + /* Do a copy if resulting packet would be out of segments or packets - * are from different pools. */ + * are from different pools or src is a reference. */ if (odp_unlikely((dst_segs + src_segs) > CONFIG_PACKET_MAX_SEGS) || - odp_unlikely(dst_pool != src_pool)) { + odp_unlikely(dst_pool != src_pool) || + odp_unlikely(packet_ref_count(src_hdr) > 1)) { if (odp_packet_extend_tail(dst, src_len, NULL, NULL) >= 0) { (void)odp_packet_copy_from_pkt(*dst, dst_len, src, 0, src_len); @@ -1489,8 +1609,7 @@ int odp_packet_split(odp_packet_t *pkt, uint32_t len, odp_packet_t *tail) odp_packet_t odp_packet_copy(odp_packet_t pkt, odp_pool_t pool) { - odp_packet_hdr_t *srchdr = packet_hdr(pkt); - uint32_t pktlen = srchdr->frame_len; + uint32_t pktlen = odp_packet_len(pkt); odp_packet_t newpkt = odp_packet_alloc(pool, pktlen); if (newpkt != ODP_PACKET_INVALID) { @@ -1529,7 +1648,7 @@ int odp_packet_copy_to_mem(odp_packet_t pkt, uint32_t offset, uint8_t *dstaddr = (uint8_t *)dst; odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); - if (offset + len > pkt_hdr->frame_len) + if (offset + len > packet_len(pkt_hdr)) return -1; while (len > 0) { @@ -1553,7 +1672,7 @@ int odp_packet_copy_from_mem(odp_packet_t pkt, uint32_t offset, const uint8_t *srcaddr = (const uint8_t *)src; odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); - if (offset + len > pkt_hdr->frame_len) + if (offset + len > packet_len(pkt_hdr)) return -1; ODP_ASSERT(odp_packet_unshared_len(pkt) >= offset + len); @@ -1583,10 +1702,12 @@ int odp_packet_copy_from_pkt(odp_packet_t dst, uint32_t dst_offset, uint32_t src_seglen = 0; /* GCC */ int overlap; - if (dst_offset + len > dst_hdr->frame_len || - src_offset + len > src_hdr->frame_len) + if (dst_offset + len > packet_len(dst_hdr) || + src_offset + len > packet_len(src_hdr)) return -1; + ODP_ASSERT(odp_packet_unshared_len(dst) >= dst_offset + len); + overlap = (dst_hdr == src_hdr && ((dst_offset <= src_offset && dst_offset + len >= src_offset) || @@ -1719,7 +1840,7 @@ void odp_packet_print(odp_packet_t pkt) len += snprintf(&str[len], n - len, " l4_offset %" PRIu32 "\n", hdr->p.l4_offset); len += snprintf(&str[len], n - len, - " frame_len %" PRIu32 "\n", hdr->frame_len); + " frame_len %" PRIu32 "\n", packet_len(hdr)); len += snprintf(&str[len], n - len, " input %" PRIu64 "\n", odp_pktio_to_u64(hdr->input)); @@ -2192,11 +2313,6 @@ int odp_packet_has_ref(odp_packet_t pkt) return 0; } -uint32_t odp_packet_unshared_len(odp_packet_t pkt) -{ - return odp_packet_len(pkt); -} - /* Include non-inlined versions of API functions */ #if ODP_ABI_COMPAT == 1 #include From patchwork Thu Jul 20 18:00:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 108431 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2448879qge; Thu, 20 Jul 2017 11:05:51 -0700 (PDT) X-Received: by 10.55.165.82 with SMTP id o79mr6231712qke.348.1500573951330; Thu, 20 Jul 2017 11:05:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500573951; cv=none; d=google.com; s=arc-20160816; b=zwQbA7zjhGw0eiXPL9YKxE/ZjWior1tNPgobGhlPl4n7PeqffQw23T4rYJ1OYllc0b u0DLNZw9mcDNQFxqwahq4NNhpMbiLVNdiHuRH6dOie95r1UfLG90vflndpPzU8ACRupX FsUM5BaNiz3t7fY/iuxTBfeueW+vhuffRVs4xNoILmchkGUlSeJP545/4B6Iju8FFQOF 1AgYBb6Qpvq/HELIvOyg10TzuwOBTC60Uab7k9ZkXHpYEtxivSFSSM5rKi4df4JN14YU +bWumjpzMP1qWp1HCVimJQDeVSBMWhYfKsQx1AB2tQ/+qqhjHOEYbAATpGkNNt9RHMOk mYeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=6cHa0a14kzd6CNJUiz0LwICu54ZTka8ttAHMtd7BBnY=; b=nuo29PSaj3CrNBm0NzXlN6PgbtbsD/gGe1/Vux0HeZl1xBypCDGJuQ6h6eBV7INBIM 5deSqiqgHSqKUGeSxk6STBSb8ZHT7I/ngZZGqbnomBSz4P/Ctapp7q0ELH1gnOMjQJht nXOQBEHJ0p4Yu5tdhhn/R+M4vQYCpE/B0J1aEL90/KZVINSasDElSekayVJW5avuJclu bYCEiAuV9KToaqG+6Jer+uY30kKxSvx5O1/TiHgPT/RyI4vy3oFSwuSJL3ZmfHaMVNUV d117HNah2x8FLMa9rtVkK0E5Vf7xTIdwz22qCCcCPXzpKXaX2ESuErZRY+svGkU3Ogb1 ilsQ== ARC-Authentication-Results: i=1; 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id q101si2424219qkh.349.2017.07.20.11.05.51; Thu, 20 Jul 2017 11:05:51 -0700 (PDT) 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id CAF8F60694; Thu, 20 Jul 2017 18:05:50 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 49129644D6; Thu, 20 Jul 2017 18:00:48 +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 62CF360804; Thu, 20 Jul 2017 18:00:31 +0000 (UTC) Received: from forward5h.cmail.yandex.net (forward5h.cmail.yandex.net [87.250.230.20]) by lists.linaro.org (Postfix) with ESMTPS id 002EE60D25 for ; Thu, 20 Jul 2017 18:00:20 +0000 (UTC) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [95.108.252.166]) by forward5h.cmail.yandex.net (Yandex) with ESMTP id 9462720F58 for ; Thu, 20 Jul 2017 21:00:18 +0300 (MSK) Received: from smtp4p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp4p.mail.yandex.net (Yandex) with ESMTP id 70B106500CA9 for ; Thu, 20 Jul 2017 21:00:18 +0300 (MSK) Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id a46hdQ3693-0HaOxjR6; Thu, 20 Jul 2017 21:00:17 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 20 Jul 2017 21:00:04 +0300 Message-Id: <1500573607-18783-8-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> References: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 82 Subject: [lng-odp] [PATCH v3 7/10] linux-generic: packet: restructure free routines for references 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" From: Bill Fischofer Restructure the various packet/segment free routines to support references. Signed-off-by: Bill Fischofer --- /** Email created from pull request 82 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/82 ** Patch: https://github.com/Linaro/odp/pull/82.patch ** Base sha: 95ba4b394009d92c29c2e22f0776e90bb4c6edec ** Merge commit sha: 01d093d362af5a52e079c622a99ae3495f68b64c **/ platform/linux-generic/odp_packet.c | 123 +++++++++++++++++++++++++----------- 1 file changed, 87 insertions(+), 36 deletions(-) diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index b31d1d78..a26d6528 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -438,13 +438,20 @@ static inline odp_packet_hdr_t *add_segments(odp_packet_hdr_t *pkt_hdr, static inline void free_bufs(odp_packet_hdr_t *pkt_hdr, int first, int num) { - int i; + int i, nfree; odp_buffer_hdr_t *buf_hdr[num]; - for (i = 0; i < num; i++) - buf_hdr[i] = pkt_hdr->buf_hdr.seg[first + i].hdr; + for (i = 0, nfree = 0; i < num; i++) { + odp_packet_hdr_t *hdr = pkt_hdr->buf_hdr.seg[first + i].hdr; + + if (packet_ref_count(hdr) == 1 || packet_ref_dec(hdr) == 1) { + ODP_ASSERT((packet_ref_count_set(hdr, 0), 1)); + buf_hdr[nfree++] = &hdr->buf_hdr; + } + } - buffer_free_multi(buf_hdr, num); + if (nfree > 0) + buffer_free_multi(buf_hdr, nfree); } static inline odp_packet_hdr_t *free_segments(odp_packet_hdr_t *pkt_hdr, @@ -455,11 +462,19 @@ static inline odp_packet_hdr_t *free_segments(odp_packet_hdr_t *pkt_hdr, if (head) { odp_packet_hdr_t *new_hdr; - int i; + int i, nfree; odp_buffer_hdr_t *buf_hdr[num]; - for (i = 0; i < num; i++) - buf_hdr[i] = pkt_hdr->buf_hdr.seg[i].hdr; + for (i = 0, nfree = 0; i < num; i++) { + new_hdr = pkt_hdr->buf_hdr.seg[i].hdr; + + if (packet_ref_count(new_hdr) == 1 || + packet_ref_dec(new_hdr) == 1) { + ODP_ASSERT((packet_ref_count_set(new_hdr, 0), + 1)); + buf_hdr[nfree++] = &new_hdr->buf_hdr; + } + } /* First remaining segment is the new packet descriptor */ new_hdr = pkt_hdr->buf_hdr.seg[num].hdr; @@ -477,7 +492,8 @@ static inline odp_packet_hdr_t *free_segments(odp_packet_hdr_t *pkt_hdr, pkt_hdr = new_hdr; - buffer_free_multi(buf_hdr, num); + if (nfree > 0) + buffer_free_multi(buf_hdr, nfree); } else { /* Free last 'num' bufs */ free_bufs(pkt_hdr, num_remain, num); @@ -593,48 +609,80 @@ int odp_packet_alloc_multi(odp_pool_t pool_hdl, uint32_t len, return num; } -void odp_packet_free(odp_packet_t pkt) +static inline void packet_free(odp_packet_hdr_t *pkt_hdr) { - odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); - odp_buffer_t hdl = buffer_handle(pkt_hdr); + odp_packet_hdr_t *ref_hdr; + odp_buffer_hdr_t *buf_hdr; + uint32_t ref_count; + int num_seg; + + do { + buf_hdr = &pkt_hdr->buf_hdr; + ref_count = packet_ref_count(pkt_hdr); + num_seg = pkt_hdr->buf_hdr.segcount; + ref_hdr = pkt_hdr->ref_hdr; + ODP_ASSERT(ref_count >= 1); + + if (odp_likely((CONFIG_PACKET_MAX_SEGS == 1 || num_seg == 1) && + ref_count == 1)) { + ODP_ASSERT((packet_ref_count_set(pkt_hdr, 0), 1)); + buffer_free_multi(&buf_hdr, 1); + } else { + free_bufs(pkt_hdr, 0, num_seg); + } - int num_seg = pkt_hdr->buf_hdr.segcount; + pkt_hdr = ref_hdr; + } while (pkt_hdr); +} - if (odp_likely(CONFIG_PACKET_MAX_SEGS == 1 || num_seg == 1)) - buffer_free_multi((odp_buffer_hdr_t **)&hdl, 1); - else - free_bufs(pkt_hdr, 0, num_seg); +void odp_packet_free(odp_packet_t pkt) +{ + packet_free(packet_hdr(pkt)); } void odp_packet_free_multi(const odp_packet_t pkt[], int num) { - if (CONFIG_PACKET_MAX_SEGS == 1) { - buffer_free_multi((odp_buffer_hdr_t **)(uintptr_t)pkt, num); - } else { - odp_buffer_hdr_t *buf_hdr[num * CONFIG_PACKET_MAX_SEGS]; - int i; - int j; - int bufs = 0; + odp_packet_hdr_t *pkt_hdr, *ref_hdr, *hdr; + int nbufs = num * CONFIG_PACKET_MAX_SEGS * 2; + odp_buffer_hdr_t *buf_hdr[nbufs]; + int num_seg; + int i, j; + uint32_t ref_count; + int nfree = 0; - for (i = 0; i < num; i++) { - odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt[i]); - int num_seg = pkt_hdr->buf_hdr.segcount; - odp_buffer_hdr_t *hdr = &pkt_hdr->buf_hdr; + for (i = 0; i < num; i++) { + pkt_hdr = packet_hdr(pkt[i]); - buf_hdr[bufs] = hdr; - bufs++; + do { + num_seg = pkt_hdr->buf_hdr.segcount; + ref_hdr = pkt_hdr->ref_hdr; - if (odp_likely(num_seg == 1)) - continue; + /* Make sure we have enough space for this pkt's segs */ + if (nfree + num_seg > nbufs) { + buffer_free_multi(buf_hdr, nfree); + nfree = 0; + } - for (j = 1; j < num_seg; j++) { - buf_hdr[bufs] = hdr->seg[j].hdr; - bufs++; + for (j = 0; j < num_seg; j++) { + hdr = pkt_hdr->buf_hdr.seg[j].hdr; + ref_count = packet_ref_count(hdr); + ODP_ASSERT(ref_count >= 1); + + if (ref_count == 1 || + packet_ref_dec(hdr) == 1) { + ODP_ASSERT + ((packet_ref_count_set(hdr, 0), + 1)); + buf_hdr[nfree++] = &hdr->buf_hdr; + } } - } - buffer_free_multi(buf_hdr, bufs); + pkt_hdr = ref_hdr; + } while (pkt_hdr); } + + if (nfree > 0) + buffer_free_multi(buf_hdr, nfree); } int odp_packet_reset(odp_packet_t pkt, uint32_t len) @@ -646,6 +694,9 @@ int odp_packet_reset(odp_packet_t pkt, uint32_t len) if (odp_unlikely(len > (pool->max_seg_len * num))) return -1; + if (pkt_hdr->ref_hdr) + packet_free(pkt_hdr->ref_hdr); + reset_seg(pkt_hdr, 0, num); packet_init(pkt_hdr, len); From patchwork Thu Jul 20 18:00:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 108433 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2451568qge; Thu, 20 Jul 2017 11:08:06 -0700 (PDT) X-Received: by 10.55.82.3 with SMTP id g3mr5956577qkb.23.1500574085880; Thu, 20 Jul 2017 11:08:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500574085; cv=none; d=google.com; s=arc-20160816; b=W+xOIIojq2l5tPtshW3Zj/xirb06fn2iVKk864V0Z5gDQATj/kb82V3EMyOitdPnsU 2otZBYKIiIjQP5BNrv3bU8SUx0QTmnEaEINiUFEtb+JG7FcQxswLdXkROSj2MjOYlghC FFsZELzr72GuJEt6dW4/DKNldKDmMY6kYSbbpdsdl+bHmltjF89qIDQa5OJn7GOIl8W1 Xi6sqveEmW9XzXkh+aPQU8aYtA655Ysl3rlkRQcU65QCRwdF1Q0tVKoFeAKUdyBi2foY px+4n9JYnWuh6UO9K/xhgufN0VejIaYnM2LPujCYeljDi9RDfnC7FpKi7Q0RqV1xI0hF 2W0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=OXTX2a3ebkE857/bm81a8z5X3sLsTKHv2j/hzT++eaY=; b=TOyYrBI6Hjq8MHGdoTLkeIVarAnbCeqeMe/5a8xjRTky/AeX4Pnj3nGT7NQ4wH7gKa SadF7wumz9pJZwc9gFDxnQfg6OzgzY/xZcC5i48wAdx5i5SNmYDTZ72oXsWUgUfjF3ua rdD6dBws6jxkjNJSTOXjF8ZEA81u78cFmzAdUs6toBBTgNp+l9PPvskCArt8AUNrFv0Y tf25hLtpVSc1C+KX0bDgiQj30v3w7gyPHr4JCxkEsDlXWZyCmXiQab3BYOKAqUkJVvCX oyrhqxHUiRQDa5YC8yuktL+OT16ZzmTdx3Fle0hZmDEK9SxZvR+PAji75u0XOr5qnTKY RUNQ== ARC-Authentication-Results: i=1; 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id d82si2392339qkg.408.2017.07.20.11.08.05; Thu, 20 Jul 2017 11:08:05 -0700 (PDT) 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 29B0F63CB0; Thu, 20 Jul 2017 18:08:05 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 A7801644EA; Thu, 20 Jul 2017 18:01:10 +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 1B64860D00; Thu, 20 Jul 2017 18:01:05 +0000 (UTC) Received: from forward1m.cmail.yandex.net (forward1m.cmail.yandex.net [5.255.216.2]) by lists.linaro.org (Postfix) with ESMTPS id 4373B61E02 for ; Thu, 20 Jul 2017 18:00:21 +0000 (UTC) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [IPv6:2a02:6b8:0:1402::15:6]) by forward1m.cmail.yandex.net (Yandex) with ESMTP id 76AF6216CC for ; Thu, 20 Jul 2017 21:00:19 +0300 (MSK) Received: from smtp4p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp4p.mail.yandex.net (Yandex) with ESMTP id 532846500E80 for ; Thu, 20 Jul 2017 21:00:18 +0300 (MSK) Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id a46hdQ3693-0IaeQ3Js; Thu, 20 Jul 2017 21:00:18 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 20 Jul 2017 21:00:05 +0300 Message-Id: <1500573607-18783-9-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> References: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 82 Subject: [lng-odp] [PATCH v3 8/10] linux-generic: packet: add reference support for head/tail manipulation 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" From: Bill Fischofer Signed-off-by: Bill Fischofer --- /** Email created from pull request 82 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/82 ** Patch: https://github.com/Linaro/odp/pull/82.patch ** Base sha: 95ba4b394009d92c29c2e22f0776e90bb4c6edec ** Merge commit sha: 01d093d362af5a52e079c622a99ae3495f68b64c **/ platform/linux-generic/odp_packet.c | 96 +++++++++++++++++++++++++++++-------- 1 file changed, 77 insertions(+), 19 deletions(-) diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index a26d6528..a5abf1ba 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -966,6 +966,13 @@ int odp_packet_extend_head(odp_packet_t *pkt, uint32_t len, segs = pkt_hdr->buf_hdr.segcount; if (odp_unlikely((segs + num) > CONFIG_PACKET_MAX_SEGS)) { + /* Corner case: fail request if packet has + * references since we cannot shuffle segments + * since another thread may be accessing them + * concurrently */ + if (packet_ref_count(pkt_hdr) > 1) + return -1; + /* Cannot directly add new segments */ odp_packet_hdr_t *new_hdr; int new_segs = 0; @@ -1043,11 +1050,16 @@ int odp_packet_extend_head(odp_packet_t *pkt, uint32_t len, push_head(pkt_hdr, len); } - if (data_ptr) - *data_ptr = packet_data(pkt_hdr); + if (data_ptr || seg_len) { + uint32_t seg_ln = 0; + void *data = packet_map(pkt_hdr, 0, &seg_ln, NULL); - if (seg_len) - *seg_len = packet_first_seg_len(pkt_hdr); + if (data_ptr) + *data_ptr = data; + + if (seg_len) + *seg_len = seg_ln; + } return ret; } @@ -1068,15 +1080,35 @@ void *odp_packet_pull_head(odp_packet_t pkt, uint32_t len) int odp_packet_trunc_head(odp_packet_t *pkt, uint32_t len, void **data_ptr, uint32_t *seg_len_out) { - odp_packet_hdr_t *pkt_hdr = packet_hdr(*pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(*pkt), *nxt_hdr; uint32_t seg_len = packet_first_seg_len(pkt_hdr); + int ret = 0; - if (len > pkt_hdr->frame_len) + if (len > packet_len(pkt_hdr)) return -1; - if (len < seg_len) { + ODP_ASSERT(len <= odp_packet_unshared_len(*pkt)); + + /* Special processing for references */ + while (len >= pkt_hdr->frame_len && pkt_hdr->ref_hdr) { + ODP_ASSERT(packet_ref_count(pkt_hdr) == 1); + nxt_hdr = pkt_hdr->ref_hdr; + len -= pkt_hdr->frame_len; + len += pkt_hdr->ref_offset + + (nxt_hdr->frame_len - pkt_hdr->ref_len); + pkt_hdr->ref_hdr = NULL; + packet_free(pkt_hdr); + pkt_hdr = nxt_hdr; + seg_len = packet_first_seg_len(pkt_hdr); + *pkt = packet_handle(pkt_hdr); + ret = 1; + } + + if (CONFIG_PACKET_MAX_SEGS == 1 || + len < seg_len || + pkt_hdr->buf_hdr.segcount == 1) { pull_head(pkt_hdr, len); - } else if (CONFIG_PACKET_MAX_SEGS != 1) { + } else { int num = 0; uint32_t pull_len = 0; @@ -1091,23 +1123,29 @@ int odp_packet_trunc_head(odp_packet_t *pkt, uint32_t len, *pkt = packet_handle(pkt_hdr); } - if (data_ptr) - *data_ptr = packet_data(pkt_hdr); + if (data_ptr || seg_len_out) { + void *data_head = packet_map(pkt_hdr, 0, &seg_len, NULL); - if (seg_len_out) - *seg_len_out = packet_first_seg_len(pkt_hdr); + if (data_ptr) + *data_ptr = data_head; - return 0; + if (seg_len_out) + *seg_len_out = seg_len; + } + + return ret; } void *odp_packet_push_tail(odp_packet_t pkt, uint32_t len) { - odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_last_hdr(pkt, NULL); void *old_tail; if (len > pkt_hdr->tailroom) return NULL; + ODP_ASSERT(packet_ref_count(pkt_hdr) == 1); + old_tail = packet_tail(pkt_hdr); push_tail(pkt_hdr, len); @@ -1117,12 +1155,14 @@ void *odp_packet_push_tail(odp_packet_t pkt, uint32_t len) int odp_packet_extend_tail(odp_packet_t *pkt, uint32_t len, void **data_ptr, uint32_t *seg_len_out) { - odp_packet_hdr_t *pkt_hdr = packet_hdr(*pkt); + odp_packet_hdr_t *pkt_hdr = packet_last_hdr(*pkt, NULL); uint32_t frame_len = pkt_hdr->frame_len; uint32_t tailroom = pkt_hdr->tailroom; uint32_t tail_off = frame_len; int ret = 0; + ODP_ASSERT(packet_ref_count(pkt_hdr) == 1); + if (len > tailroom) { pool_t *pool = pkt_hdr->buf_hdr.pool_ptr; int num; @@ -1213,6 +1253,7 @@ void *odp_packet_pull_tail(odp_packet_t pkt, uint32_t len) if (len > packet_last_seg_len(pkt_hdr)) return NULL; + ODP_ASSERT(packet_ref_count(pkt_hdr) == 1); pull_tail(pkt_hdr, len); return packet_tail(pkt_hdr); @@ -1223,17 +1264,34 @@ int odp_packet_trunc_tail(odp_packet_t *pkt, uint32_t len, { int last; uint32_t seg_len; - odp_packet_hdr_t *pkt_hdr = packet_hdr(*pkt); + uint32_t offset; + odp_packet_hdr_t *first_hdr = packet_hdr(*pkt); + odp_packet_hdr_t *pkt_hdr, *prev_hdr; - if (len > pkt_hdr->frame_len) + if (len > packet_len(first_hdr)) return -1; + pkt_hdr = packet_last_hdr(*pkt, &offset); + + /* Special processing for references */ + while (len >= pkt_hdr->frame_len - offset && first_hdr->ref_hdr) { + len -= (pkt_hdr->frame_len - offset); + prev_hdr = packet_prev_hdr(first_hdr, pkt_hdr, &offset); + ODP_ASSERT(packet_ref_count(prev_hdr) == 1); + prev_hdr->ref_hdr = NULL; + packet_free(pkt_hdr); + pkt_hdr = prev_hdr; + } + + ODP_ASSERT(packet_ref_count(pkt_hdr) == 1); last = packet_last_seg(pkt_hdr); seg_len = packet_seg_len(pkt_hdr, last); - if (len < seg_len) { + if (CONFIG_PACKET_MAX_SEGS == 1 || + len < seg_len || + pkt_hdr->buf_hdr.segcount == 1) { pull_tail(pkt_hdr, len); - } else if (CONFIG_PACKET_MAX_SEGS != 1) { + } else { int num = 0; uint32_t pull_len = 0; From patchwork Thu Jul 20 18:00:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 108432 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2451034qge; Thu, 20 Jul 2017 11:07:35 -0700 (PDT) X-Received: by 10.237.32.141 with SMTP id 13mr6574251qtb.41.1500574055845; Thu, 20 Jul 2017 11:07:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500574055; cv=none; d=google.com; s=arc-20160816; b=AiT+/bqex7zwaUACyrYvZ81SdAVymQ83AkuCLS+sOcOaq/6wGNnadAcBQiGehhGmEX unMx3QqFIlOR5wOrJ7yfngX8N2Vj3HHsdaNoVlZzCdqKuLlerkLCChHML7+ZTGqXB3fP 6SWN2+4pU8vLa+hsN9N2VrU79ZV1oHV4V8iB59prKeR54jtBkSR1EH9C8bwBWj8XYHTu 40k9Jy/q2lttnUXBPRRBxp7zr/B3pYJK7s2c1pAH+O9sweHfyAHjPdvQFSmjDrrublCm uJOi9LyjMGuODYXfcmI3/6+OC9pGhcS5Q72+xw+qDao+GEhgGm6WCe/Szjo/I67YFdm2 6IIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=8Tt19deuuIApu7KJMbNapNHD9p5LLSLGXGhr6bkQVQ8=; b=Thz7ivGkRlr1hzpVwrsA2uHVOayTxjp3Mk14JUqht89xqy+jRXYawwPCgUPGJyt6+Z jW6GZdpMvA4WhsnjOtugBCrjjg7I3PNjoHzM7GQmNU4A3ZFSz9IhvZnpb2/ETwzjGck8 FtNpQqImGTWGA80eOb5DcBIZATU89HJROtu+HYp+gUfx20Gm9HOPCHUWh7VzsU7O4N+5 8wEKTbDgYPFWGwN0maAX93Wv2z59tzQxNE3ZJT+XHl/AbxpSJSgtdUH1CIUdpVCK4ciH zrNhmimA0lEt9YMkYseVpYecUF4TOPnelkDm+pLZdJWp1D+e1SuKypBS8tZe2Zx5L7rf O/5g== ARC-Authentication-Results: i=1; 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id m4si2330895qtf.195.2017.07.20.11.07.35; Thu, 20 Jul 2017 11:07:35 -0700 (PDT) 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 74835636AA; Thu, 20 Jul 2017 18:07:35 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 728E360CE2; Thu, 20 Jul 2017 18: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 3C795644EA; Thu, 20 Jul 2017 18:01:04 +0000 (UTC) Received: from forward4h.cmail.yandex.net (forward4h.cmail.yandex.net [87.250.230.101]) by lists.linaro.org (Postfix) with ESMTPS id C6A9160CB2 for ; Thu, 20 Jul 2017 18:00:21 +0000 (UTC) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [95.108.252.166]) by forward4h.cmail.yandex.net (Yandex) with ESMTP id 58A3820DCD for ; Thu, 20 Jul 2017 21:00:20 +0300 (MSK) Received: from smtp4p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp4p.mail.yandex.net (Yandex) with ESMTP id 339436501177 for ; Thu, 20 Jul 2017 21:00:19 +0300 (MSK) Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id a46hdQ3693-0JaGQTJD; Thu, 20 Jul 2017 21:00:19 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 20 Jul 2017 21:00:06 +0300 Message-Id: <1500573607-18783-10-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> References: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 82 Subject: [lng-odp] [PATCH v3 9/10] linux-generic: ipc: cannot share references across ipc 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" From: Bill Fischofer When attempting to send a reference via IPC, make a copy of the packet as reference sharing is only supported within a single ODP instance. Signed-off-by: Bill Fischofer --- /** Email created from pull request 82 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/82 ** Patch: https://github.com/Linaro/odp/pull/82.patch ** Base sha: 95ba4b394009d92c29c2e22f0776e90bb4c6edec ** Merge commit sha: 01d093d362af5a52e079c622a99ae3495f68b64c **/ platform/linux-generic/pktio/ipc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c index bc7d7564..8c7db84e 100644 --- a/platform/linux-generic/pktio/ipc.c +++ b/platform/linux-generic/pktio/ipc.c @@ -592,7 +592,9 @@ static int ipc_pktio_send_lockless(pktio_entry_t *pktio_entry, _ipc_free_ring_packets(pktio_entry, pktio_entry->s.ipc.tx.free); - /* Copy packets to shm shared pool if they are in different */ + /* Copy packets to shm shared pool if they are in different + * pool, or if they are references (we can't share across IPC). + */ for (i = 0; i < len; i++) { odp_packet_t pkt = pkt_table[i]; pool_t *ipc_pool = pool_entry_from_hdl(pktio_entry->s.ipc.pool); @@ -602,7 +604,8 @@ static int ipc_pktio_send_lockless(pktio_entry_t *pktio_entry, pkt_hdr = odp_packet_hdr(pkt); pool = pkt_hdr->buf_hdr.pool_ptr; - if (pool->pool_idx != ipc_pool->pool_idx) { + if (pool->pool_idx != ipc_pool->pool_idx || + odp_packet_has_ref(pkt)) { odp_packet_t newpkt; newpkt = odp_packet_copy(pkt, pktio_entry->s.ipc.pool); From patchwork Thu Jul 20 18:00:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 108434 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2452360qge; Thu, 20 Jul 2017 11:08:49 -0700 (PDT) X-Received: by 10.55.126.198 with SMTP id z189mr5980812qkc.299.1500574129732; Thu, 20 Jul 2017 11:08:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500574129; cv=none; d=google.com; s=arc-20160816; b=dDpbD7/fFPQbVhNPcUAhgZ+BbcZEO4wu02lLDneA6Os4qa0e7Pzse/IvaaoEWGSwww qbI990JOkcEg6qAgoc/prflwmVyYAdpF31kb0lJYFsyJplLY0itozFG36AU/gb/L1Ip6 1RmqOHdScLvrNvhGsNhiBYgsBRy/cfskMEygWaMlpip5XQiF2IJDIRiAyDsrsVHp2gpF 4ND4Ti/q5ZmeRHoNyfY6wEmDwhIEQKZNIQxwQnQ1noePBjLkEJ0/igmUOOyB6WK2swwW 74Cr6m6LInVivTWCcFdl9lVrX71EoIX+7lsf+KID3dhZxHrKmo1WNMedCzpptTe0svZH SeSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=Alp/JugAihJuDJYkhfPe6RK32SCZZ55IvHdOObdaZ50=; b=ltiV8Sc9wTmoRtNb6AlUYaCLxeBvug8X8dc0LK1nl2aoi390NSFkCNVLe9y6mWYR+i MxgaE+sM0XFif+ZlFgsHnuSmdBRdAag/nXf5DQmxXhWQSCBdfTC4Ep4Am29CjkRj2dpl BswmxEYOYDmPgypaeOVe9QAdHjLkfu+pcp3HoBMXdKaIy89KlICtoScYRR5ALNEhY+s9 QiJGz84oF+37KJUpH6nGAZEqgZPXkCgvUx7h1NL/lYqz62drpsTszwsrUiJX+OCf9PhL I/EaACMHWe6fJjVnSmicNPUE+BKwiMDPO0qaF5nN7VXSkmNtNPFcB9/BQ0eNqvF0jdBd +Gvw== ARC-Authentication-Results: i=1; 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id t187si2366275qkh.150.2017.07.20.11.08.49; Thu, 20 Jul 2017 11:08:49 -0700 (PDT) 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 58C0F60D25; Thu, 20 Jul 2017 18:08:49 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 EC42364FD5; Thu, 20 Jul 2017 18:01:14 +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 6E9EA60CE2; Thu, 20 Jul 2017 18:01:06 +0000 (UTC) Received: from forward4h.cmail.yandex.net (forward4h.cmail.yandex.net [87.250.230.101]) by lists.linaro.org (Postfix) with ESMTPS id 6F20C60CE0 for ; Thu, 20 Jul 2017 18:00:22 +0000 (UTC) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [IPv6:2a02:6b8:0:1402::15:6]) by forward4h.cmail.yandex.net (Yandex) with ESMTP id 6C0A420DDB for ; Thu, 20 Jul 2017 21:00:21 +0300 (MSK) Received: from smtp4p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp4p.mail.yandex.net (Yandex) with ESMTP id 2A93C6501177 for ; Thu, 20 Jul 2017 21:00:20 +0300 (MSK) Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id a46hdQ3693-0KaGv8Te; Thu, 20 Jul 2017 21:00:20 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 20 Jul 2017 21:00:07 +0300 Message-Id: <1500573607-18783-11-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> References: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 82 Subject: [lng-odp] [PATCH v3 10/10] linux-generic: packet: enable zero-copy reference 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" From: Bill Fischofer Signed-off-by: Bill Fischofer --- /** Email created from pull request 82 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/82 ** Patch: https://github.com/Linaro/odp/pull/82.patch ** Base sha: 95ba4b394009d92c29c2e22f0776e90bb4c6edec ** Merge commit sha: 01d093d362af5a52e079c622a99ae3495f68b64c **/ platform/linux-generic/odp_packet.c | 172 +++++++++++++++++++++--------------- 1 file changed, 103 insertions(+), 69 deletions(-) diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index a5abf1ba..35a8c645 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -1710,6 +1710,109 @@ int odp_packet_split(odp_packet_t *pkt, uint32_t len, odp_packet_t *tail) } /* + * References + */ + +static inline void packet_ref(odp_packet_hdr_t *pkt_hdr) +{ + uint32_t i; + odp_packet_hdr_t *hdr; + + do { + for (i = 0; i < pkt_hdr->buf_hdr.segcount; i++) { + hdr = pkt_hdr->buf_hdr.seg[i].hdr; + packet_ref_inc(hdr); + } + + pkt_hdr = pkt_hdr->ref_hdr; + } while (pkt_hdr); +} + +static inline odp_packet_t packet_splice(odp_packet_hdr_t *pkt_hdr, + uint32_t offset, + odp_packet_hdr_t *ref_hdr) +{ + /* Catch attempted references to stale handles in debug builds */ + ODP_ASSERT(packet_ref_count(pkt_hdr) > 0); + + /* Splicing is from the last section of src pkt */ + while (ref_hdr->ref_hdr) + ref_hdr = ref_hdr->ref_hdr; + + /* Find section where splice begins */ + while (offset >= pkt_hdr->frame_len && pkt_hdr->ref_hdr) { + offset -= (pkt_hdr->frame_len - pkt_hdr->ref_offset); + offset += (pkt_hdr->ref_hdr->frame_len - pkt_hdr->ref_len); + pkt_hdr = pkt_hdr->ref_hdr; + } + + ref_hdr->ref_hdr = pkt_hdr; + ref_hdr->ref_offset = offset; + ref_hdr->ref_len = pkt_hdr->frame_len; + + if (packet_ref_count(pkt_hdr) == 1 || offset < pkt_hdr->unshared_len) + pkt_hdr->unshared_len = offset; + + packet_ref(pkt_hdr); + return packet_handle(ref_hdr); +} + +odp_packet_t odp_packet_ref_static(odp_packet_t pkt) +{ + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); + + packet_ref(pkt_hdr); + pkt_hdr->unshared_len = 0; + return pkt; +} + +odp_packet_t odp_packet_ref(odp_packet_t pkt, uint32_t offset) +{ + odp_packet_t hdr; + odp_packet_hdr_t *pkt_hdr; + + if (pkt == ODP_PACKET_INVALID) + return ODP_PACKET_INVALID; + + pkt_hdr = packet_hdr(pkt); + if (offset >= packet_len(pkt_hdr)) + return ODP_PACKET_INVALID; + + hdr = odp_packet_alloc(odp_packet_pool(pkt), 0); + + if (hdr == ODP_PACKET_INVALID) + return ODP_PACKET_INVALID; + + return packet_splice(pkt_hdr, offset, packet_hdr(hdr)); +} + +odp_packet_t odp_packet_ref_pkt(odp_packet_t pkt, uint32_t offset, + odp_packet_t hdr) +{ + odp_packet_hdr_t *pkt_hdr; + + if (pkt == ODP_PACKET_INVALID || + hdr == ODP_PACKET_INVALID || + pkt == hdr) + return ODP_PACKET_INVALID; + + ODP_ASSERT(odp_packet_has_ref(hdr) == 0); + + pkt_hdr = packet_hdr(pkt); + if (offset >= packet_len(pkt_hdr)) + return ODP_PACKET_INVALID; + + return packet_splice(pkt_hdr, offset, packet_hdr(hdr)); +} + +int odp_packet_has_ref(odp_packet_t pkt) +{ + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); + + return pkt_hdr->ref_hdr != NULL || packet_ref_count(pkt_hdr) > 1; +} + +/* * * Copy * ******************************************************** @@ -2353,75 +2456,6 @@ uint64_t odp_packet_seg_to_u64(odp_packet_seg_t hdl) return _odp_pri(hdl); } -odp_packet_t odp_packet_ref_static(odp_packet_t pkt) -{ - return odp_packet_copy(pkt, odp_packet_pool(pkt)); -} - -odp_packet_t odp_packet_ref(odp_packet_t pkt, uint32_t offset) -{ - odp_packet_t new; - int ret; - - new = odp_packet_copy(pkt, odp_packet_pool(pkt)); - - if (new == ODP_PACKET_INVALID) { - ODP_ERR("copy failed\n"); - return ODP_PACKET_INVALID; - } - - ret = odp_packet_trunc_head(&new, offset, NULL, NULL); - - if (ret < 0) { - ODP_ERR("trunk_head failed\n"); - odp_packet_free(new); - return ODP_PACKET_INVALID; - } - - return new; -} - -odp_packet_t odp_packet_ref_pkt(odp_packet_t pkt, uint32_t offset, - odp_packet_t hdr) -{ - odp_packet_t new; - int ret; - - new = odp_packet_copy(pkt, odp_packet_pool(pkt)); - - if (new == ODP_PACKET_INVALID) { - ODP_ERR("copy failed\n"); - return ODP_PACKET_INVALID; - } - - if (offset) { - ret = odp_packet_trunc_head(&new, offset, NULL, NULL); - - if (ret < 0) { - ODP_ERR("trunk_head failed\n"); - odp_packet_free(new); - return ODP_PACKET_INVALID; - } - } - - ret = odp_packet_concat(&hdr, new); - - if (ret < 0) { - ODP_ERR("concat failed\n"); - odp_packet_free(new); - return ODP_PACKET_INVALID; - } - - return hdr; -} - -int odp_packet_has_ref(odp_packet_t pkt) -{ - (void)pkt; - - return 0; -} - /* Include non-inlined versions of API functions */ #if ODP_ABI_COMPAT == 1 #include