rcu_node_tree.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * RCU node combining tree definitions. These are used to compute
  4. * global attributes while avoiding common-case global contention. A key
  5. * property that these computations rely on is a tournament-style approach
  6. * where only one of the tasks contending a lower level in the tree need
  7. * advance to the next higher level. If properly configured, this allows
  8. * unlimited scalability while maintaining a constant level of contention
  9. * on the root node.
  10. *
  11. * This seemingly RCU-private file must be available to SRCU users
  12. * because the size of the TREE SRCU srcu_struct structure depends
  13. * on these definitions.
  14. *
  15. * Copyright IBM Corporation, 2017
  16. *
  17. * Author: Paul E. McKenney <paulmck@linux.ibm.com>
  18. */
  19. #ifndef __LINUX_RCU_NODE_TREE_H
  20. #define __LINUX_RCU_NODE_TREE_H
  21. /*
  22. * Define shape of hierarchy based on NR_CPUS, CONFIG_RCU_FANOUT, and
  23. * CONFIG_RCU_FANOUT_LEAF.
  24. * In theory, it should be possible to add more levels straightforwardly.
  25. * In practice, this did work well going from three levels to four.
  26. * Of course, your mileage may vary.
  27. */
  28. #ifdef CONFIG_RCU_FANOUT
  29. #define RCU_FANOUT CONFIG_RCU_FANOUT
  30. #else /* #ifdef CONFIG_RCU_FANOUT */
  31. # ifdef CONFIG_64BIT
  32. # define RCU_FANOUT 64
  33. # else
  34. # define RCU_FANOUT 32
  35. # endif
  36. #endif /* #else #ifdef CONFIG_RCU_FANOUT */
  37. #ifdef CONFIG_RCU_FANOUT_LEAF
  38. #define RCU_FANOUT_LEAF CONFIG_RCU_FANOUT_LEAF
  39. #else /* #ifdef CONFIG_RCU_FANOUT_LEAF */
  40. #define RCU_FANOUT_LEAF 16
  41. #endif /* #else #ifdef CONFIG_RCU_FANOUT_LEAF */
  42. #define RCU_FANOUT_1 (RCU_FANOUT_LEAF)
  43. #define RCU_FANOUT_2 (RCU_FANOUT_1 * RCU_FANOUT)
  44. #define RCU_FANOUT_3 (RCU_FANOUT_2 * RCU_FANOUT)
  45. #define RCU_FANOUT_4 (RCU_FANOUT_3 * RCU_FANOUT)
  46. #if NR_CPUS <= RCU_FANOUT_1
  47. # define RCU_NUM_LVLS 1
  48. # define NUM_RCU_LVL_0 1
  49. # define NUM_RCU_NODES NUM_RCU_LVL_0
  50. # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0 }
  51. # define RCU_NODE_NAME_INIT { "rcu_node_0" }
  52. # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0" }
  53. #elif NR_CPUS <= RCU_FANOUT_2
  54. # define RCU_NUM_LVLS 2
  55. # define NUM_RCU_LVL_0 1
  56. # define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1)
  57. # define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1)
  58. # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1 }
  59. # define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1" }
  60. # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1" }
  61. #elif NR_CPUS <= RCU_FANOUT_3
  62. # define RCU_NUM_LVLS 3
  63. # define NUM_RCU_LVL_0 1
  64. # define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_2)
  65. # define NUM_RCU_LVL_2 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1)
  66. # define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2)
  67. # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1, NUM_RCU_LVL_2 }
  68. # define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1", "rcu_node_2" }
  69. # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1", "rcu_node_fqs_2" }
  70. #elif NR_CPUS <= RCU_FANOUT_4
  71. # define RCU_NUM_LVLS 4
  72. # define NUM_RCU_LVL_0 1
  73. # define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_3)
  74. # define NUM_RCU_LVL_2 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_2)
  75. # define NUM_RCU_LVL_3 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1)
  76. # define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2 + NUM_RCU_LVL_3)
  77. # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1, NUM_RCU_LVL_2, NUM_RCU_LVL_3 }
  78. # define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1", "rcu_node_2", "rcu_node_3" }
  79. # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1", "rcu_node_fqs_2", "rcu_node_fqs_3" }
  80. #else
  81. # error "CONFIG_RCU_FANOUT insufficient for NR_CPUS"
  82. #endif /* #if (NR_CPUS) <= RCU_FANOUT_1 */
  83. #endif /* __LINUX_RCU_NODE_TREE_H */