Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2569617pxf; Sun, 14 Mar 2021 04:16:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxe5PIrolOID5WWfZOQTmtjan95j2I/M+aO5v7KZaEniimFTT3FmjN5npPdvYMTfdbSzsRV X-Received: by 2002:a17:906:4055:: with SMTP id y21mr13189664ejj.507.1615720613525; Sun, 14 Mar 2021 04:16:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615720613; cv=none; d=google.com; s=arc-20160816; b=dbMexAxp4zUEBURl7ELpv5p9R9mlQSC90X17LNq/qdQATP1rXnVkxd8mpu+z+k1Dyd 4Qqqox07hsm8HCxkpPF9TaaK7YGSDhHagTiJIwMgN8qAHCdSaO6Gzp0tOGL6UQuw5Rx3 /JzSOuFSxRflkRVtOsQRt1YoPbhhd3UgcUTEqe7W3anVkxjMWiVtrc7u1FyX7s+seiGD fcrInV5kxKA207C2QM/2Sp0hwFK5AvZvRorZmsuulfdByAF1Upvh6z7gvhFG8aM/grxn /QoPsmWxtbU67jrukcudaoPJLRwH3uy5Eim4c8iFVB2gYqrOCS/ye+eFyJazUu5UVbbE 7mSw== 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:reply-to:cc:from:to :dkim-signature:date; bh=5MpWKAjO4E1TpGup0jNHoJh4fKp9mBQ4WRLVO089bHE=; b=Rsauhsoxhf+rpVYpsIH9tuL2OC4KyAOs1FZ/VuD7AJkFJqvXblQqlZLW3MeJG3c+Fi IfwXghaS90Q3BkVw/1/xWN2ALYCiVOCgGaW5mGhhO6wX6mDbjGOt87J3/8xI5MYXBGb3 ESnM/3j9sdO9BCykMf/SFNMKtqfCPYV4yg2SvPUGez45jWXqQSRuzV2ayITN/p0KmufA 6NMT5ylw5o8/ffmq7lq404c7+AtkbN6o/Zbd965TOsWj4eGPl/hlMp55hYFGeTk288ba tWy8TgTiV7N/lYtmcElk9vzFtJOnAQNhNrR6lEooR5zofAkQImxFq4fD6/SioTtvUTCF RxDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=dbiUPBOm; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x14si8019128edr.255.2021.03.14.04.16.31; Sun, 14 Mar 2021 04:16:53 -0700 (PDT) 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=@pm.me header.s=protonmail header.b=dbiUPBOm; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235395AbhCNLMV (ORCPT + 99 others); Sun, 14 Mar 2021 07:12:21 -0400 Received: from mail1.protonmail.ch ([185.70.40.18]:32547 "EHLO mail1.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235293AbhCNLLz (ORCPT ); Sun, 14 Mar 2021 07:11:55 -0400 Date: Sun, 14 Mar 2021 11:11:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1615720313; bh=5MpWKAjO4E1TpGup0jNHoJh4fKp9mBQ4WRLVO089bHE=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=dbiUPBOmaUdweDnPve56m+Fshaf0U8bdXHkN24JVcIYUbpoizTv55lvHF/w8XNmg3 Qhc1V/KdtQD+jcN7EKajUKa/v4sEZsRlXnNpbm/z/1IqO24GsfeAlezRBd6QB/lfbZ bAnrXo9BTu0rYUQQ0HvcuPyotUTPNVCxVZILC6nH34Xoo6hLIsRWAPcfBbTTEZmXM2 JWUVlFSFtpi3/hl/h4uJv7rYrRapbq5CLpQmTP52r2V1V4aXeFzINSrM03jHdS4dE5 89g5/EtcJjdyvnshLOwfUVQ+dCCJHtEMaPVAprXSGUJIA2y2tpe6zfSbbhuv62RYXl KIsmX4XcdmAcg== To: "David S. Miller" , Jakub Kicinski From: Alexander Lobakin Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Jonathan Lemon , Alexander Lobakin , Eric Dumazet , Willem de Bruijn , Kevin Hao , Pablo Neira Ayuso , Jakub Sitnicki , Marco Elver , Dexuan Cui , Vladimir Oltean , Ariel Levkovich , Wang Qing , Davide Caratti , Guillaume Nault , Eran Ben Elisha , Mauro Carvalho Chehab , Kirill Tkhai , Bartosz Golaszewski , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Reply-To: Alexander Lobakin Subject: [PATCH v3 net-next 6/6] skbuff: micro-optimize {,__}skb_header_pointer() Message-ID: <20210314111027.7657-7-alobakin@pm.me> In-Reply-To: <20210314111027.7657-1-alobakin@pm.me> References: <20210314111027.7657-1-alobakin@pm.me> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org {,__}skb_header_pointer() helpers exist mainly for preventing accesses-beyond-end of the linear data. In the vast majorify of cases, they bail out on the first condition. All code going after is mostly a fallback. Mark the most common branch as 'likely' one to move it in-line. Also, skb_copy_bits() can return negative values only when the input arguments are invalid, e.g. offset is greater than skb->len. It can be safely marked as 'unlikely' branch, assuming that hotpath code provides sane input to not fail here. These two bump the throughput with a single Flow Dissector pass on every packet (e.g. with RPS or driver that uses eth_get_headlen()) on 20 Mbps per flow/core. Signed-off-by: Alexander Lobakin --- include/linux/skbuff.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 46c61e127e9f..ecc029674ae4 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3680,11 +3680,10 @@ static inline void * __must_check __skb_header_pointer(const struct sk_buff *skb, int offset, int len, =09=09 const void *data, int hlen, void *buffer) { -=09if (hlen - offset >=3D len) +=09if (likely(hlen - offset >=3D len)) =09=09return (void *)data + offset; -=09if (!skb || -=09 skb_copy_bits(skb, offset, buffer, len) < 0) +=09if (!skb || unlikely(skb_copy_bits(skb, offset, buffer, len) < 0)) =09=09return NULL; =09return buffer; -- 2.30.2