From patchwork Sun Mar 5 12:21:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 94900 Delivered-To: patch@linaro.org Received: by 10.140.82.71 with SMTP id g65csp988602qgd; Sun, 5 Mar 2017 04:23:54 -0800 (PST) X-Received: by 10.55.97.6 with SMTP id v6mr11766669qkb.80.1488716634449; Sun, 05 Mar 2017 04:23:54 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id c139si13383943qka.1.2017.03.05.04.23.54; Sun, 05 Mar 2017 04:23:54 -0800 (PST) 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 1641163D24; Sun, 5 Mar 2017 12:23:54 +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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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 5CFE760A45; Sun, 5 Mar 2017 12:22:04 +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 1927663D1D; Sun, 5 Mar 2017 12:22:01 +0000 (UTC) Received: from mail-wr0-f182.google.com (mail-wr0-f182.google.com [209.85.128.182]) by lists.linaro.org (Postfix) with ESMTPS id 1B04960AD1 for ; Sun, 5 Mar 2017 12:21:34 +0000 (UTC) Received: by mail-wr0-f182.google.com with SMTP id l37so99744372wrc.1 for ; Sun, 05 Mar 2017 04:21:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UKK3UtL+uFp5/lJxu3ygq8d+bIs0vlTBqVv1cd0GFn4=; b=mD5Oh8azHNH4Zn7PEJUG29U44q9MceRBdoDhE1HhBWSAgUjaRUwZxKaHVED+AOOG65 ZNTY+THmzgqMX7Izz3SuOqlsNBaSQ85Lkh2RnGGBYvW4L/fH3uuat/2mwrtTn6l6U50x iA/Y8uQI+3yB8+X2725BFpG3tgIUBjHIGBh8DV0yep83HYK752AtP6xRvYaJ0uZDnQdL lqE7Pi76tOhslP24kHhH+t2f448b29f1IoIqnv0rYO2Y4R/CJmj3ypwoWb3/aR6IpNGR c+PpSrACaIf4AA5MqjRHmesN+u9TcOF/gaigAYgGmCYf1deXOaPEVeOVYCNksV+CDu9r q0Xg== X-Gm-Message-State: AMke39m080N+M70t3FjFSSqgOw/tGnxBf0ABXbS/nwAhFXGCESLhLjPpNgmDss1ZCvOTZkUPcvniUA== X-Received: by 10.223.151.217 with SMTP id t25mr11511282wrb.95.1488716492913; Sun, 05 Mar 2017 04:21:32 -0800 (PST) Received: from Ubuntu15.localdomain ([109.74.56.122]) by smtp.gmail.com with ESMTPSA id 127sm10686971wmt.20.2017.03.05.04.21.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 05 Mar 2017 04:21:32 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Sun, 5 Mar 2017 13:21:19 +0100 Message-Id: <1488716485-15002-6-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1488716485-15002-1-git-send-email-bill.fischofer@linaro.org> References: <1488716485-15002-1-git-send-email-bill.fischofer@linaro.org> Subject: [lng-odp] [PATCH 05/11] 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" Signed-off-by: Bill Fischofer --- platform/linux-generic/include/odp_packet_internal.h | 19 +++++++++++++++++++ platform/linux-generic/odp_packet.c | 10 ++++++++++ 2 files changed, 29 insertions(+) -- 2.5.0 diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index 31d46df..39deae2 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -196,6 +196,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 067d0fc..4bbb619 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -57,6 +57,16 @@ static inline odp_buffer_t buffer_handle(odp_packet_hdr_t *pkt_hdr) return pkt_hdr->buf_hdr.handle.handle; } +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);