rcu_node_tree.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 seemingly RCU-private file must be available to SRCU users
  11. * because the size of the TREE SRCU srcu_struct structure depends
  12. * on these definitions.
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, you can access it online at
  26. * http://www.gnu.org/licenses/gpl-2.0.html.
  27. *
  28. * Copyright IBM Corporation, 2017
  29. *
  30. * Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
  31. */
  32. #ifndef __LINUX_RCU_NODE_TREE_H
  33. #define __LINUX_RCU_NODE_TREE_H
  34. /*
  35. * Define shape of hierarchy based on NR_CPUS, CONFIG_RCU_FANOUT, and
  36. * CONFIG_RCU_FANOUT_LEAF.
  37. * In theory, it should be possible to add more levels straightforwardly.
  38. * In practice, this did work well going from three levels to four.
  39. * Of course, your mileage may vary.
  40. */
  41. #ifdef CONFIG_RCU_FANOUT
  42. #define RCU_FANOUT CONFIG_RCU_FANOUT
  43. #else /* #ifdef CONFIG_RCU_FANOUT */
  44. # ifdef CONFIG_64BIT
  45. # define RCU_FANOUT 64
  46. # else
  47. # define RCU_FANOUT 32
  48. # endif
  49. #endif /* #else #ifdef CONFIG_RCU_FANOUT */
  50. #ifdef CONFIG_RCU_FANOUT_LEAF
  51. #define RCU_FANOUT_LEAF CONFIG_RCU_FANOUT_LEAF
  52. #else /* #ifdef CONFIG_RCU_FANOUT_LEAF */
  53. #define RCU_FANOUT_LEAF 16
  54. #endif /* #else #ifdef CONFIG_RCU_FANOUT_LEAF */
  55. #define RCU_FANOUT_1 (RCU_FANOUT_LEAF)
  56. #define RCU_FANOUT_2 (RCU_FANOUT_1 * RCU_FANOUT)
  57. #define RCU_FANOUT_3 (RCU_FANOUT_2 * RCU_FANOUT)
  58. #define RCU_FANOUT_4 (RCU_FANOUT_3 * RCU_FANOUT)
  59. #if NR_CPUS <= RCU_FANOUT_1
  60. # define RCU_NUM_LVLS 1
  61. # define NUM_RCU_LVL_0 1
  62. # define NUM_RCU_NODES NUM_RCU_LVL_0
  63. # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0 }
  64. # define RCU_NODE_NAME_INIT { "rcu_node_0" }
  65. # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0" }
  66. #elif NR_CPUS <= RCU_FANOUT_2
  67. # define RCU_NUM_LVLS 2
  68. # define NUM_RCU_LVL_0 1
  69. # define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1)
  70. # define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1)
  71. # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1 }
  72. # define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1" }
  73. # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1" }
  74. #elif NR_CPUS <= RCU_FANOUT_3
  75. # define RCU_NUM_LVLS 3
  76. # define NUM_RCU_LVL_0 1
  77. # define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_2)
  78. # define NUM_RCU_LVL_2 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1)
  79. # define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2)
  80. # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1, NUM_RCU_LVL_2 }
  81. # define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1", "rcu_node_2" }
  82. # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1", "rcu_node_fqs_2" }
  83. #elif NR_CPUS <= RCU_FANOUT_4
  84. # define RCU_NUM_LVLS 4
  85. # define NUM_RCU_LVL_0 1
  86. # define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_3)
  87. # define NUM_RCU_LVL_2 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_2)
  88. # define NUM_RCU_LVL_3 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1)
  89. # define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2 + NUM_RCU_LVL_3)
  90. # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1, NUM_RCU_LVL_2, NUM_RCU_LVL_3 }
  91. # define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1", "rcu_node_2", "rcu_node_3" }
  92. # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1", "rcu_node_fqs_2", "rcu_node_fqs_3" }
  93. #else
  94. # error "CONFIG_RCU_FANOUT insufficient for NR_CPUS"
  95. #endif /* #if (NR_CPUS) <= RCU_FANOUT_1 */
  96. #endif /* __LINUX_RCU_NODE_TREE_H */