From patchwork Tue Aug 1 15:00:03 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: 109177 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp1610288qge; Tue, 1 Aug 2017 08:05:18 -0700 (PDT) X-Received: by 10.200.53.251 with SMTP id l56mr9782114qtb.82.1501599918305; Tue, 01 Aug 2017 08:05:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501599918; cv=none; d=google.com; s=arc-20160816; b=EGj2D4lrOP5p1c9TUvydESlTj1qTyKB+aMgg3cWBVY0kDrSsbbtWy7ALa/XSHgDXaf +p+kIhmT6Dh/nYO6V9aV1PVkiQeHlORjJ8jF0FPkrfE5bZGDwqdYfUzjMy1nLhaGzFzp A/hhIWlk23cY12S4voV6Q348BonQEHJyyKqvPobTmEZ8W1Qj6DrxZcdAtOVzc+To0d0g 84B2xLtSuEOMwK7iVpKL4BWoGcdaQvfmkEqbNgbgUMp8OkzEChmEJ6W28sClcimXQBlT f5kf97h3n5k5KsDChwAOr3NqCIL/6lLwTITId3UojwZUzMs8mw0xuGLlk35sX/Yg6KPK 3bzg== 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=/4/M2/gZXVsl1ZhuQbgYBYg3pYZLGWn2bK1igDYs89g=; b=QtpuP3lPb7aOWOy8QMS4YtvCOX4Ab14eHcjvDn3lIUIMtCq9v39X7AnaVHXgMwa51N sZ6dMrMEkiF4JKdNuEeSAJuNP8pl+7VK/5coB7c0O3bmrO9mTYXRQeLIJcJcLDHcIY8+ Ytmw/8f2qau1365zKi0PeqQdio0oKSOR98FA7gxlTcTaYG6YkBzaT+A26ug0oU9a88PD Sc/SX2J6tMbctFhasjSXDyz6Uml9SNbOidRcXdSDqLEBpRvSp5T3iPOwUF7kajYW8WA/ Wga16/HmVziqwxhYoaKNgVmZh8BTgHC0rmfj7Z3SGAKKNFJ0738DTOa87SIrdvNSLrpE oEDA== 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 i28si27193920qta.182.2017.08.01.08.05.17; Tue, 01 Aug 2017 08:05:18 -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 C570365BE7; Tue, 1 Aug 2017 15:05: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 1D7CF65BC1; Tue, 1 Aug 2017 15:01:28 +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 1DC8160C1E; Tue, 1 Aug 2017 15:01:14 +0000 (UTC) Received: from forward1h.cmail.yandex.net (forward1h.cmail.yandex.net [87.250.230.16]) by lists.linaro.org (Postfix) with ESMTPS id E215A644E6 for ; Tue, 1 Aug 2017 15:00:35 +0000 (UTC) Received: from smtp2j.mail.yandex.net (smtp2j.mail.yandex.net [IPv6:2a02:6b8:0:801::ac]) by forward1h.cmail.yandex.net (Yandex) with ESMTP id 8678820FE1 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 CFFF43EC11BF for ; Tue, 1 Aug 2017 18:00:27 +0300 (MSK) Received: by smtp2j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id tyzQTD0Qgu-0Qb4ocuF; Tue, 01 Aug 2017 18:00:26 +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:03 +0300 Message-Id: <1501599610-28388-4-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 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: bb0ca193f8c28036fdf8b3d6c8aa5d4f11980e6c ** Merge commit sha: dfef320840f96825686124135a6e509db80b7b82 **/ 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 0542dd10..8c83966c 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -254,6 +254,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..988045e4 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 void packet_ref_inc(odp_packet_hdr_t *pkt_hdr) +{ + odp_atomic_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);