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);