summaryrefslogtreecommitdiff
path: root/drivers/net/tun.c
diff options
context:
space:
mode:
authorStephen Hemminger <stephen@networkplumber.org>2024-01-25 16:25:11 -0800
committerPaolo Abeni <pabeni@redhat.com>2024-01-30 12:02:32 +0100
commit3f3ebe53620818f6e9b029850cb47b96a4ac5b3b (patch)
treec0f1ff282d3068a586ac73525e2d42aae5688590 /drivers/net/tun.c
parente8166eb24692ddac08ed3a401d3d09e9b4443642 (diff)
downloadlwn-3f3ebe53620818f6e9b029850cb47b96a4ac5b3b.tar.gz
lwn-3f3ebe53620818f6e9b029850cb47b96a4ac5b3b.zip
net/tun: use reciprocal_scale
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> Reviewed-by: Willem de Bruijn <willemb@google.com> Acked-by: Jason Wang <jasowang@redhat.com> Link: https://lore.kernel.org/r/20240126002550.169608-1-stephen@networkplumber.org Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Diffstat (limited to 'drivers/net/tun.c')
-rw-r--r--drivers/net/tun.c7
1 files 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;