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 48/57] net: core: add RPS balancer
6 Signed-off-by: John Crispin <john@phrozen.org>
8 net/core/dev.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
9 1 file changed, 56 insertions(+), 1 deletion(-)
13 @@ -3551,6 +3551,58 @@ set_rps_cpu(struct net_device *dev, stru
17 +#define RPS_TBL_SIZE_SHIFT 10
18 +#define RPS_TBL_SIZE (1 << RPS_TBL_SIZE_SHIFT)
21 + struct timer_list expire;
23 +static struct rps_table rps_table[RPS_TBL_SIZE];
24 +static int rps_table_last_core;
26 +static void rps_table_expire(unsigned long data)
28 + struct rps_table *entry = (struct rps_table *) data;
33 +static int rps_table_core(struct rps_map *map)
37 + for (i = 0; i < map->len; i++) {
38 + int cpu = map->cpus[(rps_table_last_core + i + 1) % map->len];
39 + if (cpu_online(cpu)) {
40 + rps_table_last_core = cpu;
44 + return map->cpus[0];
47 +static int rps_table_lookup(struct rps_map *map, u32 hash)
49 + int bucket = hash & 0x3ff;
51 + if (rps_table[bucket].core < 0)
52 + rps_table[bucket].core = rps_table_core(map);
53 + mod_timer(&rps_table[bucket].expire, jiffies + HZ);
55 + return rps_table[bucket].core;
58 +static void rps_table_init(void)
62 + for (i = 0; i < RPS_TBL_SIZE; i++) {
63 + rps_table[i].core = -1;
64 + setup_timer(&rps_table[i].expire, rps_table_expire,
65 + (unsigned long) &rps_table[i]);
70 * get_rps_cpu is called from netif_receive_skb and returns the target
71 * CPU from the RPS map of the receiving queue for a given skb.
72 @@ -3640,7 +3692,7 @@ static int get_rps_cpu(struct net_device
76 - tcpu = map->cpus[reciprocal_scale(hash, map->len)];
77 + tcpu = rps_table_lookup(map, hash);
78 if (cpu_online(tcpu)) {
81 @@ -8431,6 +8483,9 @@ static int __init net_dev_init(void)
82 sd->backlog.weight = weight_p;
85 + if (IS_ENABLED(CONFIG_RPS))
90 /* The loopback device is special if any other network devices