Message ID | 20240126002550.169608-1-stephen@networkplumber.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-39459-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp350948dyb; Thu, 25 Jan 2024 16:26:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IElNH/ZcOUYHx4c6vuOxaQWonb47yf67t1MDgbRqDBFh4r8sW+Ae+PH70n36Fk6ZDK7SK28 X-Received: by 2002:a05:620a:1a22:b0:783:c0b3:eed0 with SMTP id bk34-20020a05620a1a2200b00783c0b3eed0mr639624qkb.85.1706228782749; Thu, 25 Jan 2024 16:26:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706228782; cv=pass; d=google.com; s=arc-20160816; b=lE0iLClI8sUQvMZMxcQ223zmS5wRrLxnvZSIRrMLjTLUuDFJZZJPhYb41YyMyetgS6 a/3MzV1d1nNeVFsT3kbizV5NxYm5YI3rc9p8Pvz2rt9OXyIYL6r1r9uGzJxAYK9b5+kN 6qHIBU0C7HnDuubnzmgvTg7S27wRPINTpyNO/H3jhAYJ+fX2nXLAujOgkZ/D/WVXrU1Q X7Z8mad+xbhp23UA2Y8sobbwlJp3QL9wZOF9lSTFH6KwCmlJNJ9p+5ApehPKXIczMuSC f85hJkrg0qAnK6flAf+KS7KmelXIJQki4sjxVD8AqPpEEt6AccLx5biP99OxnOjH7/eH e9aA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=C3n8jP9y3uPiUHRGFsi0dJRm8wXS2AMvfgDp5gCgG2I=; fh=WuzUXX5EP/9U+m6IgkGT74/kj14EftA7Qs0IwOkDPzg=; b=ub8GI/V89tiLF38qfNEWx2OhvNuYrPEnUTwO/Dp+DtoFjHonkEGp7gorDtmGpYcjtz 3Y5NQfWJ6iy/2R21yzYFzHvDuJnmWke8yGnpL+SV80qD+KLtEyf46cyjEgk9z0/F9O0I Vgi1FfZgnZJJy9jeE0xgwXwHoP3PCL5+E2/JZKy1Y05KNt9yJZNxbVgjUQUBmFu4js7S Qag/tyannotc3lQ53/i/fy1Xz23w0kxVs4VOd5/XyfixG/TLlsI1raYgoHKpb6VHm7pq BQj82RF1ogPI871qkNXKbv7Uo0DVdJMoHR9fMkC93pGgBSTX4pr4ScziHX6BbtuWJjPT +x4A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@networkplumber-org.20230601.gappssmtp.com header.s=20230601 header.b=03J8gHrI; arc=pass (i=1 spf=pass spfdomain=networkplumber.org dkim=pass dkdomain=networkplumber-org.20230601.gappssmtp.com dmarc=pass fromdomain=networkplumber.org); spf=pass (google.com: domain of linux-kernel+bounces-39459-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39459-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=networkplumber.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i15-20020a05620a0a0f00b007833571fa52si124425qka.654.2024.01.25.16.26.22 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 16:26:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39459-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@networkplumber-org.20230601.gappssmtp.com header.s=20230601 header.b=03J8gHrI; arc=pass (i=1 spf=pass spfdomain=networkplumber.org dkim=pass dkdomain=networkplumber-org.20230601.gappssmtp.com dmarc=pass fromdomain=networkplumber.org); spf=pass (google.com: domain of linux-kernel+bounces-39459-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39459-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=networkplumber.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 893AF1C23EC5 for <ouuuleilei@gmail.com>; Fri, 26 Jan 2024 00:26:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 89E941C13; Fri, 26 Jan 2024 00:26:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=networkplumber-org.20230601.gappssmtp.com header.i=@networkplumber-org.20230601.gappssmtp.com header.b="03J8gHrI" Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFB6B4416 for <linux-kernel@vger.kernel.org>; Fri, 26 Jan 2024 00:26:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706228762; cv=none; b=Z6u4MNOSS5cbr0E3Ac/73ct+Q0/Pk/TGGKQ8aKXvGNsLwu+HonYC2SHOsnpLQXLGxAy5R11lxEo0aq3/nvpt+X/VuPc92CmnLTHwcS0FhHSq/so1zZwGpJPr/jlHLivXSPSccac+fSba3/ljUNfBYw9rG1r7xH89v8fBh9YPQKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706228762; c=relaxed/simple; bh=6uc9Il8X4Kn9u6X/lHrXvQxTWpXcD8ov8vlLdijWmI8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=U0WfWWNyX08L7At/u0fcG4zDTOsrqYehNSTfARi0SLXKjwSOtF27wN51d7oI4YbFMaswUo9jy5i5QNYpnmiuN5ZSz9ve+ReC2qFvmWKjBgRlbBMuO/7S0x9BDJ1s1V/3RW0ROU1oL+bSDKle/tPQSxiTllGtghLQun8SS+2Y+Qo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=networkplumber.org; spf=pass smtp.mailfrom=networkplumber.org; dkim=pass (2048-bit key) header.d=networkplumber-org.20230601.gappssmtp.com header.i=@networkplumber-org.20230601.gappssmtp.com header.b=03J8gHrI; arc=none smtp.client-ip=209.85.167.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=networkplumber.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=networkplumber.org Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3bdbf401bd3so80748b6e.0 for <linux-kernel@vger.kernel.org>; Thu, 25 Jan 2024 16:26:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1706228760; x=1706833560; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=C3n8jP9y3uPiUHRGFsi0dJRm8wXS2AMvfgDp5gCgG2I=; b=03J8gHrIpmQpsE9x+BgZlC3yjvO4HdHQH+lw9Ewx6XxsPITXcBcm9et+zrLLldQrkP xoyTE0bOZBTtks+clEwklz5Q/ZLEO18mgmn0aLxedIqRww2nFBr/jjwgkPgu+AVyxX7h R9KPHx/SP53VHTJ6ksh4xOe7q02uP9cWf9RTT/VVsyTtFOXedO9dd/HWQVCDrT7wN//p wGYKOLi0rgq8o498bGpoEnw4mHRgDOHAP8L3Dwx05yyAt6umDWdObpzJUeYYfMPlTN/E jd4gTTfVXiCYOZmYFzpETHTgM6FLf23qkI0DyG0xKrhxCH6anzrUMlxLHKFm/RiI0zg6 AkkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706228760; x=1706833560; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=C3n8jP9y3uPiUHRGFsi0dJRm8wXS2AMvfgDp5gCgG2I=; b=fPVh7+ZfuA1DCMTmXtjVuPKMoUzsRTGxr6+twtBgXtF0DJ5WxCakVvRiDKm5TLuTPl BFdozkQoXPJX6fFI2McwLHQljNT2PYVhmdTDegRJfkyNs7svtZhGLzbFL4z/XnQpkeNk ntFnVacypD0cHbK4lvjj4bYu5i6nYcthkNzipOL/xNz1iEqlfUv89BI96UqH5XghnmYa jlnOQlXMnHwfoUa7H0wlZC1+2oZ95nXxXnAg+VsWeTChzy6ipGkGkt++lCr3AgOGVSMw qp1DEbSxV7j92bH7NPlKMKdbbvSgG/vrAbtQXo81dd6CMoFz35zXVBtE94q957FyCT0F OU5w== X-Gm-Message-State: AOJu0YwLvPEfYGz4noYVl14tcUsCrZslEhDU6fQXg+iNdLxqqX17kbR0 mLI4b1ZeNuPULAi7rOmhLQb6UEFwP4kDLj5mmpJyCOuU+sFA6EDhI3wHDsHgud4= X-Received: by 2002:aca:2103:0:b0:3bd:9d4c:de with SMTP id 3-20020aca2103000000b003bd9d4c00demr563865oiz.30.1706228760099; Thu, 25 Jan 2024 16:26:00 -0800 (PST) Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id n13-20020a056a000d4d00b006dddd5cc47csm105379pfv.157.2024.01.25.16.25.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 16:25:59 -0800 (PST) From: Stephen Hemminger <stephen@networkplumber.org> To: netdev@vger.kernel.org Cc: Stephen Hemminger <stephen@networkplumber.org>, Willem de Bruijn <willemdebruijn.kernel@gmail.com>, Jason Wang <jasowang@redhat.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, linux-kernel@vger.kernel.org (open list) Subject: [PATCH] net/tun: use reciprocal_scale Date: Thu, 25 Jan 2024 16:25:11 -0800 Message-ID: <20240126002550.169608-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789110552423546169 X-GMAIL-MSGID: 1789110552423546169 |
Series |
net/tun: use reciprocal_scale
|
|
Commit Message
Stephen Hemminger
Jan. 26, 2024, 12:25 a.m. UTC
Use the inline function reciprocal_scale rather than open coding
the scale optimization. Also, remove unnecessary initializations.
Resulting compiled code is unchanged (according to godbolt).
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/net/tun.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
Comments
Stephen Hemminger wrote: > Use the inline function reciprocal_scale rather than open coding > the scale optimization. Also, remove unnecessary initializations. > Resulting compiled code is unchanged (according to godbolt). > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Targeting net-next Reviewed-by: Willem de Bruijn <willemb@google.com>
On Fri, Jan 26, 2024 at 8:26 AM Stephen Hemminger <stephen@networkplumber.org> wrote: > > Use the inline function reciprocal_scale rather than open coding > the scale optimization. Also, remove unnecessary initializations. > Resulting compiled code is unchanged (according to godbolt). > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Acked-by: Jason Wang <jasowang@redhat.com> Thanks
Hello: This patch was applied to netdev/net-next.git (main) by Paolo Abeni <pabeni@redhat.com>: On Thu, 25 Jan 2024 16:25:11 -0800 you wrote: > Use the inline function reciprocal_scale rather than open coding > the scale optimization. Also, remove unnecessary initializations. > Resulting compiled code is unchanged (according to godbolt). > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> > --- > drivers/net/tun.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) Here is the summary with links: - net/tun: use reciprocal_scale https://git.kernel.org/netdev/net-next/c/3f3ebe536208 You are awesome, thank you!
diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 4a4f8c8e79fa..e335ece47dec 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -54,6 +54,7 @@ #include <linux/if_tun.h> #include <linux/if_vlan.h> #include <linux/crc32.h> +#include <linux/math.h> #include <linux/nsproxy.h> #include <linux/virtio_net.h> #include <linux/rcupdate.h> @@ -523,8 +524,7 @@ static inline void tun_flow_save_rps_rxhash(struct tun_flow_entry *e, u32 hash) static u16 tun_automq_select_queue(struct tun_struct *tun, struct sk_buff *skb) { struct tun_flow_entry *e; - u32 txq = 0; - u32 numqueues = 0; + u32 txq, numqueues; numqueues = READ_ONCE(tun->numqueues); @@ -534,8 +534,7 @@ static u16 tun_automq_select_queue(struct tun_struct *tun, struct sk_buff *skb) tun_flow_save_rps_rxhash(e, txq); txq = e->queue_index; } else { - /* use multiply and shift instead of expensive divide */ - txq = ((u64)txq * numqueues) >> 32; + txq = reciprocal_scale(txq, numqueues); } return txq;