From patchwork Sat Jul 29 14:04:17 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: 108938 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp1633457obm; Sat, 29 Jul 2017 07:05:13 -0700 (PDT) X-Received: by 10.233.239.1 with SMTP id d1mr14563354qkg.126.1501337113510; Sat, 29 Jul 2017 07:05:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501337113; cv=none; d=google.com; s=arc-20160816; b=E932OHyLFZ3yp6EQaA56SNz8OtxDz87+nlvzsjiasKdhlJkrY1enznpyr2Cliu9sHB MeStSn4HqNrkAwzaXdXN+PF9/o1c4mD4vdVZkpxb3cDQLN9mpeMymV8xIoWbBoDGLfsi u6S/1F4nRWmd7gyugkM8Sogi1G1LEIE6OY+WFlXGyx3+WjUT3tO7xgzy9w9u/4u0dOZV sBljjYTaq2tlTIWGl1tZ+bFptABkprfeddoYxPB34PdstMveUwyJzq56QDIIOEpYD83z +eoImhivzBQdq4F0BpJyzmWZgb9Q5BpWxKEpFvD1Da2CKrTsVWDe7qfoz5jHmDH3Kn7u lBpw== 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=xQgbVlcsE88TW9yCeuYNfc6AQJJGzWOpaPtqWfxt1MA=; b=qEzCUHEv9+gBwYAvetmgXKnjM6Zi62q+VSNVL4ipXMIxQKrTVkPx43/n61hjjdVhLI oGAxXkEMRPwyQScfUyArR0K29On5Uz57xXl3+PquP/ui6n+Jxp+9yH3Ny+uJ4ZvUKcKI tiPwu8k9QAblNbZ3Lqn0ASzrR32SpfBk1iHqZn8JooYVVozo/D84s24+XeuA7B3NVeAa 51fO5rXvuc4xQ2wrfzr90WxrGeL7HlC/orCZbQj4ldHF8AiSbs9u7WbIztpf12+J2uwl URgxJumyImgs9FyRjLBLq2/cI00GjVGknnMV8QgXXIAeunnckjupdXcQyDzOQriITIxZ QaeQ== 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 23si5272126qtx.357.2017.07.29.07.05.13; Sat, 29 Jul 2017 07:05:13 -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 3D57962C2D; Sat, 29 Jul 2017 14:05:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-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 45BB062D0E; Sat, 29 Jul 2017 14:04:42 +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 C6D9962BE4; Sat, 29 Jul 2017 14:04:34 +0000 (UTC) Received: from forward5p.cmail.yandex.net (forward5p.cmail.yandex.net [77.88.31.20]) by lists.linaro.org (Postfix) with ESMTPS id CA86B60D7C for ; Sat, 29 Jul 2017 14:04:32 +0000 (UTC) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b6:7]) by forward5p.cmail.yandex.net (Yandex) with ESMTP id 4595620734 for ; Sat, 29 Jul 2017 17:04:30 +0300 (MSK) Received: from smtp2p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp2p.mail.yandex.net (Yandex) with ESMTP id 25DAC1A8009F for ; Sat, 29 Jul 2017 17:04:29 +0300 (MSK) Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id jNuvJAvdk4-4Tde1NpM; Sat, 29 Jul 2017 17:04:29 +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: Sat, 29 Jul 2017 17:04:17 +0300 Message-Id: <1501337066-32268-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501337066-32268-1-git-send-email-odpbot@yandex.ru> References: <1501337066-32268-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 90 Subject: [lng-odp] [PATCH v1 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 90 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/90 ** Patch: https://github.com/Linaro/odp/pull/90.patch ** Base sha: 79336f5eaee25168a5e4ad7fc0aee07395d4ca1f ** Merge commit sha: 7572a3f8658171fac22a3770b32be6795a1861a8 **/ .../include/odp/api/plat/packet_flag_inlines.h | 3 +- .../include/odp/api/plat/packet_inlines.h | 40 ++++++++-------------- .../include/odp/api/plat/packet_types.h | 4 +++ 3 files changed, 19 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..42003e31 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 @@ -22,8 +22,7 @@ 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..d0cf1390 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_inlines.h +++ b/platform/linux-generic/include/odp/api/plat/packet_inlines.h @@ -38,91 +38,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 +122,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 */ 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..41468bec 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_types.h +++ b/platform/linux-generic/include/odp/api/plat/packet_types.h @@ -67,6 +67,10 @@ typedef enum { #endif +/** @internal Packet field accessor */ +#define _odp_pkt_get(pkt, cast, field) \ + (*(cast *)(uintptr_t)((uint8_t *)pkt + _odp_packet_inline.field)) + /** @internal Packet header field offsets for inline functions */ typedef struct _odp_packet_inline_offset_t { /** @internal field offset */ From patchwork Sat Jul 29 14:04:19 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: 108939 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp1634623obm; Sat, 29 Jul 2017 07:06:06 -0700 (PDT) X-Received: by 10.55.163.3 with SMTP id m3mr13822435qke.118.1501337166784; Sat, 29 Jul 2017 07:06:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501337166; cv=none; d=google.com; s=arc-20160816; b=UTVW1lSAflZFf6TuheXqRctYtoUyF8qzyqtLZ237AUOpPiojcx7e8t1XsKXTwgoGKH K+J8dnmj09xc0oeLT7OgOZ7MtGoC344JVtgcNI/4TGOxvema5MZDIaMQagCn59FLhtOY xH4kjZWEdpyxxVhIyiVpcLcOn6fYHZZ2nPduikNdUgkN4u7u8wOfAMS0gWvoiTKimCrJ PFZP0TRYeJsaC4d89gcqznoqsRbrVULt6gaa9uPs1gUVwOJACO/5TN1jXgn8hOA0D4l1 DF5GOxbrEr2Xf8CGqlyKrNdeDB+0WKRrBE5KKoN4uiNrzi2W618qLAkkcRDPyihIncmg mnwA== 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=3o6GT6pEe3goz6Unb3HWUuP2bDj4DFdpqgWqAK1c0gc=; b=IBDu+vOlI7HdQAEJzxt9V/2r/gdLy/GpmVtTTe8cqcPvH1dVTXoa8FLvKuLoiPo58N DS5LpZbhUAkf7yjXyoSvcBg2lY6s8TQ29fgSMcsVKbf9BEgLA1/7wMlywc/+ycJ3FRnk sVje+mb38DEWj+URTPt3HtNshiB4ZTK/LMGQCNENOWWD0vBuZqjcs/PB2GumMYc6z1fQ 5yhCW1WaQ9cIRnf89KMduthMBvG0/pbJuCiUzm5F8qXvYDb4Ov5t8bZDCtVcKGwNQJ04 CQ4NfLHUjb38hM9FR0HBSbnUqjK8l88CNFmP6UaexJpdf7yv1+Y1HLfXYWw9maFzK7JM C5xw== 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 a66si14336239qke.490.2017.07.29.07.06.06; Sat, 29 Jul 2017 07:06:06 -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 41E9660D7C; Sat, 29 Jul 2017 14:06:04 +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 0B33B60DB8; Sat, 29 Jul 2017 14:05:11 +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 2162462C6C; Sat, 29 Jul 2017 14:05:06 +0000 (UTC) Received: from forward4o.cmail.yandex.net (forward4o.cmail.yandex.net [37.9.109.248]) by lists.linaro.org (Postfix) with ESMTPS id EA01160D7C for ; Sat, 29 Jul 2017 14:04:34 +0000 (UTC) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [77.88.29.85]) by forward4o.cmail.yandex.net (Yandex) with ESMTP id 228D120EA5 for ; Sat, 29 Jul 2017 17:04:33 +0300 (MSK) Received: from smtp2p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp2p.mail.yandex.net (Yandex) with ESMTP id 8D0D01A800AC for ; Sat, 29 Jul 2017 17:04:32 +0300 (MSK) Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id jNuvJAvdk4-4VdSdOo3; Sat, 29 Jul 2017 17:04:31 +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: Sat, 29 Jul 2017 17:04:19 +0300 Message-Id: <1501337066-32268-4-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501337066-32268-1-git-send-email-odpbot@yandex.ru> References: <1501337066-32268-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 90 Subject: [lng-odp] [PATCH v1 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 90 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/90 ** Patch: https://github.com/Linaro/odp/pull/90.patch ** Base sha: 79336f5eaee25168a5e4ad7fc0aee07395d4ca1f ** Merge commit sha: 7572a3f8658171fac22a3770b32be6795a1861a8 **/ 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 Sat Jul 29 14:04:20 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: 108940 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp1635255obm; Sat, 29 Jul 2017 07:06:37 -0700 (PDT) X-Received: by 10.55.75.8 with SMTP id y8mr15099714qka.247.1501337197020; Sat, 29 Jul 2017 07:06:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501337197; cv=none; d=google.com; s=arc-20160816; b=iAVb5CnJAKzSh3CkO3iZQyRfrYdwB9Ek4YqZPFE1Pfs3Y53C5oS8/phVxg4xpK0Dcm 4stjQ5j5RWghGVhfFj1wzgho4c6y7jH7Domv+QdYJIB8vSZTKQeUEwMABYt7m4GxIz8T T8LKQEAIV/aBM7KTQQcOWB0TJ2KyZFK1EAc5gHmRoCpk1tZEs1FWhiPubVvxme/7d5a9 +aH7hVvikkbyxxidfve3N+wqvBkds+p3vM+XCEWf1BL/qmf9iA+BhZeNtcc0cmqxeGEr vb2j9lIEXj9S0IrMeixWP9/A9BQnA83pbiXqQFmZ5dED3PUZFKvSvxc09iPoA0m3P8fM 7Oew== 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=aBxvzoULUBj5RndUquQjRc3TY2B3vHs5WMjnWzPn1W4=; b=sN6ZHPRk+HTaMAPMNYB3BTGDGMU4q/sPeUotamR9FzenR0yG1cUDgocJa9UO76F9M9 EbeVoS5g7RoaVmQTpoTRLYeP4MIeqoClxb7AknwA+lDxzo/o8YkTNMacAyJ4cg8jgaby cXXK87r0qLKy6sjYbuHyTNXSDqKdblXNH+vfSis+TUeuDcX5h8O1CcMuPzvLJZ9J3+Fw 4Ns9dSHd8l1uGYpE52DU4Q6IS9lpVe23zpZZBIwoUhc1gGDPWNlR4eIgDZI9dd/dQ49R 95s2+TcDBULCLHEodrYbhPTri8jDZ8q7LA1671uXxRtfvfr051CfNIuKbiw1+xc3TADl bF6A== 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 e125si19650047qkc.352.2017.07.29.07.06.36; Sat, 29 Jul 2017 07:06:37 -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 AD67464478; Sat, 29 Jul 2017 14:06:36 +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 87E3462C6C; Sat, 29 Jul 2017 14:05: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 806A9622F0; Sat, 29 Jul 2017 14:05:06 +0000 (UTC) Received: from forward4j.cmail.yandex.net (forward4j.cmail.yandex.net [5.255.227.22]) by lists.linaro.org (Postfix) with ESMTPS id 36A6362AEA for ; Sat, 29 Jul 2017 14:04:35 +0000 (UTC) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [77.88.29.85]) by forward4j.cmail.yandex.net (Yandex) with ESMTP id AAB7E20859 for ; Sat, 29 Jul 2017 17:04:33 +0300 (MSK) Received: from smtp2p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp2p.mail.yandex.net (Yandex) with ESMTP id 570841A8009D for ; Sat, 29 Jul 2017 17:04:32 +0300 (MSK) Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id jNuvJAvdk4-4WdGqmRm; Sat, 29 Jul 2017 17:04:32 +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: Sat, 29 Jul 2017 17:04:20 +0300 Message-Id: <1501337066-32268-5-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501337066-32268-1-git-send-email-odpbot@yandex.ru> References: <1501337066-32268-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 90 Subject: [lng-odp] [PATCH v1 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 90 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/90 ** Patch: https://github.com/Linaro/odp/pull/90.patch ** Base sha: 79336f5eaee25168a5e4ad7fc0aee07395d4ca1f ** Merge commit sha: 7572a3f8658171fac22a3770b32be6795a1861a8 **/ 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 Sat Jul 29 14:04:21 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: 108942 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp1637251obm; Sat, 29 Jul 2017 07:08:05 -0700 (PDT) X-Received: by 10.55.46.66 with SMTP id u63mr14284657qkh.333.1501337285346; Sat, 29 Jul 2017 07:08:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501337285; cv=none; d=google.com; s=arc-20160816; b=ab7vnKU1Sd90Ohc7aZD4S/i/06JSnJ+s6HwtCJBXRznHNbjeInzhyuu98sgSyEINJe hKePW3t8DGCFYvS0mxrnndN9m0moEViyj2paF2kg8AFR8IJ4N/V3hRF1appb4FfTulMH gUIeXlPg/u+7iaQQl2iCTLrVSWwwrdYqoJ7pbrSBqVmLYkK/uiczAq0LkeAK8KB02b/N 7+ibjWy5RvhROXCSorh0FLbVooaZcuS1aMhOl9JADNM5f0zbL/4VTSZ1Jl8Dh+VPBF62 NvZ/yreQrzZTDzlEi5gHjFhiYY8pUHl5Dxp3H9Iwk0OJVPSFKYCXJwxWxVSP1Li9kTNx Gmmw== 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=uR3eGGagNUzj1m+i615sXLF6gtui+cxY+7nIj+k+N78=; b=dFUyk42LniXSOTsDELbOWMa4kCgFBvVX/qUWlkWvGLuLD+hzHZpj1XVIdVWgxURROg OSISRQTj/Y1MmZpSZxKxRTUeizRgbY0H57fgaj1lsA82pSUzc7GYNqxuwtuXYWdfU0qd KukNzh9OgRWkH/dJ0YssyXyOC6LffTS4X57jVwInw7NkadfOc+0eCqolZ4DjCEUFyTem tNHPX+04JDXUM9KlA5UyPWq2npt01I/jZbQTtY3VlLr+5//TdN/S7oyIM8YeBNRyn1sh MvFE2XduGI+k6Qks4LpI2Tg/K3nw376AiTnD+yain2hf3P409MHp0yH/1q4HctKm4WZo Gs9w== 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 r199si13279417qke.287.2017.07.29.07.08.05; Sat, 29 Jul 2017 07: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 058B760D39; Sat, 29 Jul 2017 14: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 2A41265C5D; Sat, 29 Jul 2017 14:05:25 +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 EDFFB622F0; Sat, 29 Jul 2017 14:05:07 +0000 (UTC) Received: from forward3m.cmail.yandex.net (forward3m.cmail.yandex.net [5.255.216.21]) by lists.linaro.org (Postfix) with ESMTPS id BE30562BE4 for ; Sat, 29 Jul 2017 14:04:35 +0000 (UTC) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b6:7]) by forward3m.cmail.yandex.net (Yandex) with ESMTP id 6E62B20F31 for ; Sat, 29 Jul 2017 17:04:34 +0300 (MSK) Received: from smtp2p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp2p.mail.yandex.net (Yandex) with ESMTP id 4DA7D1A800A2 for ; Sat, 29 Jul 2017 17:04:33 +0300 (MSK) Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id jNuvJAvdk4-4Xdu80bB; Sat, 29 Jul 2017 17:04:33 +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: Sat, 29 Jul 2017 17:04:21 +0300 Message-Id: <1501337066-32268-6-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501337066-32268-1-git-send-email-odpbot@yandex.ru> References: <1501337066-32268-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 90 Subject: [lng-odp] [PATCH v1 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 90 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/90 ** Patch: https://github.com/Linaro/odp/pull/90.patch ** Base sha: 79336f5eaee25168a5e4ad7fc0aee07395d4ca1f ** Merge commit sha: 7572a3f8658171fac22a3770b32be6795a1861a8 **/ .../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 Sat Jul 29 14:04:22 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: 108945 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp1639403obm; Sat, 29 Jul 2017 07:10:02 -0700 (PDT) X-Received: by 10.55.201.201 with SMTP id m70mr13623901qkl.20.1501337402676; Sat, 29 Jul 2017 07:10:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501337402; cv=none; d=google.com; s=arc-20160816; b=IOdAn4Syxe0yoQTL1uIBNO1+5rF0cd3wSxI6BWoSpXThzXk7d508WWZdZoXELmWxgu uKqAmGlP7NZIov7jjXRv9QVxkhrizq8c36zb2mAae5jkaz/rDjIImS3Epks9cQG//ubB sMvWrmaoUeY59X3o15lq/X6kLgTnQAkfxMaUx8Ppk2I1NeWiNlsnn7+YeNdxKfQtQY7m RKLXEfbZWD1ha+d8r+0HxuMAben/HJ8oCUH1cJL5/XlX/oC5/eLypd415yce/2q4uuHQ l4hZBz2gS5k+u43w2r6V53mOUBtQHMkuwFA1s5UlQsrT6mKFW/zfI4FIJ9zAJm+cIC0K wqow== 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=5SlTC71JNSF9xPbfj4eGs6/aD4EFpg+oKNr7KCNrCOI=; b=xZQRdwRnS6vNEZcV5hfP/A+MUbWNKIzYDq4exX/Ft+gvg+SWDhsDi2n8JQUwO9DBI7 +Rwungx6tQ59Ir08te9ymlgxHk0TV3cySOKw6/JrTP2fKWMnMyCRas6ERSdgKcOxxo/o MLTsxsqhcp28+mtndOfAfEv5lLg3mU9pQlQlZmpF+NOXUYjhxuxleDIh8MGJRHPeioXV EdwoR2UkQUlVQmUVtKGrt9CEqZEVBX9DEfWtygpVgpgRrp2lKyxo7Q0jOzS00VycfSfw k8apCsQrj2Bt8puM5+1w6rTL6mKhVBjPk7P3e3drEj50bBlmtSSZkSn/4DM3g4gN/8jw eCJg== 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 y25si14361529qtc.18.2017.07.29.07.10.02; Sat, 29 Jul 2017 07:10:02 -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 4336662AEA; Sat, 29 Jul 2017 14:10:02 +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 1F01065CEA; Sat, 29 Jul 2017 14:05: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 26C6162AEA; Sat, 29 Jul 2017 14:05:10 +0000 (UTC) Received: from forward5j.cmail.yandex.net (forward5j.cmail.yandex.net [5.255.227.23]) by lists.linaro.org (Postfix) with ESMTPS id 0087D60DB8 for ; Sat, 29 Jul 2017 14:04:37 +0000 (UTC) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [77.88.29.85]) by forward5j.cmail.yandex.net (Yandex) with ESMTP id CAADE20723 for ; Sat, 29 Jul 2017 17:04:35 +0300 (MSK) Received: from smtp2p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp2p.mail.yandex.net (Yandex) with ESMTP id A94BE1A8009D for ; Sat, 29 Jul 2017 17:04:35 +0300 (MSK) Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id jNuvJAvdk4-4YdqISHg; Sat, 29 Jul 2017 17:04:34 +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: Sat, 29 Jul 2017 17:04:22 +0300 Message-Id: <1501337066-32268-7-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501337066-32268-1-git-send-email-odpbot@yandex.ru> References: <1501337066-32268-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 90 Subject: [lng-odp] [PATCH v1 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 90 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/90 ** Patch: https://github.com/Linaro/odp/pull/90.patch ** Base sha: 79336f5eaee25168a5e4ad7fc0aee07395d4ca1f ** Merge commit sha: 7572a3f8658171fac22a3770b32be6795a1861a8 **/ .../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 d0cf1390..06b049fc 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_inlines.h +++ b/platform/linux-generic/include/odp/api/plat/packet_inlines.h @@ -50,7 +50,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 */ @@ -78,12 +90,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); @@ -122,7 +128,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 */ @@ -133,23 +140,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 Sat Jul 29 14:04:23 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: 108941 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp1636225obm; Sat, 29 Jul 2017 07:07:16 -0700 (PDT) X-Received: by 10.200.4.145 with SMTP id s17mr15958685qtg.154.1501337236183; Sat, 29 Jul 2017 07:07:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501337236; cv=none; d=google.com; s=arc-20160816; b=El0nm94fFY+CbxEhgc725pQM/T+gK09FxwhigynAfRINL9li/46OMhZw5Kf5IrNdfL Z9UDeNFd9c3LJ5HFv1uclpnKJIUjss7mK/KsR0PwR8NivQsomnoKmpB7c5dcm48cUiFW 7ndp3C00ilO2xbR/CqWR3hWH0MzvreZXxRlWVpBUfdXIlkhgOojXufuSHJXFbvaWduwn oaMKRS3gdH0/jx4bYfpzxOnuXgAnpeRx59dVS9j5ECVTz20sCS4wyZvfgmtaSeBEKWxy s1hiG6uYT5Ba+m7c+H9/zsgoh96NtRwu70QcBrLS0aKiDaIJxoA8z83H9uphLDLSCfqY myzQ== 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=twSKOIfmR60lfL7XBb0Ohw1j6dm/TUkSCMuCtP4jxmY=; b=QHa8ejmctn9wQ5yG6BMQmtBpR9qbhIdgRJ2wFKt7DNkgk9TnbgsdH+QKqJdop8kq+r n7W0oCilp2TGp0ACcAtkJLRP99EgTGBiVtfr7sag3MrJEFUs0PX6Ifdl5WMV3QC/IMi1 DC44ppB/8ocWrvwPLkxmBAdZTWbpG+zCE33DFP4MLEmneK8w8i8u3e+ys3unoR+FLqY4 Gj8q6Vc8G+6pII2gjl5pu1GQhyBEsxw3ZJPb/IB9Z10cCRFcnaRYFcRm0OwxZ+mRv38e XPjsvJ9I7dvWB8g/KamqVNj5PYNKy2Q21uxu/Zd9HchoZTni8roXzKEB2V2WjEpQBKne ZeTg== 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 x5si19963558qke.346.2017.07.29.07.07.15; Sat, 29 Jul 2017 07:07:16 -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 D3FD761E1A; Sat, 29 Jul 2017 14:07:15 +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 DCC9B62CFE; Sat, 29 Jul 2017 14:05:18 +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 A7CFB622F0; Sat, 29 Jul 2017 14:05:07 +0000 (UTC) Received: from forward3o.cmail.yandex.net (forward3o.cmail.yandex.net [37.9.109.247]) by lists.linaro.org (Postfix) with ESMTPS id A06BE62C2D for ; Sat, 29 Jul 2017 14:04:37 +0000 (UTC) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b6:7]) by forward3o.cmail.yandex.net (Yandex) with ESMTP id 8F6E420722 for ; Sat, 29 Jul 2017 17:04:36 +0300 (MSK) Received: from smtp2p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp2p.mail.yandex.net (Yandex) with ESMTP id 69A0E1A800A7 for ; Sat, 29 Jul 2017 17:04:36 +0300 (MSK) Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id jNuvJAvdk4-4ZdS9haf; Sat, 29 Jul 2017 17:04:35 +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: Sat, 29 Jul 2017 17:04:23 +0300 Message-Id: <1501337066-32268-8-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501337066-32268-1-git-send-email-odpbot@yandex.ru> References: <1501337066-32268-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 90 Subject: [lng-odp] [PATCH v1 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 90 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/90 ** Patch: https://github.com/Linaro/odp/pull/90.patch ** Base sha: 79336f5eaee25168a5e4ad7fc0aee07395d4ca1f ** Merge commit sha: 7572a3f8658171fac22a3770b32be6795a1861a8 **/ 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 Sat Jul 29 14:04:24 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: 108944 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp1638637obm; Sat, 29 Jul 2017 07:09:20 -0700 (PDT) X-Received: by 10.200.45.3 with SMTP id n3mr14103180qta.15.1501337360544; Sat, 29 Jul 2017 07:09:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501337360; cv=none; d=google.com; s=arc-20160816; b=blQcL+XePulbdPYw3hutz3Xgr0iq0QVREv5/PHE3ezTWTJtJbz2atMBQaw/NxmfocZ mng7mSzmcozoxzIpx674STcw/6QiZfbBKHLCwHTdV01/+MtfJ2NodloltX6Dzfe4cvTc +Qs9QqxBTAJMBB1lGxKcbjWPvpN0uoEZvNqHNEa7w9IFvg7avLEqw5Uc/oZzTLoZbZ9E 97k5avJeMzPSFk5G83Jja7PrkBiBeNM1E/dViaNrDVX/1ubtQ/h3GMbcJoonMrMtBMWa w8zEWgXIm5tGiHo22sDEp9vK6hwZgMN/dNFKz1i/AIj5WHi0xuI7HBj+hzX/TKm/GYwr bgmA== 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=WRh4XonKQCHwwAQmTcx0CImSmKfr+Jt3KC8H7V/HYto=; b=L85v2ZAWK9bLf3RwMy6ZlzXcMfX8nyDk6YJzjViPEeI1wTG2mWfVuDAgBM3e5p52/t Yi/JeJ+LhsYb3HPq6YXYFVlUpTlzsGvgbG5wSkvgYDfSOVzzAiipA4XqCxWT/sxQaIN1 k5regMSztksUhZ8VICCtp0RI3O/l87VI9U4oftAvBrPqS/GLWZLtVoUwI/dPv6+nz5+s h3bERLgRGKik/VjZmfOZWBvcSCR2aKAgMxdBqvcJN2NEjGJDIXjLWFa+ENsdFQlw1D/K gPPkzFk6s9rsnvVDemjECqOFzgeoYdv9wMQ7CQ0XLqN8T9KMAmEEQtdyqVV3PVePxRFw jCpA== 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 t5si19757443qtd.471.2017.07.29.07.09.20; Sat, 29 Jul 2017 07:09:20 -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 3D18662C2D; Sat, 29 Jul 2017 14:09:20 +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 B82E865CE0; Sat, 29 Jul 2017 14:05: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 E5D0F622F0; Sat, 29 Jul 2017 14:05:09 +0000 (UTC) Received: from forward3j.cmail.yandex.net (forward3j.cmail.yandex.net [5.255.227.21]) by lists.linaro.org (Postfix) with ESMTPS id 404F862CE7 for ; Sat, 29 Jul 2017 14:04:39 +0000 (UTC) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b6:7]) by forward3j.cmail.yandex.net (Yandex) with ESMTP id 5FC9020765 for ; Sat, 29 Jul 2017 17:04:37 +0300 (MSK) Received: from smtp2p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp2p.mail.yandex.net (Yandex) with ESMTP id 3B1CF1A800AA for ; Sat, 29 Jul 2017 17:04:36 +0300 (MSK) Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id jNuvJAvdk4-4ad4SlDZ; Sat, 29 Jul 2017 17:04:36 +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: Sat, 29 Jul 2017 17:04:24 +0300 Message-Id: <1501337066-32268-9-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501337066-32268-1-git-send-email-odpbot@yandex.ru> References: <1501337066-32268-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 90 Subject: [lng-odp] [PATCH v1 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 90 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/90 ** Patch: https://github.com/Linaro/odp/pull/90.patch ** Base sha: 79336f5eaee25168a5e4ad7fc0aee07395d4ca1f ** Merge commit sha: 7572a3f8658171fac22a3770b32be6795a1861a8 **/ 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 Sat Jul 29 14:04:25 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: 108943 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp1638139obm; Sat, 29 Jul 2017 07:08:50 -0700 (PDT) X-Received: by 10.237.61.16 with SMTP id g16mr14321238qtf.60.1501337330665; Sat, 29 Jul 2017 07:08:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501337330; cv=none; d=google.com; s=arc-20160816; b=SGy0YIkvjaMTn3OeWZTI4ZFanf7nAKeXiV16fkvLlBhoo13g51GcoVeMcGpfJdoZby iH+x1V6cVCbTDxj2LJTvMlZzF6u8LEQ9zPaMMQYFtXuOQQB36FuOeXb8pmrWL9rgwU/3 Mw4sDAsfI2kBaQIQVkR3AjR07E9zH0O/fPQIIfG3drrN6U4br0SHPUpURydW/EvdQ4so hDcM0sKio0lJQduANpsaRZ8bp+S/o582u1Qsyc3tISEZ9ETd9+ytVKwb6P4CndDrULem XgDdR20LOyhqgSwcxj/UJUbJgHMlN24a6oJ9lHaIXBYhP9q/uiQDAzX+07SGE9vLzAUX tx0w== 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=ta8lYC+7z5DTgdvuacPtGylOlwVx+ozrAgHeGO5PLnE=; b=0eu/OUeJxnqowFMZ3kx1L7Dwr8e6r5idbhYV2F2KbldEGkMFW/yjgSk6sfCWWWJVcr Qzs8ALAJg3NzaiWKqa//e0D5ORDQ72o4dIHIex62cysc8ht+kfg9uppCQqDpSCBT781l qj+Ak3RTeuYRwEM4qb9PDVdmz4yGHSJKWOS2IbY/WA1+OOtuziUGWcX0vawZzDY6wbIO XyuOxKeFt4I5LJYMjQLDI7udHNUbjmyIp74SIWplYg1EmJhq8UyvZi9Xkhe71Xt29Y4z 2FqF+X6VhRrHNv9pkDSg0BbVQhkjExxEbmno6B8laRO4Y+QnftMDrGNY49RSVnQW/Shc g8Nw== 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 n66si19173375qkf.365.2017.07.29.07.08.50; Sat, 29 Jul 2017 07:08:50 -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 4CDCF622F0; Sat, 29 Jul 2017 14:08: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 6F00765CE3; Sat, 29 Jul 2017 14:05:27 +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 24475622F0; Sat, 29 Jul 2017 14:05:09 +0000 (UTC) Received: from forward3j.cmail.yandex.net (forward3j.cmail.yandex.net [5.255.227.21]) by lists.linaro.org (Postfix) with ESMTPS id 51A1262CF0 for ; Sat, 29 Jul 2017 14:04:39 +0000 (UTC) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [77.88.29.85]) by forward3j.cmail.yandex.net (Yandex) with ESMTP id 5648C20BB6 for ; Sat, 29 Jul 2017 17:04:38 +0300 (MSK) Received: from smtp2p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp2p.mail.yandex.net (Yandex) with ESMTP id 0A8191A800A2 for ; Sat, 29 Jul 2017 17:04:37 +0300 (MSK) Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id jNuvJAvdk4-4bd8WtHG; Sat, 29 Jul 2017 17:04:37 +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: Sat, 29 Jul 2017 17:04:25 +0300 Message-Id: <1501337066-32268-10-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501337066-32268-1-git-send-email-odpbot@yandex.ru> References: <1501337066-32268-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 90 Subject: [lng-odp] [PATCH v1 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 90 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/90 ** Patch: https://github.com/Linaro/odp/pull/90.patch ** Base sha: 79336f5eaee25168a5e4ad7fc0aee07395d4ca1f ** Merge commit sha: 7572a3f8658171fac22a3770b32be6795a1861a8 **/ 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 Sat Jul 29 14:04:26 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: 108946 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp1641623obm; Sat, 29 Jul 2017 07:12:18 -0700 (PDT) X-Received: by 10.233.235.3 with SMTP id b3mr13750269qkg.138.1501337537988; Sat, 29 Jul 2017 07:12:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501337537; cv=none; d=google.com; s=arc-20160816; b=Bl0G5g3sxEL8AlM1Fi6+JfudABSPKxrc0blSBClBEW5vXwY0pN5HebVon577fl5gW2 UrJKKOLrL19xSTx68uG4UvAgDbbvyVWWLnzsUTlCd+nc1pwH50mu8mBiWICgZs7LgcGy oXAmCtKEAy23zNspl9anEDnu67U6+Zalf6RRIHHFq7x62pi+7T1XfGfcNhgNEn7kBqg+ fJvFINvQ641PG+KBi6X5EDGeNznAW5M8IkgyoYcvoLxqO2sZpGvnUfsaTwXTJ5aks3QI 9ptxoo7Qqbx49iFxL5M/Wj64hsT5b9pqvL5FtBdCr8PIhi4GJ4Cym9lVUKqrVpO3ZucK eYvA== 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=ipltEGouqUS8FJa77/hlbopFzvVp1a9T677tsVCczbo=; b=kRkr8qjsLgVC3oI+TLw2O6eWDHuHcx+D1J34Rmr9hL49a4nbsl8lFSc3pW9madRSvM 4q8CniDbS3RnvSm/0tGkKFWHSUZcBXLzLW83OLt6Q0hv8cxPvwFjwXA0wBqHXK9RGJOh QYupfM19MI+EJ3QwQNQAlwTidMrsOVwbg99fn5Z56v0jJOJYy91NFr/HpJzWQUyIpzzw LbCW85dso1fj5c+83aFMJbuK4IQVQjqAi8lVHWncxvrSUt+doci/46ugG6oMFqfjkj9+ JEns7EPjHnYNnOcrfUXvL0POzT+7EH1SpazJhT48JigxqVYBaoEJzXJ87WQzP4dMvUfN utIQ== 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 t185si19779515qkc.252.2017.07.29.07.12.17; Sat, 29 Jul 2017 07:12:17 -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 71F5E60C10; Sat, 29 Jul 2017 14:12: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 3BC1160A06; Sat, 29 Jul 2017 14:06: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 E13C460D7C; Sat, 29 Jul 2017 14:06:03 +0000 (UTC) Received: from forward3m.cmail.yandex.net (forward3m.cmail.yandex.net [5.255.216.21]) by lists.linaro.org (Postfix) with ESMTPS id 530E260D94 for ; Sat, 29 Jul 2017 14:04:40 +0000 (UTC) Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [77.88.29.85]) by forward3m.cmail.yandex.net (Yandex) with ESMTP id 591AB20F31 for ; Sat, 29 Jul 2017 17:04:39 +0300 (MSK) Received: from smtp2p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp2p.mail.yandex.net (Yandex) with ESMTP id 2EEEF1A800A4 for ; Sat, 29 Jul 2017 17:04:38 +0300 (MSK) Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id jNuvJAvdk4-4cdiWGfA; Sat, 29 Jul 2017 17:04:38 +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: Sat, 29 Jul 2017 17:04:26 +0300 Message-Id: <1501337066-32268-11-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501337066-32268-1-git-send-email-odpbot@yandex.ru> References: <1501337066-32268-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 90 Subject: [lng-odp] [PATCH v1 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 90 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/90 ** Patch: https://github.com/Linaro/odp/pull/90.patch ** Base sha: 79336f5eaee25168a5e4ad7fc0aee07395d4ca1f ** Merge commit sha: 7572a3f8658171fac22a3770b32be6795a1861a8 **/ 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