From patchwork Thu Jul 20 18:00:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 108434 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2452360qge; Thu, 20 Jul 2017 11:08:49 -0700 (PDT) X-Received: by 10.55.126.198 with SMTP id z189mr5980812qkc.299.1500574129732; Thu, 20 Jul 2017 11:08:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500574129; cv=none; d=google.com; s=arc-20160816; b=dDpbD7/fFPQbVhNPcUAhgZ+BbcZEO4wu02lLDneA6Os4qa0e7Pzse/IvaaoEWGSwww qbI990JOkcEg6qAgoc/prflwmVyYAdpF31kb0lJYFsyJplLY0itozFG36AU/gb/L1Ip6 1RmqOHdScLvrNvhGsNhiBYgsBRy/cfskMEygWaMlpip5XQiF2IJDIRiAyDsrsVHp2gpF 4ND4Ti/q5ZmeRHoNyfY6wEmDwhIEQKZNIQxwQnQ1noePBjLkEJ0/igmUOOyB6WK2swwW 74Cr6m6LInVivTWCcFdl9lVrX71EoIX+7lsf+KID3dhZxHrKmo1WNMedCzpptTe0svZH SeSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=Alp/JugAihJuDJYkhfPe6RK32SCZZ55IvHdOObdaZ50=; b=ltiV8Sc9wTmoRtNb6AlUYaCLxeBvug8X8dc0LK1nl2aoi390NSFkCNVLe9y6mWYR+i MxgaE+sM0XFif+ZlFgsHnuSmdBRdAag/nXf5DQmxXhWQSCBdfTC4Ep4Am29CjkRj2dpl BswmxEYOYDmPgypaeOVe9QAdHjLkfu+pcp3HoBMXdKaIy89KlICtoScYRR5ALNEhY+s9 QiJGz84oF+37KJUpH6nGAZEqgZPXkCgvUx7h1NL/lYqz62drpsTszwsrUiJX+OCf9PhL I/EaACMHWe6fJjVnSmicNPUE+BKwiMDPO0qaF5nN7VXSkmNtNPFcB9/BQ0eNqvF0jdBd +Gvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id t187si2366275qkh.150.2017.07.20.11.08.49; Thu, 20 Jul 2017 11:08:49 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 58C0F60D25; Thu, 20 Jul 2017 18:08:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id EC42364FD5; Thu, 20 Jul 2017 18:01:14 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 6E9EA60CE2; Thu, 20 Jul 2017 18:01:06 +0000 (UTC) Received: from forward4h.cmail.yandex.net (forward4h.cmail.yandex.net [87.250.230.101]) by lists.linaro.org (Postfix) with ESMTPS id 6F20C60CE0 for ; Thu, 20 Jul 2017 18:00:22 +0000 (UTC) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [IPv6:2a02:6b8:0:1402::15:6]) by forward4h.cmail.yandex.net (Yandex) with ESMTP id 6C0A420DDB for ; Thu, 20 Jul 2017 21:00:21 +0300 (MSK) Received: from smtp4p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp4p.mail.yandex.net (Yandex) with ESMTP id 2A93C6501177 for ; Thu, 20 Jul 2017 21:00:20 +0300 (MSK) Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id a46hdQ3693-0KaGv8Te; Thu, 20 Jul 2017 21:00:20 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 20 Jul 2017 21:00:07 +0300 Message-Id: <1500573607-18783-11-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> References: <1500573607-18783-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 82 Subject: [lng-odp] [PATCH v3 10/10] linux-generic: packet: enable zero-copy reference creation X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Bill Fischofer Signed-off-by: Bill Fischofer --- /** Email created from pull request 82 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/82 ** Patch: https://github.com/Linaro/odp/pull/82.patch ** Base sha: 95ba4b394009d92c29c2e22f0776e90bb4c6edec ** Merge commit sha: 01d093d362af5a52e079c622a99ae3495f68b64c **/ platform/linux-generic/odp_packet.c | 172 +++++++++++++++++++++--------------- 1 file changed, 103 insertions(+), 69 deletions(-) diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index a5abf1ba..35a8c645 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -1710,6 +1710,109 @@ int odp_packet_split(odp_packet_t *pkt, uint32_t len, odp_packet_t *tail) } /* + * References + */ + +static inline void packet_ref(odp_packet_hdr_t *pkt_hdr) +{ + uint32_t i; + odp_packet_hdr_t *hdr; + + do { + for (i = 0; i < pkt_hdr->buf_hdr.segcount; i++) { + hdr = pkt_hdr->buf_hdr.seg[i].hdr; + packet_ref_inc(hdr); + } + + pkt_hdr = pkt_hdr->ref_hdr; + } while (pkt_hdr); +} + +static inline odp_packet_t packet_splice(odp_packet_hdr_t *pkt_hdr, + uint32_t offset, + odp_packet_hdr_t *ref_hdr) +{ + /* Catch attempted references to stale handles in debug builds */ + ODP_ASSERT(packet_ref_count(pkt_hdr) > 0); + + /* Splicing is from the last section of src pkt */ + while (ref_hdr->ref_hdr) + ref_hdr = ref_hdr->ref_hdr; + + /* Find section where splice begins */ + while (offset >= pkt_hdr->frame_len && pkt_hdr->ref_hdr) { + offset -= (pkt_hdr->frame_len - pkt_hdr->ref_offset); + offset += (pkt_hdr->ref_hdr->frame_len - pkt_hdr->ref_len); + pkt_hdr = pkt_hdr->ref_hdr; + } + + ref_hdr->ref_hdr = pkt_hdr; + ref_hdr->ref_offset = offset; + ref_hdr->ref_len = pkt_hdr->frame_len; + + if (packet_ref_count(pkt_hdr) == 1 || offset < pkt_hdr->unshared_len) + pkt_hdr->unshared_len = offset; + + packet_ref(pkt_hdr); + return packet_handle(ref_hdr); +} + +odp_packet_t odp_packet_ref_static(odp_packet_t pkt) +{ + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); + + packet_ref(pkt_hdr); + pkt_hdr->unshared_len = 0; + return pkt; +} + +odp_packet_t odp_packet_ref(odp_packet_t pkt, uint32_t offset) +{ + odp_packet_t hdr; + odp_packet_hdr_t *pkt_hdr; + + if (pkt == ODP_PACKET_INVALID) + return ODP_PACKET_INVALID; + + pkt_hdr = packet_hdr(pkt); + if (offset >= packet_len(pkt_hdr)) + return ODP_PACKET_INVALID; + + hdr = odp_packet_alloc(odp_packet_pool(pkt), 0); + + if (hdr == ODP_PACKET_INVALID) + return ODP_PACKET_INVALID; + + return packet_splice(pkt_hdr, offset, packet_hdr(hdr)); +} + +odp_packet_t odp_packet_ref_pkt(odp_packet_t pkt, uint32_t offset, + odp_packet_t hdr) +{ + odp_packet_hdr_t *pkt_hdr; + + if (pkt == ODP_PACKET_INVALID || + hdr == ODP_PACKET_INVALID || + pkt == hdr) + return ODP_PACKET_INVALID; + + ODP_ASSERT(odp_packet_has_ref(hdr) == 0); + + pkt_hdr = packet_hdr(pkt); + if (offset >= packet_len(pkt_hdr)) + return ODP_PACKET_INVALID; + + return packet_splice(pkt_hdr, offset, packet_hdr(hdr)); +} + +int odp_packet_has_ref(odp_packet_t pkt) +{ + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); + + return pkt_hdr->ref_hdr != NULL || packet_ref_count(pkt_hdr) > 1; +} + +/* * * Copy * ******************************************************** @@ -2353,75 +2456,6 @@ uint64_t odp_packet_seg_to_u64(odp_packet_seg_t hdl) return _odp_pri(hdl); } -odp_packet_t odp_packet_ref_static(odp_packet_t pkt) -{ - return odp_packet_copy(pkt, odp_packet_pool(pkt)); -} - -odp_packet_t odp_packet_ref(odp_packet_t pkt, uint32_t offset) -{ - odp_packet_t new; - int ret; - - new = odp_packet_copy(pkt, odp_packet_pool(pkt)); - - if (new == ODP_PACKET_INVALID) { - ODP_ERR("copy failed\n"); - return ODP_PACKET_INVALID; - } - - ret = odp_packet_trunc_head(&new, offset, NULL, NULL); - - if (ret < 0) { - ODP_ERR("trunk_head failed\n"); - odp_packet_free(new); - return ODP_PACKET_INVALID; - } - - return new; -} - -odp_packet_t odp_packet_ref_pkt(odp_packet_t pkt, uint32_t offset, - odp_packet_t hdr) -{ - odp_packet_t new; - int ret; - - new = odp_packet_copy(pkt, odp_packet_pool(pkt)); - - if (new == ODP_PACKET_INVALID) { - ODP_ERR("copy failed\n"); - return ODP_PACKET_INVALID; - } - - if (offset) { - ret = odp_packet_trunc_head(&new, offset, NULL, NULL); - - if (ret < 0) { - ODP_ERR("trunk_head failed\n"); - odp_packet_free(new); - return ODP_PACKET_INVALID; - } - } - - ret = odp_packet_concat(&hdr, new); - - if (ret < 0) { - ODP_ERR("concat failed\n"); - odp_packet_free(new); - return ODP_PACKET_INVALID; - } - - return hdr; -} - -int odp_packet_has_ref(odp_packet_t pkt) -{ - (void)pkt; - - return 0; -} - /* Include non-inlined versions of API functions */ #if ODP_ABI_COMPAT == 1 #include