162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * RCU node combining tree definitions. These are used to compute 462306a36Sopenharmony_ci * global attributes while avoiding common-case global contention. A key 562306a36Sopenharmony_ci * property that these computations rely on is a tournament-style approach 662306a36Sopenharmony_ci * where only one of the tasks contending a lower level in the tree need 762306a36Sopenharmony_ci * advance to the next higher level. If properly configured, this allows 862306a36Sopenharmony_ci * unlimited scalability while maintaining a constant level of contention 962306a36Sopenharmony_ci * on the root node. 1062306a36Sopenharmony_ci * 1162306a36Sopenharmony_ci * This seemingly RCU-private file must be available to SRCU users 1262306a36Sopenharmony_ci * because the size of the TREE SRCU srcu_struct structure depends 1362306a36Sopenharmony_ci * on these definitions. 1462306a36Sopenharmony_ci * 1562306a36Sopenharmony_ci * Copyright IBM Corporation, 2017 1662306a36Sopenharmony_ci * 1762306a36Sopenharmony_ci * Author: Paul E. McKenney <paulmck@linux.ibm.com> 1862306a36Sopenharmony_ci */ 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci#ifndef __LINUX_RCU_NODE_TREE_H 2162306a36Sopenharmony_ci#define __LINUX_RCU_NODE_TREE_H 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci#include <linux/math.h> 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci/* 2662306a36Sopenharmony_ci * Define shape of hierarchy based on NR_CPUS, CONFIG_RCU_FANOUT, and 2762306a36Sopenharmony_ci * CONFIG_RCU_FANOUT_LEAF. 2862306a36Sopenharmony_ci * In theory, it should be possible to add more levels straightforwardly. 2962306a36Sopenharmony_ci * In practice, this did work well going from three levels to four. 3062306a36Sopenharmony_ci * Of course, your mileage may vary. 3162306a36Sopenharmony_ci */ 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci#ifdef CONFIG_RCU_FANOUT 3462306a36Sopenharmony_ci#define RCU_FANOUT CONFIG_RCU_FANOUT 3562306a36Sopenharmony_ci#else /* #ifdef CONFIG_RCU_FANOUT */ 3662306a36Sopenharmony_ci# ifdef CONFIG_64BIT 3762306a36Sopenharmony_ci# define RCU_FANOUT 64 3862306a36Sopenharmony_ci# else 3962306a36Sopenharmony_ci# define RCU_FANOUT 32 4062306a36Sopenharmony_ci# endif 4162306a36Sopenharmony_ci#endif /* #else #ifdef CONFIG_RCU_FANOUT */ 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci#ifdef CONFIG_RCU_FANOUT_LEAF 4462306a36Sopenharmony_ci#define RCU_FANOUT_LEAF CONFIG_RCU_FANOUT_LEAF 4562306a36Sopenharmony_ci#else /* #ifdef CONFIG_RCU_FANOUT_LEAF */ 4662306a36Sopenharmony_ci#define RCU_FANOUT_LEAF 16 4762306a36Sopenharmony_ci#endif /* #else #ifdef CONFIG_RCU_FANOUT_LEAF */ 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci#define RCU_FANOUT_1 (RCU_FANOUT_LEAF) 5062306a36Sopenharmony_ci#define RCU_FANOUT_2 (RCU_FANOUT_1 * RCU_FANOUT) 5162306a36Sopenharmony_ci#define RCU_FANOUT_3 (RCU_FANOUT_2 * RCU_FANOUT) 5262306a36Sopenharmony_ci#define RCU_FANOUT_4 (RCU_FANOUT_3 * RCU_FANOUT) 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci#if NR_CPUS <= RCU_FANOUT_1 5562306a36Sopenharmony_ci# define RCU_NUM_LVLS 1 5662306a36Sopenharmony_ci# define NUM_RCU_LVL_0 1 5762306a36Sopenharmony_ci# define NUM_RCU_NODES NUM_RCU_LVL_0 5862306a36Sopenharmony_ci# define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0 } 5962306a36Sopenharmony_ci# define RCU_NODE_NAME_INIT { "rcu_node_0" } 6062306a36Sopenharmony_ci# define RCU_FQS_NAME_INIT { "rcu_node_fqs_0" } 6162306a36Sopenharmony_ci#elif NR_CPUS <= RCU_FANOUT_2 6262306a36Sopenharmony_ci# define RCU_NUM_LVLS 2 6362306a36Sopenharmony_ci# define NUM_RCU_LVL_0 1 6462306a36Sopenharmony_ci# define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1) 6562306a36Sopenharmony_ci# define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1) 6662306a36Sopenharmony_ci# define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1 } 6762306a36Sopenharmony_ci# define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1" } 6862306a36Sopenharmony_ci# define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1" } 6962306a36Sopenharmony_ci#elif NR_CPUS <= RCU_FANOUT_3 7062306a36Sopenharmony_ci# define RCU_NUM_LVLS 3 7162306a36Sopenharmony_ci# define NUM_RCU_LVL_0 1 7262306a36Sopenharmony_ci# define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_2) 7362306a36Sopenharmony_ci# define NUM_RCU_LVL_2 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1) 7462306a36Sopenharmony_ci# define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2) 7562306a36Sopenharmony_ci# define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1, NUM_RCU_LVL_2 } 7662306a36Sopenharmony_ci# define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1", "rcu_node_2" } 7762306a36Sopenharmony_ci# define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1", "rcu_node_fqs_2" } 7862306a36Sopenharmony_ci#elif NR_CPUS <= RCU_FANOUT_4 7962306a36Sopenharmony_ci# define RCU_NUM_LVLS 4 8062306a36Sopenharmony_ci# define NUM_RCU_LVL_0 1 8162306a36Sopenharmony_ci# define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_3) 8262306a36Sopenharmony_ci# define NUM_RCU_LVL_2 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_2) 8362306a36Sopenharmony_ci# define NUM_RCU_LVL_3 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1) 8462306a36Sopenharmony_ci# define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2 + NUM_RCU_LVL_3) 8562306a36Sopenharmony_ci# define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1, NUM_RCU_LVL_2, NUM_RCU_LVL_3 } 8662306a36Sopenharmony_ci# define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1", "rcu_node_2", "rcu_node_3" } 8762306a36Sopenharmony_ci# define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1", "rcu_node_fqs_2", "rcu_node_fqs_3" } 8862306a36Sopenharmony_ci#else 8962306a36Sopenharmony_ci# error "CONFIG_RCU_FANOUT insufficient for NR_CPUS" 9062306a36Sopenharmony_ci#endif /* #if (NR_CPUS) <= RCU_FANOUT_1 */ 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci#endif /* __LINUX_RCU_NODE_TREE_H */ 93