From patchwork Thu Feb 16 20:15:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 94105 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2675747qgi; Thu, 16 Feb 2017 12:15:52 -0800 (PST) X-Received: by 10.107.52.211 with SMTP id b202mr3797832ioa.150.1487276152600; Thu, 16 Feb 2017 12:15:52 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id h68si8273557ith.114.2017.02.16.12.15.51; Thu, 16 Feb 2017 12:15:52 -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 D145D60905; Thu, 16 Feb 2017 20:15:51 +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 DFD39607F7; Thu, 16 Feb 2017 20:15:47 +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 D919E608B0; Thu, 16 Feb 2017 20:15:44 +0000 (UTC) Received: from mail-oi0-f47.google.com (mail-oi0-f47.google.com [209.85.218.47]) by lists.linaro.org (Postfix) with ESMTPS id 802406013B for ; Thu, 16 Feb 2017 20:15:43 +0000 (UTC) Received: by mail-oi0-f47.google.com with SMTP id s131so891248oie.1 for ; Thu, 16 Feb 2017 12:15:43 -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=Fv2+Z5nsnGukapMJb5TKjrhzKm+dvH/aqz1fWmdSIG4=; b=VQIXZl11Jr+nenCNZN3qdA/RFm+4A2fLEcbkW7feOxWL43OaQIVWELBiZ9nT6YuRIU R+aOUJ2VgYQKFgXJUPHhFxz5LcRF5xyLLluCQYtwBfQAk1yovgnynipe9k7MTjCUpUOD R5U+dIawTk1qabOhpANPP1ajY7WEr1HZVuvS2TTLEZbNKxfVAVljF39I0OLnIAa6LzdL yZ7MnWa30vmLRXYclkU34w4jE3ZNLCw2qvIq2xOGGZ4x1z3wAmg0F2BDlpuqvaMIfLCu 03WeDsfggj/PYHF7xALqcNZ4osBZ4FLA3O6G+6DmW/9LfTZ2W/tGilGn56d/3oom33Ms jw+A== X-Gm-Message-State: AMke39kKYwnDqENILauYiRZylrVnSDFpn5zSfT3mFL/kI2tx8l+5yowi1hj5mr6x0SEiBfBv9fc= X-Received: by 10.202.207.202 with SMTP id f193mr2505745oig.81.1487276142911; Thu, 16 Feb 2017 12:15:42 -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 f3sm3415080otc.32.2017.02.16.12.15.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Feb 2017 12:15:41 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Thu, 16 Feb 2017 14:15:38 -0600 Message-Id: <20170216201538.23131-1-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.12.0.rc1 Subject: [lng-odp] [API-NEXT PATCH] 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 --- platform/linux-generic/odp_packet.c | 24 +++++++++++++++--------- 1 file changed, 15 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..0019fae9 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -477,8 +477,10 @@ 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) buf[nfree++] = buffer_handle(hdr); + else + packet_ref_dec(hdr); } if (nfree > 0) @@ -499,8 +501,10 @@ 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) buf[nfree++] = buffer_handle(new_hdr); + else + packet_ref_dec(new_hdr); } /* First remaining segment is the new packet descriptor */ @@ -643,12 +647,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 +665,13 @@ 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) buf[(*nfree)++] = buffer_handle(hdr); + else + packet_ref_dec(hdr); } - if (ref_count == 1) + if (ref_count == 2) pkt_hdr->unshared_len = pkt_hdr->frame_len; } @@ -682,18 +688,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; }