From patchwork Tue Aug 1 15: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: 109174 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp1606947qge; Tue, 1 Aug 2017 08:03:00 -0700 (PDT) X-Received: by 10.237.62.156 with SMTP id n28mr29160093qtf.203.1501599780024; Tue, 01 Aug 2017 08:03:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501599780; cv=none; d=google.com; s=arc-20160816; b=H7jiCosEl8zGEu8dOfYzU4mh0LKMPT4xKAFTtvQ2+mpOp6aQo3gF0j/+rZCa+vvzNx 6Awc5kyKUzAYY5TbP8uMKveUrRH1NeRhLE15QoWO3uOaqvykl7GBpQDvC8fyo2aqZ3lU mAnPiRoaiRqC2ZDKhP8U0B32m+gZcEquxW8sYLM77o+/mEfldwVWoMY1xbLH6dsIJxxj kf16+ynOalR26x7Y9zc36S5WiWAi4QgPLsexyYiBn5lsUi1w50eoDOB2Zg7kS+QZCh4F qok8a/sFid+rpNEV7VWukK7HuHJkH6slplXmGA0ZTXti8FpcMBvUrPk/qw4atkMi+dZp EhjQ== 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=4c7V/6rQFffCdpRUgSquoUTZmAKeEJB7F3Vu7jcvV9g=; b=VXbK9miJOwy7xtyemRnblo4S9iR9qVjpitZy6JhZEeSJY6va1Yk+SDG1RZG2T/8xV3 XifiOhz7xMZmlmj7/ZkB6g2mdrf9vZmrn5QfaDMCEf7fGoH7uraSNg1PVPn5AFSJNDLa b3acliMmHbZ3DrlEBHkfVeWBJ5AamC52480Rv8iHGLgkYcv0R2BpWHG0sr9cgFVDpQE3 HNbo0GACi8n5kRd/B86lnr0Y4ioiBu7XJV22HxjrTUiY5bGrkpYgSlND2Xy0p09OIO9r moDIQTOe0EvBnrTfzSniErOHv5ariwADibVxdheUWhTThe454pl4loaiDzxSPDpJqZLW JuYA== 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 l138si26929539qke.400.2017.08.01.08.02.59; Tue, 01 Aug 2017 08:03:00 -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 9598665BE8; Tue, 1 Aug 2017 15:02:59 +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 2A45C60C1E; Tue, 1 Aug 2017 15:01:15 +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 DD7C160BD7; Tue, 1 Aug 2017 15:01:08 +0000 (UTC) Received: from forward4h.cmail.yandex.net (forward4h.cmail.yandex.net [87.250.230.101]) by lists.linaro.org (Postfix) with ESMTPS id DDD636099C for ; Tue, 1 Aug 2017 15:00:35 +0000 (UTC) Received: from smtp2j.mail.yandex.net (smtp2j.mail.yandex.net [95.108.130.60]) by forward4h.cmail.yandex.net (Yandex) with ESMTP id 8661C20BD3 for ; Tue, 1 Aug 2017 18:00:34 +0300 (MSK) Received: from smtp2j.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp2j.mail.yandex.net (Yandex) with ESMTP id D85423EC11A0 for ; Tue, 1 Aug 2017 18:00:30 +0300 (MSK) Received: by smtp2j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id tyzQTD0Qgu-0Tbqs3Ui; Tue, 01 Aug 2017 18:00: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: Tue, 1 Aug 2017 18:00:05 +0300 Message-Id: <1501599610-28388-6-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501599610-28388-1-git-send-email-odpbot@yandex.ru> References: <1501599610-28388-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 90 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 90 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/90 ** Patch: https://github.com/Linaro/odp/pull/90.patch ** Base sha: bb0ca193f8c28036fdf8b3d6c8aa5d4f11980e6c ** Merge commit sha: dfef320840f96825686124135a6e509db80b7b82 **/ .../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 2207ac58..1edb5b7d 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 @@ -250,6 +251,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; } @@ -279,7 +281,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 41262cc2..5e1b4f8c 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;