1 From 3e969c9695b45e1a052d43b367096ec99f2f0aac Mon Sep 17 00:00:00 2001
2 From: John Crispin <john@phrozen.org>
3 Date: Thu, 10 Aug 2017 15:58:29 +0200
4 Subject: [PATCH] net: core: add RPS balancer
6 This patch adds a hash bucket based rps hash balancer.
8 Signed-off-by: John Crispin <john@phrozen.org>
10 net/core/dev.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
11 1 file changed, 56 insertions(+), 1 deletion(-)
15 @@ -3626,6 +3626,58 @@ set_rps_cpu(struct net_device *dev, stru
19 +#define RPS_TBL_SIZE_SHIFT 10
20 +#define RPS_TBL_SIZE (1 << RPS_TBL_SIZE_SHIFT)
23 + struct timer_list expire;
25 +static struct rps_table rps_table[RPS_TBL_SIZE];
26 +static int rps_table_last_core;
28 +static void rps_table_expire(unsigned long data)
30 + struct rps_table *entry = (struct rps_table *) data;
35 +static int rps_table_core(struct rps_map *map)
39 + for (i = 0; i < map->len; i++) {
40 + int cpu = map->cpus[(rps_table_last_core + i + 1) % map->len];
41 + if (cpu_online(cpu)) {
42 + rps_table_last_core = cpu;
46 + return map->cpus[0];
49 +static int rps_table_lookup(struct rps_map *map, u32 hash)
51 + int bucket = hash & 0x3ff;
53 + if (rps_table[bucket].core < 0)
54 + rps_table[bucket].core = rps_table_core(map);
55 + mod_timer(&rps_table[bucket].expire, jiffies + HZ);
57 + return rps_table[bucket].core;
60 +static void rps_table_init(void)
64 + for (i = 0; i < RPS_TBL_SIZE; i++) {
65 + rps_table[i].core = -1;
66 + setup_timer(&rps_table[i].expire, rps_table_expire,
67 + (unsigned long) &rps_table[i]);
72 * get_rps_cpu is called from netif_receive_skb and returns the target
73 * CPU from the RPS map of the receiving queue for a given skb.
74 @@ -3715,7 +3767,7 @@ static int get_rps_cpu(struct net_device
78 - tcpu = map->cpus[reciprocal_scale(hash, map->len)];
79 + tcpu = rps_table_lookup(map, hash);
80 if (cpu_online(tcpu)) {
83 @@ -8800,6 +8852,10 @@ static int __init net_dev_init(void)
84 sd->backlog.weight = weight_p;
93 /* The loopback device is special if any other network devices