linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/tun: use reciprocal_scale
@ 2024-01-26  0:25 Stephen Hemminger
  2024-01-27 16:06 ` Willem de Bruijn
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Stephen Hemminger @ 2024-01-26  0:25 UTC (permalink / raw)
  To: netdev
  Cc: Stephen Hemminger, Willem de Bruijn, Jason Wang, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, open list

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(-)

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;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] net/tun: use reciprocal_scale
  2024-01-26  0:25 [PATCH] net/tun: use reciprocal_scale Stephen Hemminger
@ 2024-01-27 16:06 ` Willem de Bruijn
  2024-01-29  3:01 ` Jason Wang
  2024-01-30 11:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Willem de Bruijn @ 2024-01-27 16:06 UTC (permalink / raw)
  To: Stephen Hemminger, netdev
  Cc: Stephen Hemminger, Willem de Bruijn, Jason Wang, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, open list

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>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net/tun: use reciprocal_scale
  2024-01-26  0:25 [PATCH] net/tun: use reciprocal_scale Stephen Hemminger
  2024-01-27 16:06 ` Willem de Bruijn
@ 2024-01-29  3:01 ` Jason Wang
  2024-01-30 11:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Jason Wang @ 2024-01-29  3:01 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: netdev, Willem de Bruijn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, open list

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net/tun: use reciprocal_scale
  2024-01-26  0:25 [PATCH] net/tun: use reciprocal_scale Stephen Hemminger
  2024-01-27 16:06 ` Willem de Bruijn
  2024-01-29  3:01 ` Jason Wang
@ 2024-01-30 11:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-01-30 11:10 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: netdev, willemdebruijn.kernel, jasowang, davem, edumazet, kuba,
	pabeni, linux-kernel

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-01-30 11:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-26  0:25 [PATCH] net/tun: use reciprocal_scale Stephen Hemminger
2024-01-27 16:06 ` Willem de Bruijn
2024-01-29  3:01 ` Jason Wang
2024-01-30 11:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).