rcu_node_tree.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * RCU node combining tree definitions. These are used to compute
  3. * global attributes while avoiding common-case global contention. A key
  4. * property that these computations rely on is a tournament-style approach
  5. * where only one of the tasks contending a lower level in the tree need
  6. * advance to the next higher level. If properly configured, this allows
  7. * unlimited scalability while maintaining a constant level of contention
  8. * on the root node.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, you can access it online at
  22. * http://www.gnu.org/licenses/gpl-2.0.html.
  23. *
  24. * Copyright IBM Corporation, 2017
  25. *
  26. * Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
  27. */
  28. #ifndef __LINUX_RCU_NODE_TREE_H
  29. #define __LINUX_RCU_NODE_TREE_H
  30. /*
  31. * Define shape of hierarchy based on NR_CPUS, CONFIG_RCU_FANOUT, and
  32. * CONFIG_RCU_FANOUT_LEAF.
  33. * In theory, it should be possible to add more levels straightforwardly.
  34. * In practice, this did work well going from three levels to four.
  35. * Of course, your mileage may vary.
  36. */
  37. #ifdef CONFIG_RCU_FANOUT
  38. #define RCU_FANOUT CONFIG_RCU_FANOUT
  39. #else /* #ifdef CONFIG_RCU_FANOUT */
  40. # ifdef CONFIG_64BIT
  41. # define RCU_FANOUT 64
  42. # else
  43. # define RCU_FANOUT 32
  44. # endif
  45. #endif /* #else #ifdef CONFIG_RCU_FANOUT */
  46. #ifdef CONFIG_RCU_FANOUT_LEAF
  47. #define RCU_FANOUT_LEAF CONFIG_RCU_FANOUT_LEAF
  48. #else /* #ifdef CONFIG_RCU_FANOUT_LEAF */
  49. #define RCU_FANOUT_LEAF 16
  50. #endif /* #else #ifdef CONFIG_RCU_FANOUT_LEAF */
  51. #define RCU_FANOUT_1 (RCU_FANOUT_LEAF)
  52. #define RCU_FANOUT_2 (RCU_FANOUT_1 * RCU_FANOUT)
  53. #define RCU_FANOUT_3 (RCU_FANOUT_2 * RCU_FANOUT)
  54. #define RCU_FANOUT_4 (RCU_FANOUT_3 * RCU_FANOUT)
  55. #if NR_CPUS <= RCU_FANOUT_1
  56. # define RCU_NUM_LVLS 1
  57. # define NUM_RCU_LVL_0 1
  58. # define NUM_RCU_NODES NUM_RCU_LVL_0
  59. # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0 }
  60. # define RCU_NODE_NAME_INIT { "rcu_node_0" }
  61. # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0" }
  62. #elif NR_CPUS <= RCU_FANOUT_2
  63. # define RCU_NUM_LVLS 2
  64. # define NUM_RCU_LVL_0 1
  65. # define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1)
  66. # define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1)
  67. # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1 }
  68. # define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1" }
  69. # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1" }
  70. #elif NR_CPUS <= RCU_FANOUT_3
  71. # define RCU_NUM_LVLS 3
  72. # define NUM_RCU_LVL_0 1
  73. # define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_2)
  74. # define NUM_RCU_LVL_2 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1)
  75. # define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2)
  76. # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1, NUM_RCU_LVL_2 }
  77. # define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1", "rcu_node_2" }
  78. # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1", "rcu_node_fqs_2" }
  79. #elif NR_CPUS <= RCU_FANOUT_4
  80. # define RCU_NUM_LVLS 4
  81. # define NUM_RCU_LVL_0 1
  82. # define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_3)
  83. # define NUM_RCU_LVL_2 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_2)
  84. # define NUM_RCU_LVL_3 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1)
  85. # define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2 + NUM_RCU_LVL_3)
  86. # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1, NUM_RCU_LVL_2, NUM_RCU_LVL_3 }
  87. # define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1", "rcu_node_2", "rcu_node_3" }
  88. # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1", "rcu_node_fqs_2", "rcu_node_fqs_3" }
  89. #else
  90. # error "CONFIG_RCU_FANOUT insufficient for NR_CPUS"
  91. #endif /* #if (NR_CPUS) <= RCU_FANOUT_1 */
  92. extern int rcu_num_lvls;
  93. extern int rcu_num_nodes;
  94. #endif /* __LINUX_RCU_NODE_TREE_H */