D.3.3.3 __rcu_init()

Figure: __rcu_init() Code
\begin{figure}{ \scriptsize
\begin{verbatim}1  ...

Figure [*] shows the __rcu_init() function and its RCU_DATA_PTR_INIT() helper macro. The __rcu_init() function is invoked during early boot, before the scheduler has initialized, and before more than one CPU is running.

The RCU_DATA_PTR_INIT() macro takes as arguments a pointer to an rcu_state structure and the name of a set of rcu_data per-CPU variables. This macro scans the per-CPU rcu_data structures, assigning the ->mynode pointer of each rcu_data structure to point to the corresponding leaf rcu_node structure. It also fills out the specified rcu_state structure's ->rda[] array entries to each point to the corresponding rcu_data structure. Line 3 picks up a pointer to the first leaf rcu_node structure in local variable rnp (which must be declared by the invoker of this macro), and line 4 sets local variable j to the corresponding leaf-node number of zero. Each pass through the loop spanning lines 5-10 performs initialization for the corresponding potential CPU (as specified by NR_CPUS). Within this loop, line 6 checks to see if we have moved beyond the bounds of the current leaf rcu_node structure, and, if so, line 7 advances to the next structure. Then, still within the loop, line 8 sets the ->mynode pointer of the current CPU's rcu_data structure to reference the current leaf rcu_node structure, and line 9 sets the current CPU's ->rda[] element (within the rcu_state structure) to reference the current CPU's rcu_data structure.

Quick Quiz D.34: C-preprocessor macros are so 1990s! Why not get with the times and convert RCU_DATA_PTR_INIT() in Figure [*] to be a function? End Quick Quiz

The __rcu_init() function first invokes rcu_init_one() on the rcu_state structure on line 19, then invokes RCU_DATA_PTR_INIT() on the rcu_state structure and the rcu_data set of per-CPU variables. It then repeats this for rcu_bh_state and rcu_bh_data on lines 21-22. The loop spanning lines 24-26 invokes rcu_cpu_notify() for each CPU that is currently online (which should be only the boot CPU), and line 27 registers a notifier so that rcu_cpu_notify() will be invoked each time a CPU comes online, in order to inform RCU of its presence.

Quick Quiz D.35: What happens if a CPU comes online between the time that the last online CPU is notified on lines 25-26 of Figure [*] and the time that register_cpu_notifier() is invoked on line 27? End Quick Quiz

The rcu_cpu_notify() and related functions are discussed in Section [*] below.

Paul E. McKenney 2011-12-16