diff mbox series

net/tun: use reciprocal_scale

Message ID 20240126002550.169608-1-stephen@networkplumber.org (mailing list archive)
State Accepted
Commit 3f3ebe53620818f6e9b029850cb47b96a4ac5b3b
Delegated to: Netdev Maintainers
Headers show
Series net/tun: use reciprocal_scale | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1064 this patch: 1064
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 0 of 0 maintainers
netdev/build_clang success Errors and warnings before: 1081 this patch: 1081
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1081 this patch: 1081
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 25 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-01-29--21-00 (tests: 623)

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

Willem de Bruijn Jan. 27, 2024, 4:06 p.m. UTC | #1
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>
Jason Wang Jan. 29, 2024, 3:01 a.m. UTC | #2
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
patchwork-bot+netdevbpf@kernel.org Jan. 30, 2024, 11:10 a.m. UTC | #3
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 mbox series

Patch

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;