net: use reciprocal_scale() helper
Replace open codings of (((u64) <x> * <y>) >> 32) with reciprocal_scale(). Signed-off-by: Daniel Borkmann <dborkman@redhat.com> Cc: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
690e36e726
commit
8fc54f6891
@@ -229,7 +229,7 @@ begin:
|
||||
}
|
||||
} else if (score == hiscore && reuseport) {
|
||||
matches++;
|
||||
if (((u64)phash * matches) >> 32 == 0)
|
||||
if (reciprocal_scale(phash, matches) == 0)
|
||||
result = sk;
|
||||
phash = next_pseudo_random32(phash);
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ clusterip_hashfn(const struct sk_buff *skb,
|
||||
}
|
||||
|
||||
/* node numbers are 1..n, not 0..n */
|
||||
return (((u64)hashval * config->num_total_nodes) >> 32) + 1;
|
||||
return reciprocal_scale(hashval, config->num_total_nodes) + 1;
|
||||
}
|
||||
|
||||
static inline int
|
||||
|
||||
+3
-3
@@ -224,7 +224,7 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
|
||||
remaining = (high - low) + 1;
|
||||
|
||||
rand = prandom_u32();
|
||||
first = (((u64)rand * remaining) >> 32) + low;
|
||||
first = reciprocal_scale(rand, remaining) + low;
|
||||
/*
|
||||
* force rand to be an odd multiple of UDP_HTABLE_SIZE
|
||||
*/
|
||||
@@ -448,7 +448,7 @@ begin:
|
||||
}
|
||||
} else if (score == badness && reuseport) {
|
||||
matches++;
|
||||
if (((u64)hash * matches) >> 32 == 0)
|
||||
if (reciprocal_scale(hash, matches) == 0)
|
||||
result = sk;
|
||||
hash = next_pseudo_random32(hash);
|
||||
}
|
||||
@@ -529,7 +529,7 @@ begin:
|
||||
}
|
||||
} else if (score == badness && reuseport) {
|
||||
matches++;
|
||||
if (((u64)hash * matches) >> 32 == 0)
|
||||
if (reciprocal_scale(hash, matches) == 0)
|
||||
result = sk;
|
||||
hash = next_pseudo_random32(hash);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user