From patchwork Thu Feb 16 20:20:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 94106 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp2678775obz; Thu, 16 Feb 2017 12:20:48 -0800 (PST) X-Received: by 10.200.56.164 with SMTP id f33mr4392121qtc.158.1487276448676; Thu, 16 Feb 2017 12:20:48 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id c69si6002194qkj.81.2017.02.16.12.20.48; Thu, 16 Feb 2017 12:20:48 -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 439AE6072A; Thu, 16 Feb 2017 20:20:48 +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_H3, RCVD_IN_MSPIKE_WL, 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 2F2AE6072A; Thu, 16 Feb 2017 20:20:44 +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 CADBE60796; Thu, 16 Feb 2017 20:20:40 +0000 (UTC) Received: from mail-ot0-f176.google.com (mail-ot0-f176.google.com [74.125.82.176]) by lists.linaro.org (Postfix) with ESMTPS id C2404606A0 for ; Thu, 16 Feb 2017 20:20:39 +0000 (UTC) Received: by mail-ot0-f176.google.com with SMTP id 73so18996368otj.0 for ; Thu, 16 Feb 2017 12:20:39 -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; bh=6HX7N3VzitFYU3O/4ru2sMiKEKHT/lWJSWqXkeZIpds=; b=rYVYeDCwG7Lip0qn07+uqvtEuaszJJGUzfkibsNMHL2SnIprSzFx8cVxBH0Zc75FOJ UoJab7Ae9iIF5Xo/bN/aWjLKhpNVZJX1TRC9uUNVB2/v4gIMf8BK1RI2b+/qKEyOisim xpIA9qisri7QX8TfjBTawTFazUEUAtrPvQ7gGPcHcCV/dJxUDk8VW6/t3QU13b+Lic0J DgEueEXzbTrP1NXgnA3LeFXF1wDOi8ZIXWfkJTIZ78d0soHqyWd86/PZmPAZxzVn6Fg3 eza/QaLWZ+P2TI0ySgGcpLyYogs2JrY2GhIkuLX8HgzAsTFXT862k3RgZEWN+52KDEd8 U1Gw== X-Gm-Message-State: AMke39mVgA3DRxDxwsZQMfbgrXJXR5VksYrfaixY/fWItysJKFVL2if9vPu9ZBYcjd9YehDrNkM= X-Received: by 10.157.5.144 with SMTP id 16mr2789519otd.2.1487276439004; Thu, 16 Feb 2017 12:20:39 -0800 (PST) Received: from localhost.localdomain (cpe-70-121-83-241.austin.res.rr.com. [70.121.83.241]) by smtp.gmail.com with ESMTPSA id p124sm3401475oia.22.2017.02.16.12.20.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Feb 2017 12:20:38 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Thu, 16 Feb 2017 14:20:35 -0600 Message-Id: <20170216202035.30051-1-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.12.0.rc1 Subject: [lng-odp] [API-NEXT PATCHv2] linux-generic: packet: minimize use of atomic ops on free paths 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" While reference counts are implemented as atomics, try to avoid unnecessary atomic decrement operations in free paths. This streamlines free processing in the expected case where packets do not contain shared segments. Signed-off-by: Bill Fischofer --- Changes for v2 - avoid potential race condition in decrement processing platform/linux-generic/odp_packet.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) -- 2.12.0.rc1 diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 4d2cde12..81bbcedd 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -477,7 +477,7 @@ static inline void free_bufs(odp_packet_hdr_t *pkt_hdr, int first, int num) for (i = 0, nfree = 0; i < num; i++) { odp_packet_hdr_t *hdr = pkt_hdr->buf_hdr.seg[first + i].hdr; - if (packet_ref_dec(hdr) == 1) + if (packet_ref_count(hdr) == 1 || packet_ref_dec(hdr) == 1) buf[nfree++] = buffer_handle(hdr); } @@ -499,7 +499,8 @@ static inline odp_packet_hdr_t *free_segments(odp_packet_hdr_t *pkt_hdr, for (i = 0, nfree = 0; i < num; i++) { new_hdr = pkt_hdr->buf_hdr.seg[i].hdr; - if (packet_ref_dec(new_hdr) == 1) + if (packet_ref_count(new_hdr) == 1 || + packet_ref_dec(new_hdr) == 1) buf[nfree++] = buffer_handle(new_hdr); } @@ -643,12 +644,12 @@ static inline odp_packet_hdr_t *packet_free_to_list(odp_packet_hdr_t *pkt_hdr, int num_seg, i; do { - ref_count = packet_ref_count(pkt_hdr) - 1; + ref_count = packet_ref_count(pkt_hdr); num_seg = pkt_hdr->buf_hdr.segcount; ref_hdr = pkt_hdr->ref_hdr; if (odp_likely((CONFIG_PACKET_MAX_SEGS == 1 || num_seg == 1) && - ref_count == 0)) { + ref_count == 1)) { if (*nfree >= nbufs) break; @@ -661,11 +662,12 @@ static inline odp_packet_hdr_t *packet_free_to_list(odp_packet_hdr_t *pkt_hdr, odp_packet_hdr_t *hdr = pkt_hdr->buf_hdr.seg[i].hdr; - if (packet_ref_dec(hdr) == 1) + if (packet_ref_count(hdr) == 1 || + packet_ref_dec(hdr) == 1) buf[(*nfree)++] = buffer_handle(hdr); } - if (ref_count == 1) + if (ref_count == 2) pkt_hdr->unshared_len = pkt_hdr->frame_len; } @@ -682,18 +684,18 @@ static inline void packet_free(odp_packet_hdr_t *pkt_hdr) int num_seg; do { - ref_count = packet_ref_count(pkt_hdr) - 1; + ref_count = packet_ref_count(pkt_hdr); num_seg = pkt_hdr->buf_hdr.segcount; ref_hdr = pkt_hdr->ref_hdr; if (odp_likely((CONFIG_PACKET_MAX_SEGS == 1 || num_seg == 1) && - ref_count == 0)) { + ref_count == 1)) { buffer_free_multi((odp_buffer_t *) &pkt_hdr->buf_hdr.handle.handle, 1); } else { free_bufs(pkt_hdr, 0, num_seg); - if (ref_count == 1) + if (ref_count == 2) pkt_hdr->unshared_len = pkt_hdr->frame_len; }