D.3.2.5 rcu_needs_cpu() and rcu_cpu_notify()
Keywords: perfbook_html

###
D.3.2.5 `rcu_needs_cpu()` and `rcu_cpu_notify()`

Figure: `rcu_needs_cpu()` and `rcu_cpu_notify` Code

Figure shows the code for rcu_needs_cpu() and rcu_cpu_notify(), which are invoked by the Linux kernel to check on switching to dynticks-idle mode and to handle CPU hotplug, respectively.

Lines 1-5 show rcu_needs_cpu(), which simply checks if the specified CPU has either ``rcu'' (line 3) or ``rcu_bh'' (line 4) callbacks.

Lines 7-28 show rcu_cpu_notify(), which is a very typical CPU-hotplug notifier function with the typical switch statement. Line 16 invokes rcu_online_cpu() if the specified CPU is going to be coming online, and line 22 invokes rcu_offline_cpu() if the specified CPU has gone to be going offline. It is important to note that CPU-hotplug operations are not atomic, but rather happen in stages that can extend for multiple grace periods. RCU must therefore gracefully handle CPUs that are in the process of coming or going.