0048-net-core-add-RPS-balancer.patch 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. From 3e969c9695b45e1a052d43b367096ec99f2f0aac Mon Sep 17 00:00:00 2001
  2. From: John Crispin <[email protected]>
  3. Date: Thu, 10 Aug 2017 15:58:29 +0200
  4. Subject: [PATCH 48/57] net: core: add RPS balancer
  5. Signed-off-by: John Crispin <[email protected]>
  6. ---
  7. net/core/dev.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
  8. 1 file changed, 56 insertions(+), 1 deletion(-)
  9. --- a/net/core/dev.c
  10. +++ b/net/core/dev.c
  11. @@ -3628,6 +3628,58 @@ set_rps_cpu(struct net_device *dev, stru
  12. return rflow;
  13. }
  14. +#define RPS_TBL_SIZE_SHIFT 10
  15. +#define RPS_TBL_SIZE (1 << RPS_TBL_SIZE_SHIFT)
  16. +struct rps_table {
  17. + int core;
  18. + struct timer_list expire;
  19. +};
  20. +static struct rps_table rps_table[RPS_TBL_SIZE];
  21. +static int rps_table_last_core;
  22. +
  23. +static void rps_table_expire(unsigned long data)
  24. +{
  25. + struct rps_table *entry = (struct rps_table *) data;
  26. +
  27. + entry->core = -1;
  28. +}
  29. +
  30. +static int rps_table_core(struct rps_map *map)
  31. +{
  32. + int i;
  33. +
  34. + for (i = 0; i < map->len; i++) {
  35. + int cpu = map->cpus[(rps_table_last_core + i + 1) % map->len];
  36. + if (cpu_online(cpu)) {
  37. + rps_table_last_core = cpu;
  38. + return cpu;
  39. + }
  40. + }
  41. + return map->cpus[0];
  42. +}
  43. +
  44. +static int rps_table_lookup(struct rps_map *map, u32 hash)
  45. +{
  46. + int bucket = hash & 0x3ff;
  47. +
  48. + if (rps_table[bucket].core < 0)
  49. + rps_table[bucket].core = rps_table_core(map);
  50. + mod_timer(&rps_table[bucket].expire, jiffies + HZ);
  51. +
  52. + return rps_table[bucket].core;
  53. +}
  54. +
  55. +static void rps_table_init(void)
  56. +{
  57. + int i;
  58. +
  59. + for (i = 0; i < RPS_TBL_SIZE; i++) {
  60. + rps_table[i].core = -1;
  61. + setup_timer(&rps_table[i].expire, rps_table_expire,
  62. + (unsigned long) &rps_table[i]);
  63. + }
  64. +}
  65. +
  66. /*
  67. * get_rps_cpu is called from netif_receive_skb and returns the target
  68. * CPU from the RPS map of the receiving queue for a given skb.
  69. @@ -3717,7 +3769,7 @@ static int get_rps_cpu(struct net_device
  70. try_rps:
  71. if (map) {
  72. - tcpu = map->cpus[reciprocal_scale(hash, map->len)];
  73. + tcpu = rps_table_lookup(map, hash);
  74. if (cpu_online(tcpu)) {
  75. cpu = tcpu;
  76. goto done;
  77. @@ -8802,6 +8854,9 @@ static int __init net_dev_init(void)
  78. sd->backlog.weight = weight_p;
  79. }
  80. + if (IS_ENABLED(CONFIG_RPS))
  81. + rps_table_init();
  82. +
  83. dev_boot_phase = 0;
  84. /* The loopback device is special if any other network devices