Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8fc54f68 authored by Daniel Borkmann's avatar Daniel Borkmann Committed by David S. Miller
Browse files

net: use reciprocal_scale() helper



Replace open codings of (((u64) <x> * <y>) >> 32) with reciprocal_scale().

Signed-off-by: default avatarDaniel Borkmann <dborkman@redhat.com>
Cc: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 690e36e7
Loading
Loading
Loading
Loading
+1 −2
Original line number Original line Diff line number Diff line
@@ -3124,8 +3124,7 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
	}
	}


	if (map) {
	if (map) {
		tcpu = map->cpus[((u64) hash * map->len) >> 32];
		tcpu = map->cpus[reciprocal_scale(hash, map->len)];

		if (cpu_online(tcpu)) {
		if (cpu_online(tcpu)) {
			cpu = tcpu;
			cpu = tcpu;
			goto done;
			goto done;
+3 −4
Original line number Original line Diff line number Diff line
@@ -298,7 +298,7 @@ u16 __skb_tx_hash(const struct net_device *dev, struct sk_buff *skb,
		qcount = dev->tc_to_txq[tc].count;
		qcount = dev->tc_to_txq[tc].count;
	}
	}


	return (u16) (((u64)skb_get_hash(skb) * qcount) >> 32) + qoffset;
	return (u16) reciprocal_scale(skb_get_hash(skb), qcount) + qoffset;
}
}
EXPORT_SYMBOL(__skb_tx_hash);
EXPORT_SYMBOL(__skb_tx_hash);


@@ -371,9 +371,8 @@ static inline int get_xps_queue(struct net_device *dev, struct sk_buff *skb)
			if (map->len == 1)
			if (map->len == 1)
				queue_index = map->queues[0];
				queue_index = map->queues[0];
			else
			else
				queue_index = map->queues[
				queue_index = map->queues[reciprocal_scale(skb_get_hash(skb),
				    ((u64)skb_get_hash(skb) * map->len) >> 32];
									   map->len)];

			if (unlikely(queue_index >= dev->real_num_tx_queues))
			if (unlikely(queue_index >= dev->real_num_tx_queues))
				queue_index = -1;
				queue_index = -1;
		}
		}
+1 −1
Original line number Original line Diff line number Diff line
@@ -229,7 +229,7 @@ struct sock *__inet_lookup_listener(struct net *net,
			}
			}
		} else if (score == hiscore && reuseport) {
		} else if (score == hiscore && reuseport) {
			matches++;
			matches++;
			if (((u64)phash * matches) >> 32 == 0)
			if (reciprocal_scale(phash, matches) == 0)
				result = sk;
				result = sk;
			phash = next_pseudo_random32(phash);
			phash = next_pseudo_random32(phash);
		}
		}
+1 −1
Original line number Original line Diff line number Diff line
@@ -285,7 +285,7 @@ clusterip_hashfn(const struct sk_buff *skb,
	}
	}


	/* node numbers are 1..n, not 0..n */
	/* 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
static inline int
+3 −3
Original line number Original line Diff line number Diff line
@@ -224,7 +224,7 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
		remaining = (high - low) + 1;
		remaining = (high - low) + 1;


		rand = prandom_u32();
		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
		 * force rand to be an odd multiple of UDP_HTABLE_SIZE
		 */
		 */
@@ -448,7 +448,7 @@ static struct sock *udp4_lib_lookup2(struct net *net,
			}
			}
		} else if (score == badness && reuseport) {
		} else if (score == badness && reuseport) {
			matches++;
			matches++;
			if (((u64)hash * matches) >> 32 == 0)
			if (reciprocal_scale(hash, matches) == 0)
				result = sk;
				result = sk;
			hash = next_pseudo_random32(hash);
			hash = next_pseudo_random32(hash);
		}
		}
@@ -529,7 +529,7 @@ struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr,
			}
			}
		} else if (score == badness && reuseport) {
		} else if (score == badness && reuseport) {
			matches++;
			matches++;
			if (((u64)hash * matches) >> 32 == 0)
			if (reciprocal_scale(hash, matches) == 0)
				result = sk;
				result = sk;
			hash = next_pseudo_random32(hash);
			hash = next_pseudo_random32(hash);
		}
		}
Loading