kernel: bump 4.14 to 4.14.20
[openwrt/openwrt.git] / target / linux / mediatek / patches-4.14 / 0048-net-core-add-RPS-balancer.patch
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
5
6 Signed-off-by: John Crispin <john@phrozen.org>
7 ---
8 net/core/dev.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
9 1 file changed, 56 insertions(+), 1 deletion(-)
10
11 --- a/net/core/dev.c
12 +++ b/net/core/dev.c
13 @@ -3621,6 +3621,58 @@ set_rps_cpu(struct net_device *dev, stru
14 return rflow;
15 }
16
17 +#define RPS_TBL_SIZE_SHIFT 10
18 +#define RPS_TBL_SIZE (1 << RPS_TBL_SIZE_SHIFT)
19 +struct rps_table {
20 + int core;
21 + struct timer_list expire;
22 +};
23 +static struct rps_table rps_table[RPS_TBL_SIZE];
24 +static int rps_table_last_core;
25 +
26 +static void rps_table_expire(unsigned long data)
27 +{
28 + struct rps_table *entry = (struct rps_table *) data;
29 +
30 + entry->core = -1;
31 +}
32 +
33 +static int rps_table_core(struct rps_map *map)
34 +{
35 + int i;
36 +
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;
41 + return cpu;
42 + }
43 + }
44 + return map->cpus[0];
45 +}
46 +
47 +static int rps_table_lookup(struct rps_map *map, u32 hash)
48 +{
49 + int bucket = hash & 0x3ff;
50 +
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);
54 +
55 + return rps_table[bucket].core;
56 +}
57 +
58 +static void rps_table_init(void)
59 +{
60 + int i;
61 +
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]);
66 + }
67 +}
68 +
69 /*
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 @@ -3710,7 +3762,7 @@ static int get_rps_cpu(struct net_device
73 try_rps:
74
75 if (map) {
76 - tcpu = map->cpus[reciprocal_scale(hash, map->len)];
77 + tcpu = rps_table_lookup(map, hash);
78 if (cpu_online(tcpu)) {
79 cpu = tcpu;
80 goto done;
81 @@ -8795,6 +8847,9 @@ static int __init net_dev_init(void)
82 sd->backlog.weight = weight_p;
83 }
84
85 + if (IS_ENABLED(CONFIG_RPS))
86 + rps_table_init();
87 +
88 dev_boot_phase = 0;
89
90 /* The loopback device is special if any other network devices