Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2146774pxb; Sat, 23 Jan 2021 19:28:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwP2zjUU6ZsLkC/Bck7jxoDCrTSZpqETf93pcDM2uShtwUVAKWvtEugaLN4Tpa2x5DuH+s2 X-Received: by 2002:aa7:d304:: with SMTP id p4mr399211edq.144.1611458911936; Sat, 23 Jan 2021 19:28:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611458911; cv=none; d=google.com; s=arc-20160816; b=MIHCglOQn2CM7BpgQX+KqsusEqp5zCfGyg+avCfFuHd18CO3aKwOV8HWbYbKNgFEIl yXo0cxfFvJJlKcE0ir4dtBtXN5ZY1hy9Xg0HZvVoHutRoZ7VaGBwpHOftg0jYfDt8/VB x9HMD8UngJWVkGryis804f1jGe5oz/eHI2/GE0Z1qZ6z5cgHitZaONaM2oF8ic5KuL3F 0zxnjOXbjjh3IYGJOs51z6d7KnVjKfYiTOjgD535Qct2NlyEgjHNzwv1SVLrxqBL+wmJ VHhYCI/PHu/PI9lEnmZnXBPgRPFweDUP7IvqD+rWot5F2pBe+85YQTtxTLc5ARboFlGO DYaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=g+7Y+g78fbyRBLx0BKw1XnJILsZVvRMYouxmUW4KHG8=; b=dPF5Z5Obc03+5MY31ep9pFwv8UZ5qymXq/j0NGUbP9Fal6nLvUu5mfx/Yk+Ab9toH+ TGsy8fPBGxUHaIENrCfLXm1v1Qgg6tYmu9ETARgizdnh4LosfucUhgXuIa6k3n7KYFuO /8HcBn8d8hteT+qFdhLX8yTZ2QNhnqTkM5X3D+FlDFuMTFqqAdhdxzVqpFsFQ0A8N6jh 0Q8qFual8N0pNgi2PjNK5AfUKVgjorwfxYcw6BwuFNj9AxSRuf9tmkmE89OdcScztnuy 56ChZY0Y1+UslLKan1FvhnKUlUICvynTc3Wfh+x0114mHvS6PLZ+zd70o7NPLNh9HVHQ XIdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bVGwaYit; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n22si4593377eji.534.2021.01.23.19.28.08; Sat, 23 Jan 2021 19:28:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bVGwaYit; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726510AbhAXD1N (ORCPT + 99 others); Sat, 23 Jan 2021 22:27:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:34254 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726375AbhAXD1J (ORCPT ); Sat, 23 Jan 2021 22:27:09 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 90CB322D0A; Sun, 24 Jan 2021 03:26:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611458786; bh=+OOJlwiRevgXr+hw4L13I8DH0AsYtPCQi4EnGrYc5gM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=bVGwaYitrqgUvCcJOYsC1tYWpRN4CdN8TKkLfKjCod6DpsRvHkz9rkU0B2RwfiXI+ ykwg5qHnGPOQX1tgAB+8o4iM45MnLB+TdCkS2+sv78yWG6MERZJlSYR97VNWMCR/Zs RCkvsvEudcMYMX+e590qz7nEXQI+2OS4IAxsmec3F2bhuRTdGUg2fn7jQulwK02UEv oFv9qXKf01OlO4Ngw5lEEE1RC20WZqz8Kn7iLiUISwG2UVWLTfPAVPiVrC8Pmzib/X ddIA07xY0XV6QGGQJJvWN1/hjwNQre4zccWHcvs34vgirLYDPUPlxLTvibKFy0k0B0 hNjc++Sv/eDGA== Date: Sat, 23 Jan 2021 19:26:24 -0800 From: Jakub Kicinski To: Lukas Wunner Cc: "Pablo Neira Ayuso" , Jozsef Kadlecsik , Florian Westphal , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, Daniel Borkmann , Alexei Starovoitov , Eric Dumazet , Thomas Graf , Laura Garcia Liebana , John Fastabend , LKML Subject: Re: [PATCH nf-next v4 1/5] net: sched: Micro-optimize egress handling Message-ID: <20210123192624.4cee3b7d@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 22 Jan 2021 09:47:01 +0100 Lukas Wunner wrote: > sch_handle_egress() returns either the skb or NULL to signal to its > caller __dev_queue_xmit() whether a packet should continue to be > processed. > > The skb is always non-NULL, otherwise __dev_queue_xmit() would hit a > NULL pointer deref right at its top. > > But the compiler doesn't know that. So if sch_handle_egress() signals > success by returning the skb, the "if (!skb) goto out;" statement > results in a gratuitous NULL pointer check in the Assembler output. Which exact compiler are we talking about it? Did you report this? As Eric pointed the compiler should be able to figure this out quite easily. > Avoid by telling the compiler that __dev_queue_xmit() is never passed a > NULL skb. This also eliminates another gratuitous NULL pointer check in > __dev_queue_xmit() > qdisc_pkt_len_init() > skb_header_pointer() > __skb_header_pointer() > > The speedup is barely measurable: > Before: 1877 1875 1878 1874 1882 1873 Mb/sec > After: 1877 1877 1880 1883 1888 1886 Mb/sec > > However we're about to add a netfilter egress hook to __dev_queue_xmit() > and without the micro-optimization, it will result in a performance > degradation which is indeed measurable: > With netfilter hook: 1853 1852 1850 1848 1849 1851 Mb/sec > With netfilter hook + micro-optim: 1874 1877 1881 1875 1876 1876 Mb/sec > > The performance degradation is caused by a JNE instruction ("if (skb)") > being flipped to a JE instruction ("if (!skb)") once the netfilter hook > is added. The micro-optimization removes the test and jump instructions > altogether. > > Measurements were performed on a Core i7-3615QM. Reproducer: > ip link add dev foo type dummy > ip link set dev foo up > tc qdisc add dev foo clsact > tc filter add dev foo egress bpf da bytecode '1,6 0 0 0,' > modprobe pktgen > echo "add_device foo" > /proc/net/pktgen/kpktgend_3 > samples/pktgen/pktgen_bench_xmit_mode_queue_xmit.sh -i foo -n 400000000 -m "11:11:11:11:11:11" -d 1.1.1.1 > > Signed-off-by: Lukas Wunner > Cc: John Fastabend > Cc: Daniel Borkmann > Cc: Alexei Starovoitov > Cc: Eric Dumazet > Cc: Thomas Graf > --- > net/core/dev.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/net/core/dev.c b/net/core/dev.c > index 7afbb642e203..4c16b9932823 100644 > --- a/net/core/dev.c > +++ b/net/core/dev.c > @@ -4072,6 +4072,7 @@ struct netdev_queue *netdev_core_pick_tx(struct net_device *dev, > * the BH enable code must have IRQs enabled so that it will not deadlock. > * --BLG > */ > +__attribute__((nonnull(1))) > static int __dev_queue_xmit(struct sk_buff *skb, struct net_device *sb_dev) > { > struct net_device *dev = skb->dev;