文章目录
- 一、RCU 层次架构概念及源码
- 二、RCU 层次架构源码解析
- 1、RCU 层次架构每层最多叶子数
- 2、RCU 层次架构每个叶子 CPU 数量
一、RCU 层次架构概念及源码
RCU 机制 中 , 会 根据 CPU 数量 , 按照 " 树形结构 “ 组成 RCU 层次架构 , 称为 ” RCU Hierarchy " ;
在 Linux 源码 linux-5.6.18includelinuxrcu_node_tree.h
头文件中定义了 RCU 层次架构 ,
RCU 层次架构 源码 :
代码语言:javascript复制/*
* Define shape of hierarchy based on NR_CPUS, CONFIG_RCU_FANOUT, and
* CONFIG_RCU_FANOUT_LEAF.
* In theory, it should be possible to add more levels straightforwardly.
* In practice, this did work well going from three levels to four.
* Of course, your mileage may vary.
*/
#ifdef CONFIG_RCU_FANOUT
#define RCU_FANOUT CONFIG_RCU_FANOUT
#else /* #ifdef CONFIG_RCU_FANOUT */
# ifdef CONFIG_64BIT
# define RCU_FANOUT 64
# else
# define RCU_FANOUT 32
# endif
#endif /* #else #ifdef CONFIG_RCU_FANOUT */
#ifdef CONFIG_RCU_FANOUT_LEAF
#define RCU_FANOUT_LEAF CONFIG_RCU_FANOUT_LEAF
#else /* #ifdef CONFIG_RCU_FANOUT_LEAF */
#define RCU_FANOUT_LEAF 16
#endif /* #else #ifdef CONFIG_RCU_FANOUT_LEAF */
#define RCU_FANOUT_1 (RCU_FANOUT_LEAF)
#define RCU_FANOUT_2 (RCU_FANOUT_1 * RCU_FANOUT)
#define RCU_FANOUT_3 (RCU_FANOUT_2 * RCU_FANOUT)
#define RCU_FANOUT_4 (RCU_FANOUT_3 * RCU_FANOUT)
源码路径 : linux-5.6.18includelinuxrcu_node_tree.h#31
二、RCU 层次架构源码解析
" RCU 层次架构 “ 是 根据 ” CPU 数量 " 确定的 ,
在 Linux 内核源码中 , 通过各种 " 宏定义 “ 构建 ” RCU 层次架构 " ,
1、RCU 层次架构每层最多叶子数
CONFIG_RCU_FANOUT
宏 , 表示 每个层次 支持的最多的叶子个数 ;
#ifdef CONFIG_RCU_FANOUT
#define RCU_FANOUT CONFIG_RCU_FANOUT
#else /* #ifdef CONFIG_RCU_FANOUT */
# ifdef CONFIG_64BIT
# define RCU_FANOUT 64
# else
# define RCU_FANOUT 32
# endif
#endif /* #else #ifdef CONFIG_RCU_FANOUT */
2、RCU 层次架构每个叶子 CPU 数量
CONFIG_RCU_FANOUT_LEAF
宏 , 表示 每个 子叶 对应的 CPU 数量 ;
#ifdef CONFIG_RCU_FANOUT_LEAF
#define RCU_FANOUT_LEAF CONFIG_RCU_FANOUT_LEAF
#else /* #ifdef CONFIG_RCU_FANOUT_LEAF */
#define RCU_FANOUT_LEAF 16
#endif /* #else #ifdef CONFIG_RCU_FANOUT_LEAF */