Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp250148rwi; Wed, 2 Nov 2022 11:27:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Dov+/z3Q6evIYVeUsmQN4U5jKZnHK7HAKy0syqZHxcxH/SQWBOR2ZXy4RByjgT9xiBUwL X-Received: by 2002:a17:907:31ca:b0:780:2170:e08c with SMTP id xf10-20020a17090731ca00b007802170e08cmr24586213ejb.145.1667413666227; Wed, 02 Nov 2022 11:27:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667413666; cv=none; d=google.com; s=arc-20160816; b=BEi/4wRdfwraZXhzhZtI8CJPPPtQqfUBgQsepMAXmYwFSHFzDdjNTUGyTpZJwYdji9 ahdC5nDf7n9sWEL3Qn0SI9D7koHtMsO4JoNoixoPuVwVlMPWPn5JOmOfSmqVxOsLLtJN jg719wTOdoOdZpw/NCQoatg0fbmBdzbyu4K0uKK6FbT7MUyha90WrBmFxCbuHuAr3Az4 6e9GsgDZ5PrI+qa3BnsWmaDbgN0ie9bdlxh6gt4Flz3+j6zDFJCavwsZBquOsulT+VY3 mOFPiLbzVufjqC1Uf5eVNNLwE3Qvz/vdbVBbD6Og0yVZ59X6RTCqQhF1JGP0egwIfc5r 3RrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=dXAcaDDFzjoLhHRGcpbdPaqgQzXEOT+W5IONiMWb5hk=; b=aZdGyvm7zhDewUuLQI9pUrp29thEWgzHfu1BVFy1TaFGOnmEqnSQAe3XINqSCFRouh 8CVQ4/ul/cZCDcj9RDe9ti6L8xLdeEel2ngyLJ+oc9sQEQNM9K+LCLz97u9yp/mbCqxB Jm1ZCEWY0jtpyRQ7POcjb9XZ7ev7Sp5PNl2D4dnuKXJV3TK0UHQJlwutcqbrP+HJp5WI TNbpHAZJP4ch5jCtDXQ2odje8M5tBvwdj+3T6z8r/Y7kXwbILcV85txFTYwKMYqLrmRi Tkii9dP0Eeo/dLqWXXqePNJvvx3xFecWW0McLGi8sekaQhwqwNov05SlDuWOx7ZS8HoC 1Egg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=dcRTl7dy; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ck17-20020a170906c45100b0078e0e866a4dsi11053410ejb.682.2022.11.02.11.27.21; Wed, 02 Nov 2022 11:27:46 -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=@google.com header.s=20210112 header.b=dcRTl7dy; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231526AbiKBSU4 (ORCPT + 98 others); Wed, 2 Nov 2022 14:20:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231571AbiKBSUe (ORCPT ); Wed, 2 Nov 2022 14:20:34 -0400 Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 077232F644 for ; Wed, 2 Nov 2022 11:20:29 -0700 (PDT) Received: by mail-yb1-xb33.google.com with SMTP id y72so22138396yby.13 for ; Wed, 02 Nov 2022 11:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=dXAcaDDFzjoLhHRGcpbdPaqgQzXEOT+W5IONiMWb5hk=; b=dcRTl7dyVOUaj/g6ge8SSMiG1ESSTCQ25hhjNASac687d5SVlIUZKi79KYHWqlwac4 wEcgk6DCbF0Jxmfw4wMSSdQF+JlcJgBHhesAKEHA+yRGC0uW3qvSqYv/g5UtEEECLmT4 IIVQqE9SNSDxLh6nD2uX/hGLqzWJLTo99EeXDu9QPASCbwCWKq4oUkEywbXOm431YBXR 2zsTQciA7ofOV0ibUqiGl+af2jB9QlYdyoHUbb/3QDK5py/DMt8fwPfEol26G6cMkUcc ///w3XMnbZC0FInd69NZ4w5RLXlRbq7dJaX7qpob2rcbMP9UPG4hEVM97lxt0JhUBjYe 4PQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dXAcaDDFzjoLhHRGcpbdPaqgQzXEOT+W5IONiMWb5hk=; b=I2M2z0a3sSudoErnExTljGuSl4XqqEB6fJCjIs/KbAB1bgpbMvOe/o92KYl4THUb2c fyGGHfB2c194/eVltVAv92tJihjeIWwC3iApCxhidQnGxwenH3ALoZ2Pcliw9pv52wKi VXqfVjtyyJM9qXDDBwyWCXBM+zFr60KbBo+NcPSaB6FRVz0M/NoEt9ADNsediJfECMql q5v62Pzip4aTC4iUxTVa2soFmohUBYyxH7pY+e/ot52WZmnk76ubCx9FfzHiByQypJoB 9HoaPed2Cw1glvrzUBHW7IC5+HCB7Th+WzF24lQyVQ+PUj7QyZKRSVJFtN1kpVNulvN4 y2kw== X-Gm-Message-State: ACrzQf3gmekaQ1TcaJOLoSZGuE+wGgNAaASEc6aKl86hiio/K6VXQyTY CDE3tc5EXfsPBl+zbwPApWxAv5PMn3USE6DA5suFjg== X-Received: by 2002:a25:d64e:0:b0:6cb:7faa:af94 with SMTP id n75-20020a25d64e000000b006cb7faaaf94mr25177311ybg.36.1667413227920; Wed, 02 Nov 2022 11:20:27 -0700 (PDT) MIME-Version: 1.0 References: <20221024051744.GA48642@debian> <20221101085153.12ccae1c@kernel.org> In-Reply-To: From: Eric Dumazet Date: Wed, 2 Nov 2022 11:20:16 -0700 Message-ID: Subject: Re: [PATCH net-next] gro: avoid checking for a failed search To: Richard Gobert Cc: Jakub Kicinski , davem@davemloft.net, pabeni@redhat.com, lixiaoyan@google.com, alexanderduyck@fb.com, steffen.klassert@secunet.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 2, 2022 at 9:46 AM Richard Gobert 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;