From patchwork Thu Jul 20 20:00:27 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: 108442 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2562694qge; Thu, 20 Jul 2017 13:04:33 -0700 (PDT) X-Received: by 10.55.101.135 with SMTP id z129mr6288451qkb.164.1500581073222; Thu, 20 Jul 2017 13:04:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500581073; cv=none; d=google.com; s=arc-20160816; b=mGSiTwZcaL5T4iUdCRY0gLH/1yc/JpVBN+cLSW++geFUWCloJc304qv2QBXh1cmAZF 5QYtAAWJ/LcTV8AIXOtYFsV2Srq6DLFcRXnHcbCXuE/pHnh4aU79bKw4XynQv6b2GNkc NTREaZ32x0fCkwjmlK277FnYoqtzOdtNaWhxuXmupDsgVKWSyWwkfq/N1uX4eR8dTOtI Xb3N4duoBUhf+Gl33kTaiEuARm2Wfcwgu/24NnRJ6EotM7ngMT0TJPoNx8KiLE7CQpwo n5vvgmkV0QqNCbPVPJZWYQHr8pP2KPrNEudAT6uH5SIe5Q1ZF8ZJCTYQ6mQ+e0SYufeg jDdw== 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=pnca+oq4eek0jkQWWQuxgrf/VUSFlnV2HX6/JhZBsPE=; b=BH3pJPYc6Lce7vnTRO0qn3HCEYeJPZvh3kec3YM4l4ovovXD84dg3RKvnhXKa6zkTQ QrbvDB1/1327l8akQCwYSyFeHt4t1G+chg5jYvb93a48i3gldlzDMRp18WubqjPOtv6U jliB7j+OReqxPe1gwOCpoqro3UCTHPcj0nacmwDXTvNitM0+htu79NvMouKt4hyUKm9g Z2nnb5Rbi2xoVdIiUxvtJ4dKXkY7C2wQb4KJZIi4SxdSmP7Vc0A1dtmgcS/bzXo0bRmP rMc4Y2V7+WCtgIjpETwnSurOxNzXTEHWb2ABltkR9xDGT8ch5sBHTLjePc2OU6v3UytP Pang== 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 h43si2527778qth.45.2017.07.20.13.04.32; Thu, 20 Jul 2017 13:04:33 -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 CB0CD65BBE; Thu, 20 Jul 2017 20:04:32 +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 89AF265BBD; Thu, 20 Jul 2017 20:01:55 +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 7DA5C65BBE; Thu, 20 Jul 2017 20:01:49 +0000 (UTC) Received: from forward4h.cmail.yandex.net (forward4h.cmail.yandex.net [87.250.230.101]) by lists.linaro.org (Postfix) with ESMTPS id 15D0F644E2 for ; Thu, 20 Jul 2017 20:00:43 +0000 (UTC) Received: from smtp4j.mail.yandex.net (smtp4j.mail.yandex.net [IPv6:2a02:6b8:0:1619::15:6]) by forward4h.cmail.yandex.net (Yandex) with ESMTP id 89DD520DE5 for ; Thu, 20 Jul 2017 23:00:41 +0300 (MSK) Received: from smtp4j.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp4j.mail.yandex.net (Yandex) with ESMTP id 5E31432410D5 for ; Thu, 20 Jul 2017 23:00:40 +0300 (MSK) Received: by smtp4j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 0hzMV06TG7-0eEujjtA; Thu, 20 Jul 2017 23:00:40 +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 23:00:27 +0300 Message-Id: <1500580834-26476-4-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500580834-26476-1-git-send-email-odpbot@yandex.ru> References: <1500580834-26476-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 82 Subject: [lng-odp] [PATCH v4 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 82 (Bill-Fischofer-Linaro:pktrefs) ** https://github.com/Linaro/odp/pull/82 ** Patch: https://github.com/Linaro/odp/pull/82.patch ** Base sha: 3eeb249a4774f12d2d16ca349a591654eae620ae ** Merge commit sha: f6e0d4b8b10f1803fb4513254c404df31e3f9f3f **/ 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);