rcu_node_tree.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <[email protected]>
  18. */
  19. #ifndef __LINUX_RCU_NODE_TREE_H
  20. #define __LINUX_RCU_NODE_TREE_H
  21. #include <linux/math.h>
  22. /*
  23. * Define shape of hierarchy based on NR_CPUS, CONFIG_RCU_FANOUT, and
  24. * CONFIG_RCU_FANOUT_LEAF.
  25. * In theory, it should be possible to add more levels straightforwardly.
  26. * In practice, this did work well going from three levels to four.
  27. * Of course, your mileage may vary.
  28. */
  29. #ifdef CONFIG_RCU_FANOUT
  30. #define RCU_FANOUT CONFIG_RCU_FANOUT
  31. #else /* #ifdef CONFIG_RCU_FANOUT */
  32. # ifdef CONFIG_64BIT
  33. # define RCU_FANOUT 64
  34. # else
  35. # define RCU_FANOUT 32
  36. # endif
  37. #endif /* #else #ifdef CONFIG_RCU_FANOUT */
  38. #ifdef CONFIG_RCU_FANOUT_LEAF
  39. #define RCU_FANOUT_LEAF CONFIG_RCU_FANOUT_LEAF
  40. #else /* #ifdef CONFIG_RCU_FANOUT_LEAF */
  41. #define RCU_FANOUT_LEAF 16
  42. #endif /* #else #ifdef CONFIG_RCU_FANOUT_LEAF */
  43. #define RCU_FANOUT_1 (RCU_FANOUT_LEAF)
  44. #define RCU_FANOUT_2 (RCU_FANOUT_1 * RCU_FANOUT)
  45. #define RCU_FANOUT_3 (RCU_FANOUT_2 * RCU_FANOUT)
  46. #define RCU_FANOUT_4 (RCU_FANOUT_3 * RCU_FANOUT)
  47. #if NR_CPUS <= RCU_FANOUT_1
  48. # define RCU_NUM_LVLS 1
  49. # define NUM_RCU_LVL_0 1
  50. # define NUM_RCU_NODES NUM_RCU_LVL_0
  51. # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0 }
  52. # define RCU_NODE_NAME_INIT { "rcu_node_0" }
  53. # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0" }
  54. #elif NR_CPUS <= RCU_FANOUT_2
  55. # define RCU_NUM_LVLS 2
  56. # define NUM_RCU_LVL_0 1
  57. # define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1)
  58. # define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1)
  59. # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1 }
  60. # define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1" }
  61. # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1" }
  62. #elif NR_CPUS <= RCU_FANOUT_3
  63. # define RCU_NUM_LVLS 3
  64. # define NUM_RCU_LVL_0 1
  65. # define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_2)
  66. # define NUM_RCU_LVL_2 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1)
  67. # define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2)
  68. # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1, NUM_RCU_LVL_2 }
  69. # define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1", "rcu_node_2" }
  70. # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1", "rcu_node_fqs_2" }
  71. #elif NR_CPUS <= RCU_FANOUT_4
  72. # define RCU_NUM_LVLS 4
  73. # define NUM_RCU_LVL_0 1
  74. # define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_3)
  75. # define NUM_RCU_LVL_2 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_2)
  76. # define NUM_RCU_LVL_3 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1)
  77. # define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2 + NUM_RCU_LVL_3)
  78. # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1, NUM_RCU_LVL_2, NUM_RCU_LVL_3 }
  79. # define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1", "rcu_node_2", "rcu_node_3" }
  80. # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1", "rcu_node_fqs_2", "rcu_node_fqs_3" }
  81. #else
  82. # error "CONFIG_RCU_FANOUT insufficient for NR_CPUS"
  83. #endif /* #if (NR_CPUS) <= RCU_FANOUT_1 */
  84. #endif /* __LINUX_RCU_NODE_TREE_H */