Message ID | 20221024051744.GA48642@debian |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2917033wru; Tue, 1 Nov 2022 05:08:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6BUIA2CfTZa8vpyVNvrHK5PsUsemvwn4ybc//wpytSYSf6vNa5I/f5aS6RmOQZPmpRpdLv X-Received: by 2002:a17:902:a502:b0:186:aed2:f69d with SMTP id s2-20020a170902a50200b00186aed2f69dmr19446469plq.46.1667304505852; Tue, 01 Nov 2022 05:08:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667304505; cv=none; d=google.com; s=arc-20160816; b=WfNXa7OM5c37CsH4JkH2GLlHpbSfrD+jGnT8Yj3fNNI+y4HsQkxOgrF0E6IrLqeJqk Iqkh2NE1d44ErKTyEqGjBPCNwZCzlR18mtBj+PVb3lnkEktYufp0bQX1d5vAuPl/x45M D4AB6C47BJiIizw/qrDu5W1JJhrwJAcq/blnh4lPQySQEgAu3aHj4Mg4js2W8aWdK9MV ly1zaB0TH/e6foaQFa5Kvd8kmJwWy1z1HQWspuDfmZmoJiFVuQsN2BxXanYoIE3LduLu FeGLFmrCLhYa+SakzGijIR+RkRNjo57y3jN86qD6N6vWuEK1w90RBW/8yokjNGxDK9zp hZlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:content-disposition:mime-version :message-id:subject:to:from:date:dkim-signature; bh=dDiFLbcCPs9I3+qSQ2/UHfejkBwzWQ533NU4ZUsGCPY=; b=A+NcvOim+FNXcLs7LAj26Mug5h7BLpJMSy1y2jWA3l6UONDFZ72V0JVdsf/jgqkoCw spBGwXejzXfvcrcq80BXYMSzz6tA/ETymSv6/RidV/o6LH049p5CuIDD05w7uibCMESr iQ44IwG1HlCxPEQVfO1Rao/WxzhGfrAhoE7Vva8YlLXa3LmzCjHR8wh1i1Eiiro6Nf0w Rxyd/mlIlQAcEhAQ8TrWQv08R9fv4l9ZpGDQc8zA5rsLpNB/kxcihWbZwhnKFDuz/wC6 EocFCtviB5PTUT4zLyoX43xB9cY5zBlMHidTxgmc8xl/2agBMOwTJ52vifKmhy5Ydsa9 bVTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AECDTUUM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u8-20020a17090341c800b0017f5ea2e8easi13672054ple.357.2022.11.01.05.08.11; Tue, 01 Nov 2022 05:08:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AECDTUUM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230419AbiKAMBn (ORCPT <rfc822;kartikey406@gmail.com> + 99 others); Tue, 1 Nov 2022 08:01:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbiKAMBk (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 1 Nov 2022 08:01:40 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5630A63F0; Tue, 1 Nov 2022 05:01:39 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id h9so19857368wrt.0; Tue, 01 Nov 2022 05:01:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=user-agent:content-disposition:mime-version:message-id:subject:to :from:date:from:to:cc:subject:date:message-id:reply-to; bh=dDiFLbcCPs9I3+qSQ2/UHfejkBwzWQ533NU4ZUsGCPY=; b=AECDTUUM7wPd78XMLMkzvlsVEc+oowtP7u+lfBMn+oxn2MelQNpZ5WiTFK+33zC9oQ AoIHVqndwGCRvMZwS0ecfzu2a1jw0yI15Y+BULVfPJQNRQIcq13MojBOtutuZIj5W+V/ GaZH5hxLK5yG9DZKgcgNu6/WqrUd7+meIfaLdVf96San3sh8Nxy9Mej8yr+lcIKGiqX7 80MxdWmkR0YhVa/FrIi3kIZvXHLjsusAGUrPXZDRdJ4Rzo0RLyoLOZyIQgm1N9F8I1HI zVRSO+lZurvyBZ8qJrme6uzzK7Ewv+LR4m97k8uKsXnLeKURdMMTU/qMEXRDrpJUTytB PrxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:content-disposition:mime-version:message-id:subject:to :from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dDiFLbcCPs9I3+qSQ2/UHfejkBwzWQ533NU4ZUsGCPY=; b=GGvcz1uauXsZIaX7KvpyKauRp5Pgrhe4CXWR7HrcgoL1dgxopmUsU1DA6p8fyEBfdx n7bC4foXOQudM26Ms72mIyc0hRbmeDMtlTPnwGxRhOyrFdJtwR6QDxqfuWx+1d85n9UK p16sEOZuOJncVSa+iobcmLa+rxr1QNGNZjsd9zvFD3jyFFYy4p8VcvOat4Wu5cn8Mdiz jEXN0F82btvYFsm60ZiumA/02IM94Zu8uRUJZsWKg43cD1W3g/vYvcHcD7pEm142JEy7 WaB6kN8gD2CLFrF6Nt47ahEfT4zoJm74MX2ZFEpDsQw0rKgTdKOPbUK4PqjfsIdj19ax 2lqg== X-Gm-Message-State: ACrzQf2leJwQBrEoNNXy6eAZwVXfv5kaR8EwtTzIjekhhAaJHgzl00DB rPSKsuz/DuotnXFQRCxqyxk= X-Received: by 2002:adf:dbc5:0:b0:22c:c605:3b81 with SMTP id e5-20020adfdbc5000000b0022cc6053b81mr11287837wrj.218.1667304097843; Tue, 01 Nov 2022 05:01:37 -0700 (PDT) Received: from debian ([89.238.191.199]) by smtp.gmail.com with ESMTPSA id m13-20020adffe4d000000b0022afcc11f65sm9911489wrs.47.2022.11.01.05.01.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Nov 2022 05:01:37 -0700 (PDT) Date: Mon, 24 Oct 2022 07:17:49 +0200 From: Richard Gobert <richardbgobert@gmail.com> To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lixiaoyan@google.com, alexanderduyck@fb.com, richardbgobert@gmail.com, steffen.klassert@secunet.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next] gro: avoid checking for a failed search Message-ID: <20221024051744.GA48642@debian> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=1.3 required=5.0 tests=BAYES_00,DATE_IN_PAST_96_XX, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748295489087086103?= X-GMAIL-MSGID: =?utf-8?q?1748295489087086103?= |
Series |
[net-next] gro: avoid checking for a failed search
|
|
Commit Message
Richard Gobert
Oct. 24, 2022, 5:17 a.m. UTC
After searching for a protocol handler in dev_gro_receive, checking for
failure is redundant. Skip the failure code after finding the
corresponding handler.
Signed-off-by: Richard Gobert <richardbgobert@gmail.com>
---
net/core/gro.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
Comments
On Mon, 24 Oct 2022 07:17:49 +0200 Richard Gobert wrote: > After searching for a protocol handler in dev_gro_receive, checking for > failure is redundant. Skip the failure code after finding the > corresponding handler. Why does it matter? You see a measurable perf win? Please fix the data on your system when you repost.
> Why does it matter? You see a measurable perf win?
In the common case, we will exit the loop with a break,
so this patch eliminates an unnecessary check.
On some architectures this optimization might be done
automatically by the compiler, but I think it will be better
to make it explicit here. Although on x86 this optimization
happens automatically, I noticed that on my build target
(ARM/GCC) this does change the binary.
On Wed, Nov 2, 2022 at 9:46 AM Richard Gobert <richardbgobert@gmail.com> wrote: > > > Why does it matter? You see a measurable perf win? > > In the common case, we will exit the loop with a break, > so this patch eliminates an unnecessary check. > > On some architectures this optimization might be done > automatically by the compiler, but I think it will be better > to make it explicit here. Although on x86 this optimization > happens automatically, I noticed that on my build target > (ARM/GCC) this does change the binary. What about taking this as an opportunity to reduce the indentation level by one tab ? Untested patch: diff --git a/net/core/gro.c b/net/core/gro.c index bc9451743307bc380cca96ae6995aa0a3b83d185..ddfe92c9a5e869d241931b72d6b3426a0e858468 100644 --- a/net/core/gro.c +++ b/net/core/gro.c @@ -491,43 +491,44 @@ static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff list_for_each_entry_rcu(ptype, head, list) { if (ptype->type != type || !ptype->callbacks.gro_receive) continue; + goto found_ptype; + } + rcu_read_unlock(); + goto normal; - skb_set_network_header(skb, skb_gro_offset(skb)); - skb_reset_mac_len(skb); - BUILD_BUG_ON(sizeof_field(struct napi_gro_cb, zeroed) != sizeof(u32)); - BUILD_BUG_ON(!IS_ALIGNED(offsetof(struct napi_gro_cb, zeroed), - sizeof(u32))); /* Avoid slow unaligned acc */ - *(u32 *)&NAPI_GRO_CB(skb)->zeroed = 0; - NAPI_GRO_CB(skb)->flush = skb_has_frag_list(skb); - NAPI_GRO_CB(skb)->is_atomic = 1; - NAPI_GRO_CB(skb)->count = 1; - if (unlikely(skb_is_gso(skb))) { - NAPI_GRO_CB(skb)->count = skb_shinfo(skb)->gso_segs; - /* Only support TCP at the moment. */ - if (!skb_is_gso_tcp(skb)) - NAPI_GRO_CB(skb)->flush = 1; - } - - /* Setup for GRO checksum validation */ - switch (skb->ip_summed) { - case CHECKSUM_COMPLETE: - NAPI_GRO_CB(skb)->csum = skb->csum; - NAPI_GRO_CB(skb)->csum_valid = 1; - break; - case CHECKSUM_UNNECESSARY: - NAPI_GRO_CB(skb)->csum_cnt = skb->csum_level + 1; - break; - } +found_ptype: + skb_set_network_header(skb, skb_gro_offset(skb)); + skb_reset_mac_len(skb); + BUILD_BUG_ON(sizeof_field(struct napi_gro_cb, zeroed) != sizeof(u32)); + BUILD_BUG_ON(!IS_ALIGNED(offsetof(struct napi_gro_cb, zeroed), + sizeof(u32))); /* Avoid slow unaligned acc */ + *(u32 *)&NAPI_GRO_CB(skb)->zeroed = 0; + NAPI_GRO_CB(skb)->flush = skb_has_frag_list(skb); + NAPI_GRO_CB(skb)->is_atomic = 1; + NAPI_GRO_CB(skb)->count = 1; + if (unlikely(skb_is_gso(skb))) { + NAPI_GRO_CB(skb)->count = skb_shinfo(skb)->gso_segs; + /* Only support TCP at the moment. */ + if (!skb_is_gso_tcp(skb)) + NAPI_GRO_CB(skb)->flush = 1; + } - pp = INDIRECT_CALL_INET(ptype->callbacks.gro_receive, - ipv6_gro_receive, inet_gro_receive, - &gro_list->list, skb); + /* Setup for GRO checksum validation */ + switch (skb->ip_summed) { + case CHECKSUM_COMPLETE: + NAPI_GRO_CB(skb)->csum = skb->csum; + NAPI_GRO_CB(skb)->csum_valid = 1; + break; + case CHECKSUM_UNNECESSARY: + NAPI_GRO_CB(skb)->csum_cnt = skb->csum_level + 1; break; } - rcu_read_unlock(); - if (&ptype->list == head) - goto normal; + pp = INDIRECT_CALL_INET(ptype->callbacks.gro_receive, + ipv6_gro_receive, inet_gro_receive, + &gro_list->list, skb); + + rcu_read_unlock(); if (PTR_ERR(pp) == -EINPROGRESS) { ret = GRO_CONSUMED;
On Wed, Nov 2, 2022 at 11:20 AM Eric Dumazet <edumazet@google.com> wrote: > > On Wed, Nov 2, 2022 at 9:46 AM Richard Gobert <richardbgobert@gmail.com> wrote: > > > > > Why does it matter? You see a measurable perf win? > > > > In the common case, we will exit the loop with a break, > > so this patch eliminates an unnecessary check. > > > > On some architectures this optimization might be done > > automatically by the compiler, but I think it will be better > > to make it explicit here. Although on x86 this optimization > > happens automatically, I noticed that on my build target > > (ARM/GCC) this does change the binary. > > What about taking this as an opportunity to reduce the indentation > level by one tab ? > > Untested patch: > > diff --git a/net/core/gro.c b/net/core/gro.c > index bc9451743307bc380cca96ae6995aa0a3b83d185..ddfe92c9a5e869d241931b72d6b3426a0e858468 > 100644 > --- a/net/core/gro.c > +++ b/net/core/gro.c > @@ -491,43 +491,44 @@ static enum gro_result dev_gro_receive(struct > napi_struct *napi, struct sk_buff > list_for_each_entry_rcu(ptype, head, list) { > if (ptype->type != type || !ptype->callbacks.gro_receive) > continue; > + goto found_ptype; > + } > + rcu_read_unlock(); > + goto normal; Or even better: list_for_each_entry_rcu(ptype, head, list) { if (ptype->type == type && ptype->callbacks.gro_receive) goto found_ptype; } rcu_read_unlock(); goto normal;
diff --git a/net/core/gro.c b/net/core/gro.c index bc9451743307..a4e1b5a5be64 100644 --- a/net/core/gro.c +++ b/net/core/gro.c @@ -522,13 +522,13 @@ static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff pp = INDIRECT_CALL_INET(ptype->callbacks.gro_receive, ipv6_gro_receive, inet_gro_receive, &gro_list->list, skb); - break; + rcu_read_unlock(); + goto found; } rcu_read_unlock(); + goto normal; - if (&ptype->list == head) - goto normal; - +found: if (PTR_ERR(pp) == -EINPROGRESS) { ret = GRO_CONSUMED; goto ok;