sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget>/translations/zh_CN/RCU/Design/Data-Structures/Data-StructuresmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget>/translations/zh_TW/RCU/Design/Data-Structures/Data-StructuresmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget>/translations/it_IT/RCU/Design/Data-Structures/Data-StructuresmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget>/translations/ja_JP/RCU/Design/Data-Structures/Data-StructuresmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget>/translations/ko_KR/RCU/Design/Data-Structures/Data-StructuresmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget>/translations/sp_SP/RCU/Design/Data-Structures/Data-StructuresmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhsection)}(hhh](htitle)}(h3A Tour Through TREE_RCU's Data Structures [LWN.net]h]h5A Tour Through TREE_RCU’s Data Structures [LWN.net]}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhX/var/lib/git/docbuild/linux/Documentation/RCU/Design/Data-Structures/Data-Structures.rsthKubh paragraph)}(hDecember 18, 2016h]hDecember 18, 2016}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(h0This article was contributed by Paul E. McKenneyh]h0This article was contributed by Paul E. McKenney}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hhh](h)}(h Introductionh]h Introduction}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhK ubh)}(hYThis document describes RCU's major data structures and their relationship to each other.h]h[This document describes RCU’s major data structures and their relationship to each other.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhhhubeh}(h] introductionah ]h"] introductionah$]h&]uh1hhhhhhhhK ubh)}(hhh](h)}(hData-Structure Relationshipsh]hData-Structure Relationships}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh)}(hXRCU is for all intents and purposes a large state machine, and its data structures maintain the state in such a way as to allow RCU readers to execute extremely quickly, while also processing the RCU grace periods requested by updaters in an efficient and extremely scalable fashion. The efficiency and scalability of RCU updaters is provided primarily by a combining tree, as shown below:h]hXRCU is for all intents and purposes a large state machine, and its data structures maintain the state in such a way as to allow RCU readers to execute extremely quickly, while also processing the RCU grace periods requested by updaters in an efficient and extremely scalable fashion. The efficiency and scalability of RCU updaters is provided primarily by a combining tree, as shown below:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubkfigure kernel_figure)}(hhh]hfigure)}(hhh]himage)}(h).. kernel-figure:: BigTreeClassicRCU.svg h]h}(h]h ]h"]h$]h&]uri0RCU/Design/Data-Structures/BigTreeClassicRCU.svg candidates}*j3suh1j&hj#hhhKubah}(h]h ]h"]h$]h&]uh1j!hjubah}(h]h ]h"]h$]h&]uh1jhhhhhhhKubh)}(hXThis diagram shows an enclosing ``rcu_state`` structure containing a tree of ``rcu_node`` structures. Each leaf node of the ``rcu_node`` tree has up to 16 ``rcu_data`` structures associated with it, so that there are ``NR_CPUS`` number of ``rcu_data`` structures, one for each possible CPU. This structure is adjusted at boot time, if needed, to handle the common case where ``nr_cpu_ids`` is much less than ``NR_CPUs``. For example, a number of Linux distributions set ``NR_CPUs=4096``, which results in a three-level ``rcu_node`` tree. If the actual hardware has only 16 CPUs, RCU will adjust itself at boot time, resulting in an ``rcu_node`` tree with only a single node.h](h This diagram shows an enclosing }(hjChhhNhNubhliteral)}(h ``rcu_state``h]h rcu_state}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjCubh structure containing a tree of }(hjChhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj_hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjCubh# structures. Each leaf node of the }(hjChhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjqhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjCubh tree has up to 16 }(hjChhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjCubh2 structures associated with it, so that there are }(hjChhhNhNubjL)}(h ``NR_CPUS``h]hNR_CPUS}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjCubh number of }(hjChhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjCubh| structures, one for each possible CPU. This structure is adjusted at boot time, if needed, to handle the common case where }(hjChhhNhNubjL)}(h``nr_cpu_ids``h]h nr_cpu_ids}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjCubh is much less than }(hjChhhNhNubjL)}(h ``NR_CPUs``h]hNR_CPUs}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjCubh3. For example, a number of Linux distributions set }(hjChhhNhNubjL)}(h``NR_CPUs=4096``h]h NR_CPUs=4096}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjCubh!, which results in a three-level }(hjChhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjCubhe tree. If the actual hardware has only 16 CPUs, RCU will adjust itself at boot time, resulting in an }(hjChhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjCubh tree with only a single node.}(hjChhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hXThe purpose of this combining tree is to allow per-CPU events such as quiescent states, dyntick-idle transitions, and CPU hotplug operations to be processed efficiently and scalably. Quiescent states are recorded by the per-CPU ``rcu_data`` structures, and other events are recorded by the leaf-level ``rcu_node`` structures. All of these events are combined at each level of the tree until finally grace periods are completed at the tree's root ``rcu_node`` structure. A grace period can be completed at the root once every CPU (or, in the case of ``CONFIG_PREEMPT_RCU``, task) has passed through a quiescent state. Once a grace period has completed, record of that fact is propagated back down the tree.h](hThe purpose of this combining tree is to allow per-CPU events such as quiescent states, dyntick-idle transitions, and CPU hotplug operations to be processed efficiently and scalably. Quiescent states are recorded by the per-CPU }(hjhhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh= structures, and other events are recorded by the leaf-level }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj3hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh structures. All of these events are combined at each level of the tree until finally grace periods are completed at the tree’s root }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjEhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh[ structure. A grace period can be completed at the root once every CPU (or, in the case of }(hjhhhNhNubjL)}(h``CONFIG_PREEMPT_RCU``h]hCONFIG_PREEMPT_RCU}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh, task) has passed through a quiescent state. Once a grace period has completed, record of that fact is propagated back down the tree.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK&hhhhubh)}(hAs can be seen from the diagram, on a 64-bit system a two-level tree with 64 leaves can accommodate 1,024 CPUs, with a fanout of 64 at the root and a fanout of 16 at the leaves.h]hAs can be seen from the diagram, on a 64-bit system a two-level tree with 64 leaves can accommodate 1,024 CPUs, with a fanout of 64 at the root and a fanout of 16 at the leaves.}(hjohhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK6hhhhubhtable)}(hhh]htgroup)}(hhh](hcolspec)}(hhh]h}(h]h ]h"]h$]h&]colwidthKGuh1jhjubhtbody)}(hhh](hrow)}(hhh]hentry)}(hhh]h)}(h**Quick Quiz**:h](hstrong)}(h**Quick Quiz**h]h Quick Quiz}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK;hjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]j)}(hhh]h)}(h+Why isn't the fanout at the leaves also 64?h]h-Why isn’t the fanout at the leaves also 64?}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK=hjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]j)}(hhh]h)}(h **Answer**:h](j)}(h **Answer**h]hAnswer}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK?hjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]j)}(hhh](h)}(hX|Because there are more types of events that affect the leaf-level ``rcu_node`` structures than further up the tree. Therefore, if the leaf ``rcu_node`` structures have fanout of 64, the contention on these structures' ``->structures`` becomes excessive. Experimentation on a wide variety of systems has shown that a fanout of 16 works well for the leaves of the ``rcu_node`` tree.h](hBBecause there are more types of events that affect the leaf-level }(hj hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh= structures than further up the tree. Therefore, if the leaf }(hj hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj:hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubhE structures have fanout of 64, the contention on these structures’ }(hj hhhNhNubjL)}(h``->structures``h]h ->structures}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh becomes excessive. Experimentation on a wide variety of systems has shown that a fanout of 16 works well for the leaves of the }(hj hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj^hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh tree.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKAhjubh)}(hXOf course, further experience with systems having hundreds or thousands of CPUs may demonstrate that the fanout for the non-leaf ``rcu_node`` structures must also be reduced. Such reduction can be easily carried out when and if it proves necessary. In the meantime, if you are using such a system and running into contention problems on the non-leaf ``rcu_node`` structures, you may use the ``CONFIG_RCU_FANOUT`` kernel configuration parameter to reduce the non-leaf fanout as needed.h](hOf course, further experience with systems having hundreds or thousands of CPUs may demonstrate that the fanout for the non-leaf }(hjvhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj~hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjvubh structures must also be reduced. Such reduction can be easily carried out when and if it proves necessary. In the meantime, if you are using such a system and running into contention problems on the non-leaf }(hjvhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjvubh structures, you may use the }(hjvhhhNhNubjL)}(h``CONFIG_RCU_FANOUT``h]hCONFIG_RCU_FANOUT}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjvubhH kernel configuration parameter to reduce the non-leaf fanout as needed.}(hjvhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKHhjubh)}(hKernels built for systems with strong NUMA characteristics might also need to adjust ``CONFIG_RCU_FANOUT`` so that the domains of the ``rcu_node`` structures align with hardware boundaries. However, there has thus far been no need for this.h](hUKernels built for systems with strong NUMA characteristics might also need to adjust }(hjhhhNhNubjL)}(h``CONFIG_RCU_FANOUT``h]hCONFIG_RCU_FANOUT}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh so that the domains of the }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh^ structures align with hardware boundaries. However, there has thus far been no need for this.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKQhjubeh}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]colsKuh1jhjubah}(h]h ]h"]h$]h&]uh1j}hhhhhhhNubh)}(hXIf your system has more than 1,024 CPUs (or more than 512 CPUs on a 32-bit system), then RCU will automatically add more levels to the tree. For example, if you are crazy enough to build a 64-bit system with 65,536 CPUs, RCU would configure the ``rcu_node`` tree as follows:h](hIf your system has more than 1,024 CPUs (or more than 512 CPUs on a 32-bit system), then RCU will automatically add more levels to the tree. For example, if you are crazy enough to build a 64-bit system with 65,536 CPUs, RCU would configure the }(hj hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh tree as follows:}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKWhhhhubj)}(hhh]j")}(hhh]j')}(h*.. kernel-figure:: HugeTreeClassicRCU.svg h]h}(h]h ]h"]h$]h&]uri1RCU/Design/Data-Structures/HugeTreeClassicRCU.svgj4}j6j<suh1j&hj.hhhKubah}(h]h ]h"]h$]h&]uh1j!hj+ubah}(h]h ]h"]h$]h&]uh1jhhhhhhhK]ubh)}(hXRCU currently permits up to a four-level tree, which on a 64-bit system accommodates up to 4,194,304 CPUs, though only a mere 524,288 CPUs for 32-bit systems. On the other hand, you can set both ``CONFIG_RCU_FANOUT`` and ``CONFIG_RCU_FANOUT_LEAF`` to be as small as 2, which would result in a 16-CPU test using a 4-level tree. This can be useful for testing large-system capabilities on small test machines.h](hRCU currently permits up to a four-level tree, which on a 64-bit system accommodates up to 4,194,304 CPUs, though only a mere 524,288 CPUs for 32-bit systems. On the other hand, you can set both }(hjJhhhNhNubjL)}(h``CONFIG_RCU_FANOUT``h]hCONFIG_RCU_FANOUT}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjJubh and }(hjJhhhNhNubjL)}(h``CONFIG_RCU_FANOUT_LEAF``h]hCONFIG_RCU_FANOUT_LEAF}(hjdhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjJubh to be as small as 2, which would result in a 16-CPU test using a 4-level tree. This can be useful for testing large-system capabilities on small test machines.}(hjJhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK^hhhhubh)}(hXThis multi-level combining tree allows us to get most of the performance and scalability benefits of partitioning, even though RCU grace-period detection is inherently a global operation. The trick here is that only the last CPU to report a quiescent state into a given ``rcu_node`` structure need advance to the ``rcu_node`` structure at the next level up the tree. This means that at the leaf-level ``rcu_node`` structure, only one access out of sixteen will progress up the tree. For the internal ``rcu_node`` structures, the situation is even more extreme: Only one access out of sixty-four will progress up the tree. Because the vast majority of the CPUs do not progress up the tree, the lock contention remains roughly constant up the tree. No matter how many CPUs there are in the system, at most 64 quiescent-state reports per grace period will progress all the way to the root ``rcu_node`` structure, thus ensuring that the lock contention on that root ``rcu_node`` structure remains acceptably low.h](hXThis multi-level combining tree allows us to get most of the performance and scalability benefits of partitioning, even though RCU grace-period detection is inherently a global operation. The trick here is that only the last CPU to report a quiescent state into a given }(hj|hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj|ubh structure need advance to the }(hj|hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj|ubhL structure at the next level up the tree. This means that at the leaf-level }(hj|hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj|ubhW structure, only one access out of sixteen will progress up the tree. For the internal }(hj|hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj|ubhXv structures, the situation is even more extreme: Only one access out of sixty-four will progress up the tree. Because the vast majority of the CPUs do not progress up the tree, the lock contention remains roughly constant up the tree. No matter how many CPUs there are in the system, at most 64 quiescent-state reports per grace period will progress all the way to the root }(hj|hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj|ubh@ structure, thus ensuring that the lock contention on that root }(hj|hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj|ubh" structure remains acceptably low.}(hj|hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKehhhhubh)}(hIn effect, the combining tree acts like a big shock absorber, keeping lock contention under control at all tree levels regardless of the level of loading on the system.h]hIn effect, the combining tree acts like a big shock absorber, keeping lock contention under control at all tree levels regardless of the level of loading on the system.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKuhhhhubh)}(hX]RCU updaters wait for normal grace periods by registering RCU callbacks, either directly via ``call_rcu()`` or indirectly via ``synchronize_rcu()`` and friends. RCU callbacks are represented by ``rcu_head`` structures, which are queued on ``rcu_data`` structures while they are waiting for a grace period to elapse, as shown in the following figure:h](h]RCU updaters wait for normal grace periods by registering RCU callbacks, either directly via }(hjhhhNhNubjL)}(h``call_rcu()``h]h call_rcu()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh or indirectly via }(hjhhhNhNubjL)}(h``synchronize_rcu()``h]hsynchronize_rcu()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh/ and friends. RCU callbacks are represented by }(hjhhhNhNubjL)}(h ``rcu_head``h]hrcu_head}(hj0hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh! structures, which are queued on }(hjhhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhb structures while they are waiting for a grace period to elapse, as shown in the following figure:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKyhhhhubj)}(hhh]j")}(hhh]j')}(h4.. kernel-figure:: BigTreePreemptRCUBHdyntickCB.svg h]h}(h]h ]h"]h$]h&]uri;RCU/Design/Data-Structures/BigTreePreemptRCUBHdyntickCB.svgj4}j6jksuh1j&hj]hhhKubah}(h]h ]h"]h$]h&]uh1j!hjZubah}(h]h ]h"]h$]h&]uh1jhhhhhhhKubh)}(hThis figure shows how ``TREE_RCU``'s and ``PREEMPT_RCU``'s major data structures are related. Lesser data structures will be introduced with the algorithms that make use of them.h](hThis figure shows how }(hjyhhhNhNubjL)}(h ``TREE_RCU``h]hTREE_RCU}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjyubh ’s and }(hjyhhhNhNubjL)}(h``PREEMPT_RCU``h]h PREEMPT_RCU}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjyubh|’s major data structures are related. Lesser data structures will be introduced with the algorithms that make use of them.}(hjyhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hVNote that each of the data structures in the above figure has its own synchronization:h]hVNote that each of the data structures in the above figure has its own synchronization:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubhenumerated_list)}(hhh](h list_item)}(hEach ``rcu_state`` structures has a lock and a mutex, and some fields are protected by the corresponding root ``rcu_node`` structure's lock.h]h)}(hEach ``rcu_state`` structures has a lock and a mutex, and some fields are protected by the corresponding root ``rcu_node`` structure's lock.h](hEach }(hjhhhNhNubjL)}(h ``rcu_state``h]h rcu_state}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh\ structures has a lock and a mutex, and some fields are protected by the corresponding root }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh structure’s lock.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(h+Each ``rcu_node`` structure has a spinlock.h]h)}(hjh](hEach }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh structure has a spinlock.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(hwThe fields in ``rcu_data`` are private to the corresponding CPU, although a few can be read and written by other CPUs. h]h)}(hvThe fields in ``rcu_data`` are private to the corresponding CPU, although a few can be read and written by other CPUs.h](hThe fields in }(hj)hhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hj1hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj)ubh\ are private to the corresponding CPU, although a few can be read and written by other CPUs.}(hj)hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj%ubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubeh}(h]h ]h"]h$]h&]enumtypearabicprefixhsuffix.uh1jhhhhhhhKubh)}(hX)It is important to note that different data structures can have very different ideas about the state of RCU at any given time. For but one example, awareness of the start or end of a given RCU grace period propagates slowly through the data structures. This slow propagation is absolutely necessary for RCU to have good read-side performance. If this balkanized implementation seems foreign to you, one useful trick is to consider each instance of these data structures to be a different person, each having the usual slightly different view of reality.h]hX)It is important to note that different data structures can have very different ideas about the state of RCU at any given time. For but one example, awareness of the start or end of a given RCU grace period propagates slowly through the data structures. This slow propagation is absolutely necessary for RCU to have good read-side performance. If this balkanized implementation seems foreign to you, one useful trick is to consider each instance of these data structures to be a different person, each having the usual slightly different view of reality.}(hjZhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(h@The general role of each of these data structures is as follows:h]h@The general role of each of these data structures is as follows:}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubj)}(hhh](j)}(hXp``rcu_state``: This structure forms the interconnection between the ``rcu_node`` and ``rcu_data`` structures, tracks grace periods, serves as short-term repository for callbacks orphaned by CPU-hotplug events, maintains ``rcu_barrier()`` state, tracks expedited grace-period state, and maintains state used to force quiescent states when grace periods extend too long,h]h)}(hXp``rcu_state``: This structure forms the interconnection between the ``rcu_node`` and ``rcu_data`` structures, tracks grace periods, serves as short-term repository for callbacks orphaned by CPU-hotplug events, maintains ``rcu_barrier()`` state, tracks expedited grace-period state, and maintains state used to force quiescent states when grace periods extend too long,h](jL)}(h ``rcu_state``h]h rcu_state}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj}ubh7: This structure forms the interconnection between the }(hj}hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj}ubh and }(hj}hhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj}ubh{ structures, tracks grace periods, serves as short-term repository for callbacks orphaned by CPU-hotplug events, maintains }(hj}hhhNhNubjL)}(h``rcu_barrier()``h]h rcu_barrier()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj}ubh state, tracks expedited grace-period state, and maintains state used to force quiescent states when grace periods extend too long,}(hj}hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjyubah}(h]h ]h"]h$]h&]uh1jhjvhhhhhNubj)}(hX5``rcu_node``: This structure forms the combining tree that propagates quiescent-state information from the leaves to the root, and also propagates grace-period information from the root to the leaves. It provides local copies of the grace-period state in order to allow this information to be accessed in a synchronized manner without suffering the scalability limitations that would otherwise be imposed by global locking. In ``CONFIG_PREEMPT_RCU`` kernels, it manages the lists of tasks that have blocked while in their current RCU read-side critical section. In ``CONFIG_PREEMPT_RCU`` with ``CONFIG_RCU_BOOST``, it manages the per-\ ``rcu_node`` priority-boosting kernel threads (kthreads) and state. Finally, it records CPU-hotplug state in order to determine which CPUs should be ignored during a given grace period.h]h)}(hX5``rcu_node``: This structure forms the combining tree that propagates quiescent-state information from the leaves to the root, and also propagates grace-period information from the root to the leaves. It provides local copies of the grace-period state in order to allow this information to be accessed in a synchronized manner without suffering the scalability limitations that would otherwise be imposed by global locking. In ``CONFIG_PREEMPT_RCU`` kernels, it manages the lists of tasks that have blocked while in their current RCU read-side critical section. In ``CONFIG_PREEMPT_RCU`` with ``CONFIG_RCU_BOOST``, it manages the per-\ ``rcu_node`` priority-boosting kernel threads (kthreads) and state. Finally, it records CPU-hotplug state in order to determine which CPUs should be ignored during a given grace period.h](jL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhX: This structure forms the combining tree that propagates quiescent-state information from the leaves to the root, and also propagates grace-period information from the root to the leaves. It provides local copies of the grace-period state in order to allow this information to be accessed in a synchronized manner without suffering the scalability limitations that would otherwise be imposed by global locking. In }(hjhhhNhNubjL)}(h``CONFIG_PREEMPT_RCU``h]hCONFIG_PREEMPT_RCU}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubht kernels, it manages the lists of tasks that have blocked while in their current RCU read-side critical section. In }(hjhhhNhNubjL)}(h``CONFIG_PREEMPT_RCU``h]hCONFIG_PREEMPT_RCU}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh with }(hjhhhNhNubjL)}(h``CONFIG_RCU_BOOST``h]hCONFIG_RCU_BOOST}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh, it manages the per- }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh priority-boosting kernel threads (kthreads) and state. Finally, it records CPU-hotplug state in order to determine which CPUs should be ignored during a given grace period.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjvhhhhhNubj)}(hX3``rcu_data``: This per-CPU structure is the focus of quiescent-state detection and RCU callback queuing. It also tracks its relationship to the corresponding leaf ``rcu_node`` structure to allow more-efficient propagation of quiescent states up the ``rcu_node`` combining tree. Like the ``rcu_node`` structure, it provides a local copy of the grace-period information to allow for-free synchronized access to this information from the corresponding CPU. Finally, this structure records past dyntick-idle state for the corresponding CPU and also tracks statistics.h]h)}(hX3``rcu_data``: This per-CPU structure is the focus of quiescent-state detection and RCU callback queuing. It also tracks its relationship to the corresponding leaf ``rcu_node`` structure to allow more-efficient propagation of quiescent states up the ``rcu_node`` combining tree. Like the ``rcu_node`` structure, it provides a local copy of the grace-period information to allow for-free synchronized access to this information from the corresponding CPU. Finally, this structure records past dyntick-idle state for the corresponding CPU and also tracks statistics.h](jL)}(h ``rcu_data``h]hrcu_data}(hjKhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjGubh: This per-CPU structure is the focus of quiescent-state detection and RCU callback queuing. It also tracks its relationship to the corresponding leaf }(hjGhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj]hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjGubhJ structure to allow more-efficient propagation of quiescent states up the }(hjGhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjohhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjGubh combining tree. Like the }(hjGhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjGubhX structure, it provides a local copy of the grace-period information to allow for-free synchronized access to this information from the corresponding CPU. Finally, this structure records past dyntick-idle state for the corresponding CPU and also tracks statistics.}(hjGhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjCubah}(h]h ]h"]h$]h&]uh1jhjvhhhhhNubj)}(h``rcu_head``: This structure represents RCU callbacks, and is the only structure allocated and managed by RCU users. The ``rcu_head`` structure is normally embedded within the RCU-protected data structure. h]h)}(h``rcu_head``: This structure represents RCU callbacks, and is the only structure allocated and managed by RCU users. The ``rcu_head`` structure is normally embedded within the RCU-protected data structure.h](jL)}(h ``rcu_head``h]hrcu_head}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhm: This structure represents RCU callbacks, and is the only structure allocated and managed by RCU users. The }(hjhhhNhNubjL)}(h ``rcu_head``h]hrcu_head}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhH structure is normally embedded within the RCU-protected data structure.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjvhhhhhNubeh}(h]h ]h"]h$]h&]jUjVjWhjXjYuh1jhhhhhhhKubh)}(hIf all you wanted from this article was a general notion of how RCU's data structures are related, you are done. Otherwise, each of the following sections give more details on the ``rcu_state``, ``rcu_node`` and ``rcu_data`` data structures.h](hIf all you wanted from this article was a general notion of how RCU’s data structures are related, you are done. Otherwise, each of the following sections give more details on the }(hjhhhNhNubjL)}(h ``rcu_state``h]h rcu_state}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh, }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh and }(hjhhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh data structures.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hhh](h)}(hThe ``rcu_state`` Structureh](hThe }(hj$hhhNhNubjL)}(h ``rcu_state``h]h rcu_state}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj$ubh Structure}(hj$hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhj!hhhhhKubh)}(hXlThe ``rcu_state`` structure is the base structure that represents the state of RCU in the system. This structure forms the interconnection between the ``rcu_node`` and ``rcu_data`` structures, tracks grace periods, contains the lock used to synchronize with CPU-hotplug events, and maintains state used to force quiescent states when grace periods extend too long,h](hThe }(hjDhhhNhNubjL)}(h ``rcu_state``h]h rcu_state}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjDubh structure is the base structure that represents the state of RCU in the system. This structure forms the interconnection between the }(hjDhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj^hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjDubh and }(hjDhhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hjphhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjDubh structures, tracks grace periods, contains the lock used to synchronize with CPU-hotplug events, and maintains state used to force quiescent states when grace periods extend too long,}(hjDhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj!hhubh)}(hA few of the ``rcu_state`` structure's fields are discussed, singly and in groups, in the following sections. The more specialized fields are covered in the discussion of their use.h](h A few of the }(hjhhhNhNubjL)}(h ``rcu_state``h]h rcu_state}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh structure’s fields are discussed, singly and in groups, in the following sections. The more specialized fields are covered in the discussion of their use.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj!hhubh)}(hhh](h)}(h0Relationship to rcu_node and rcu_data Structuresh]h0Relationship to rcu_node and rcu_data Structures}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hCThis portion of the ``rcu_state`` structure is declared as follows:h](hThis portion of the }(hjhhhNhNubjL)}(h ``rcu_state``h]h rcu_state}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh" structure is declared as follows:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh literal_block)}(hy1 struct rcu_node node[NUM_RCU_NODES]; 2 struct rcu_node *level[NUM_RCU_LVLS + 1]; 3 struct rcu_data __percpu *rda;h]hy1 struct rcu_node node[NUM_RCU_NODES]; 2 struct rcu_node *level[NUM_RCU_LVLS + 1]; 3 struct rcu_data __percpu *rda;}hjsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1jhhhKhjhhubj~)}(hhh]j)}(hhh](j)}(hhh]h}(h]h ]h"]h$]h&]colwidthKGuh1jhjubj)}(hhh](j)}(hhh]j)}(hhh]h)}(h**Quick Quiz**:h](j)}(h**Quick Quiz**h]h Quick Quiz}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh:}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]j)}(hhh]h)}(hzWait a minute! You said that the ``rcu_node`` structures formed a tree, but they are declared as a flat array! What gives?h](h!Wait a minute! You said that the }(hj2 hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj: hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj2 ubhM structures formed a tree, but they are declared as a flat array! What gives?}(hj2 hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj/ ubah}(h]h ]h"]h$]h&]uh1jhj, ubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]j)}(hhh]h)}(h **Answer**:h](j)}(h **Answer**h]hAnswer}(hjh hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjd ubh:}(hjd hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhja ubah}(h]h ]h"]h$]h&]uh1jhj^ ubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]j)}(hhh]h)}(hXThe tree is laid out in the array. The first node In the array is the head, the next set of nodes in the array are children of the head node, and so on until the last set of nodes in the array are the leaves. See the following diagrams to see how this works.h]hXThe tree is laid out in the array. The first node In the array is the head, the next set of nodes in the array are children of the head node, and so on until the last set of nodes in the array are the leaves. See the following diagrams to see how this works.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhj ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]colsKuh1jhjubah}(h]h ]h"]h$]h&]uh1j}hjhhhhhNubh)}(h_The ``rcu_node`` tree is embedded into the ``->node[]`` array as shown in the following figure:h](hThe }(hj hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh tree is embedded into the }(hj hhhNhNubjL)}(h ``->node[]``h]h->node[]}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh( array as shown in the following figure:}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hhh]j")}(hhh]j')}(h#.. kernel-figure:: TreeMapping.svg h]h}(h]h ]h"]h$]h&]uri*RCU/Design/Data-Structures/TreeMapping.svgj4}j6j suh1j&hj hhhKubah}(h]h ]h"]h$]h&]uh1j!hj ubah}(h]h ]h"]h$]h&]uh1jhjhhhhhKubh)}(hXOne interesting consequence of this mapping is that a breadth-first traversal of the tree is implemented as a simple linear scan of the array, which is in fact what the ``rcu_for_each_node_breadth_first()`` macro does. This macro is used at the beginning and ends of grace periods.h](hOne interesting consequence of this mapping is that a breadth-first traversal of the tree is implemented as a simple linear scan of the array, which is in fact what the }(hj hhhNhNubjL)}(h%``rcu_for_each_node_breadth_first()``h]h!rcu_for_each_node_breadth_first()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubhK macro does. This macro is used at the beginning and ends of grace periods.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hEach entry of the ``->level`` array references the first ``rcu_node`` structure on the corresponding level of the tree, for example, as shown below:h](hEach entry of the }(hj0 hhhNhNubjL)}(h ``->level``h]h->level}(hj8 hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj0 ubh array references the first }(hj0 hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjJ hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj0 ubhO structure on the corresponding level of the tree, for example, as shown below:}(hj0 hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hhh]j")}(hhh]j')}(h(.. kernel-figure:: TreeMappingLevel.svg h]h}(h]h ]h"]h$]h&]uri/RCU/Design/Data-Structures/TreeMappingLevel.svgj4}j6js suh1j&hje hhhKubah}(h]h ]h"]h$]h&]uh1j!hjb ubah}(h]h ]h"]h$]h&]uh1jhjhhhhhKubh)}(hThe zero\ :sup:`th` element of the array references the root ``rcu_node`` structure, the first element references the first child of the root ``rcu_node``, and finally the second element references the first leaf ``rcu_node`` structure.h](h The zero }(hj hhhNhNubh superscript)}(h :sup:`th`h]hth}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh* element of the array references the root }(hj hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubhE structure, the first element references the first child of the root }(hj hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh;, and finally the second element references the first leaf }(hj hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh structure.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hFor whatever it is worth, if you draw the tree to be tree-shaped rather than array-shaped, it is easy to draw a planar representation:h]hFor whatever it is worth, if you draw the tree to be tree-shaped rather than array-shaped, it is easy to draw a planar representation:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hhh]j")}(hhh]j')}(h!.. kernel-figure:: TreeLevel.svg h]h}(h]h ]h"]h$]h&]uri(RCU/Design/Data-Structures/TreeLevel.svgj4}j6j suh1j&hj hhhKubah}(h]h ]h"]h$]h&]uh1j!hj ubah}(h]h ]h"]h$]h&]uh1jhjhhhhhMubh)}(hlFinally, the ``->rda`` field references a per-CPU pointer to the corresponding CPU's ``rcu_data`` structure.h](h Finally, the }(hj hhhNhNubjL)}(h ``->rda``h]h->rda}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubhA field references a per-CPU pointer to the corresponding CPU’s }(hj hhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh structure.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hcAll of these fields are constant once initialization is complete, and therefore need no protection.h]hcAll of these fields are constant once initialization is complete, and therefore need no protection.}(hj8 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubeh}(h]0relationship-to-rcu-node-and-rcu-data-structuresah ]h"]0relationship to rcu_node and rcu_data structuresah$]h&]uh1hhj!hhhhhKubh)}(hhh](h)}(hGrace-Period Trackingh]hGrace-Period Tracking}(hjQ hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjN hhhhhM ubh)}(hCThis portion of the ``rcu_state`` structure is declared as follows:h](hThis portion of the }(hj_ hhhNhNubjL)}(h ``rcu_state``h]h rcu_state}(hjg hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj_ ubh" structure is declared as follows:}(hj_ hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM hjN hhubj)}(h1 unsigned long gp_seq;h]h1 unsigned long gp_seq;}hj sbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjN hhubh)}(hXRCU grace periods are numbered, and the ``->gp_seq`` field contains the current grace-period sequence number. The bottom two bits are the state of the current grace period, which can be zero for not yet started or one for in progress. In other words, if the bottom two bits of ``->gp_seq`` are zero, then RCU is idle. Any other value in the bottom two bits indicates that something is broken. This field is protected by the root ``rcu_node`` structure's ``->lock`` field.h](h(RCU grace periods are numbered, and the }(hj hhhNhNubjL)}(h ``->gp_seq``h]h->gp_seq}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh field contains the current grace-period sequence number. The bottom two bits are the state of the current grace period, which can be zero for not yet started or one for in progress. In other words, if the bottom two bits of }(hj hhhNhNubjL)}(h ``->gp_seq``h]h->gp_seq}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh are zero, then RCU is idle. Any other value in the bottom two bits indicates that something is broken. This field is protected by the root }(hj hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh structure’s }(hj hhhNhNubjL)}(h ``->lock``h]h->lock}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh field.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjN hhubh)}(hXThere are ``->gp_seq`` fields in the ``rcu_node`` and ``rcu_data`` structures as well. The fields in the ``rcu_state`` structure represent the most current value, and those of the other structures are compared in order to detect the beginnings and ends of grace periods in a distributed fashion. The values flow from ``rcu_state`` to ``rcu_node`` (down the tree from the root to the leaves) to ``rcu_data``.h](h There are }(hj hhhNhNubjL)}(h ``->gp_seq``h]h->gp_seq}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh fields in the }(hj hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh and }(hj hhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh' structures as well. The fields in the }(hj hhhNhNubjL)}(h ``rcu_state``h]h rcu_state}(hj! hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh structure represent the most current value, and those of the other structures are compared in order to detect the beginnings and ends of grace periods in a distributed fashion. The values flow from }(hj hhhNhNubjL)}(h ``rcu_state``h]h rcu_state}(hj3 hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh to }(hj hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjE hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh0 (down the tree from the root to the leaves) to }(hj hhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hjW hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjN hhubeh}(h]grace-period-trackingah ]h"]h$]grace-period trackingah&]uh1hhj!hhhhhM  referencedKubh)}(hhh](h)}(h Miscellaneoush]h Miscellaneous}(hj{ hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjx hhhhhM"ubh)}(hCThis portion of the ``rcu_state`` structure is declared as follows:h](hThis portion of the }(hj hhhNhNubjL)}(h ``rcu_state``h]h rcu_state}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh" structure is declared as follows:}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM$hjx hhubj)}(h81 unsigned long gp_max; 2 char abbr; 3 char *name;h]h81 unsigned long gp_max; 2 char abbr; 3 char *name;}hj sbah}(h]h ]h"]h$]h&]jjuh1jhhhM(hjx hhubh)}(hThe ``->gp_max`` field tracks the duration of the longest grace period in jiffies. It is protected by the root ``rcu_node``'s ``->lock``.h](hThe }(hj hhhNhNubjL)}(h ``->gp_max``h]h->gp_max}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh_ field tracks the duration of the longest grace period in jiffies. It is protected by the root }(hj hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh’s }(hj hhhNhNubjL)}(h ``->lock``h]h->lock}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM,hjx hhubh)}(hThe ``->name`` and ``->abbr`` fields distinguish between preemptible RCU (“rcu_preempt” and “p”) and non-preemptible RCU (“rcu_sched” and “s”). These fields are used for diagnostic and tracing purposes.h](hThe }(hj hhhNhNubjL)}(h ``->name``h]h->name}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh and }(hj hhhNhNubjL)}(h ``->abbr``h]h->abbr}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh fields distinguish between preemptible RCU (“rcu_preempt” and “p”) and non-preemptible RCU (“rcu_sched” and “s”). These fields are used for diagnostic and tracing purposes.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM/hjx hhubeh}(h] miscellaneousah ]h"] miscellaneousah$]h&]uh1hhj!hhhhhM"ubeh}(h]the-rcu-state-structureah ]h"]the rcu_state structureah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hThe ``rcu_node`` Structureh](hThe }(hj@ hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjH hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj@ ubh Structure}(hj@ hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhj= hhhhhM4ubh)}(hXAThe ``rcu_node`` structures form the combining tree that propagates quiescent-state information from the leaves to the root and also that propagates grace-period information from the root down to the leaves. They provides local copies of the grace-period state in order to allow this information to be accessed in a synchronized manner without suffering the scalability limitations that would otherwise be imposed by global locking. In ``CONFIG_PREEMPT_RCU`` kernels, they manage the lists of tasks that have blocked while in their current RCU read-side critical section. In ``CONFIG_PREEMPT_RCU`` with ``CONFIG_RCU_BOOST``, they manage the per-\ ``rcu_node`` priority-boosting kernel threads (kthreads) and state. Finally, they record CPU-hotplug state in order to determine which CPUs should be ignored during a given grace period.h](hThe }(hj` hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjh hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj` ubhX structures form the combining tree that propagates quiescent-state information from the leaves to the root and also that propagates grace-period information from the root down to the leaves. They provides local copies of the grace-period state in order to allow this information to be accessed in a synchronized manner without suffering the scalability limitations that would otherwise be imposed by global locking. In }(hj` hhhNhNubjL)}(h``CONFIG_PREEMPT_RCU``h]hCONFIG_PREEMPT_RCU}(hjz hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj` ubhu kernels, they manage the lists of tasks that have blocked while in their current RCU read-side critical section. In }(hj` hhhNhNubjL)}(h``CONFIG_PREEMPT_RCU``h]hCONFIG_PREEMPT_RCU}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj` ubh with }(hj` hhhNhNubjL)}(h``CONFIG_RCU_BOOST``h]hCONFIG_RCU_BOOST}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj` ubh, they manage the per- }(hj` hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj` ubh priority-boosting kernel threads (kthreads) and state. Finally, they record CPU-hotplug state in order to determine which CPUs should be ignored during a given grace period.}(hj` hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM6hj= hhubh)}(hcThe ``rcu_node`` structure's fields are discussed, singly and in groups, in the following sections.h](hThe }(hj hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubhU structure’s fields are discussed, singly and in groups, in the following sections.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMChj= hhubh)}(hhh](h)}(hConnection to Combining Treeh]hConnection to Combining Tree}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhMGubh)}(hBThis portion of the ``rcu_node`` structure is declared as follows:h](hThis portion of the }(hj hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh" structure is declared as follows:}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMIhj hhubj)}(hr1 struct rcu_node *parent; 2 u8 level; 3 u8 grpnum; 4 unsigned long grpmask; 5 int grplo; 6 int grphi;h]hr1 struct rcu_node *parent; 2 u8 level; 3 u8 grpnum; 4 unsigned long grpmask; 5 int grplo; 6 int grphi;}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMMhj hhubh)}(hXThe ``->parent`` pointer references the ``rcu_node`` one level up in the tree, and is ``NULL`` for the root ``rcu_node``. The RCU implementation makes heavy use of this field to push quiescent states up the tree. The ``->level`` field gives the level in the tree, with the root being at level zero, its children at level one, and so on. The ``->grpnum`` field gives this node's position within the children of its parent, so this number can range between 0 and 31 on 32-bit systems and between 0 and 63 on 64-bit systems. The ``->level`` and ``->grpnum`` fields are used only during initialization and for tracing. The ``->grpmask`` field is the bitmask counterpart of ``->grpnum``, and therefore always has exactly one bit set. This mask is used to clear the bit corresponding to this ``rcu_node`` structure in its parent's bitmasks, which are described later. Finally, the ``->grplo`` and ``->grphi`` fields contain the lowest and highest numbered CPU served by this ``rcu_node`` structure, respectively.h](hThe }(hj'hhhNhNubjL)}(h ``->parent``h]h->parent}(hj/hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj'ubh pointer references the }(hj'hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjAhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj'ubh" one level up in the tree, and is }(hj'hhhNhNubjL)}(h``NULL``h]hNULL}(hjShhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj'ubh for the root }(hj'hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjehhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj'ubha. The RCU implementation makes heavy use of this field to push quiescent states up the tree. The }(hj'hhhNhNubjL)}(h ``->level``h]h->level}(hjwhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj'ubhq field gives the level in the tree, with the root being at level zero, its children at level one, and so on. The }(hj'hhhNhNubjL)}(h ``->grpnum``h]h->grpnum}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj'ubh field gives this node’s position within the children of its parent, so this number can range between 0 and 31 on 32-bit systems and between 0 and 63 on 64-bit systems. The }(hj'hhhNhNubjL)}(h ``->level``h]h->level}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj'ubh and }(hj'hhhNhNubjL)}(h ``->grpnum``h]h->grpnum}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj'ubhA fields are used only during initialization and for tracing. The }(hj'hhhNhNubjL)}(h ``->grpmask``h]h ->grpmask}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj'ubh% field is the bitmask counterpart of }(hj'hhhNhNubjL)}(h ``->grpnum``h]h->grpnum}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj'ubhi, and therefore always has exactly one bit set. This mask is used to clear the bit corresponding to this }(hj'hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj'ubhO structure in its parent’s bitmasks, which are described later. Finally, the }(hj'hhhNhNubjL)}(h ``->grplo``h]h->grplo}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj'ubh and }hj'sbjL)}(h ``->grphi``h]h->grphi}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj'ubhC fields contain the lowest and highest numbered CPU served by this }(hj'hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj'ubh structure, respectively.}(hj'hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMThj hhubh)}(hNAll of these fields are constant, and thus do not require any synchronization.h]hNAll of these fields are constant, and thus do not require any synchronization.}(hj1hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMdhj hhubeh}(h]connection-to-combining-treeah ]h"]connection to combining treeah$]h&]uh1hhj= hhhhhMGubh)}(hhh](h)}(hSynchronizationh]hSynchronization}(hjJhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjGhhhhhMhubh)}(h@This field of the ``rcu_node`` structure is declared as follows:h](hThis field of the }(hjXhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj`hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjXubh" structure is declared as follows:}(hjXhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMjhjGhhubj)}(h1 raw_spinlock_t lock;h]h1 raw_spinlock_t lock;}hjxsbah}(h]h ]h"]h$]h&]jjuh1jhhhMnhjGhhubh)}(hX9This field is used to protect the remaining fields in this structure, unless otherwise stated. That said, all of the fields in this structure can be accessed without locking for tracing purposes. Yes, this can result in confusing traces, but better some tracing confusion than to be heisenbugged out of existence.h]hX9This field is used to protect the remaining fields in this structure, unless otherwise stated. That said, all of the fields in this structure can be accessed without locking for tracing purposes. Yes, this can result in confusing traces, but better some tracing confusion than to be heisenbugged out of existence.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMphjGhhubhtarget)}(h.. _grace-period-tracking-1:h]h}(h]h ]h"]h$]h&]refidgrace-period-tracking-1uh1jhMvhjGhhhhubeh}(h]synchronizationah ]h"]synchronizationah$]h&]uh1hhj= hhhhhMhubh)}(hhh](h)}(hGrace-Period Trackingh]hGrace-Period Tracking}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMyubh)}(hBThis portion of the ``rcu_node`` structure is declared as follows:h](hThis portion of the }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh" structure is declared as follows:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM{hjhhubj)}(h:1 unsigned long gp_seq; 2 unsigned long gp_seq_needed;h]h:1 unsigned long gp_seq; 2 unsigned long gp_seq_needed;}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(hX_The ``rcu_node`` structures' ``->gp_seq`` fields are the counterparts of the field of the same name in the ``rcu_state`` structure. They each may lag up to one step behind their ``rcu_state`` counterpart. If the bottom two bits of a given ``rcu_node`` structure's ``->gp_seq`` field is zero, then this ``rcu_node`` structure believes that RCU is idle.h](hThe }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh structures’ }(hjhhhNhNubjL)}(h ``->gp_seq``h]h->gp_seq}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhB fields are the counterparts of the field of the same name in the }(hjhhhNhNubjL)}(h ``rcu_state``h]h rcu_state}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh: structure. They each may lag up to one step behind their }(hjhhhNhNubjL)}(h ``rcu_state``h]h rcu_state}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh0 counterpart. If the bottom two bits of a given }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj9hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh structure’s }(hjhhhNhNubjL)}(h ``->gp_seq``h]h->gp_seq}(hjKhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh field is zero, then this }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj]hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh% structure believes that RCU is idle.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hrThe ``>gp_seq`` field of each ``rcu_node`` structure is updated at the beginning and the end of each grace period.h](hThe }(hjuhhhNhNubjL)}(h ``>gp_seq``h]h>gp_seq}(hj}hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjuubh field of each }(hjuhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjuubhH structure is updated at the beginning and the end of each grace period.}(hjuhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hX The ``->gp_seq_needed`` fields record the furthest-in-the-future grace period request seen by the corresponding ``rcu_node`` structure. The request is considered fulfilled when the value of the ``->gp_seq`` field equals or exceeds that of the ``->gp_seq_needed`` field.h](hThe }(hjhhhNhNubjL)}(h``->gp_seq_needed``h]h->gp_seq_needed}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhY fields record the furthest-in-the-future grace period request seen by the corresponding }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhF structure. The request is considered fulfilled when the value of the }(hjhhhNhNubjL)}(h ``->gp_seq``h]h->gp_seq}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh% field equals or exceeds that of the }(hjhhhNhNubjL)}(h``->gp_seq_needed``h]h->gp_seq_needed}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh field.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj~)}(hhh]j)}(hhh](j)}(hhh]h}(h]h ]h"]h$]h&]colwidthKGuh1jhjubj)}(hhh](j)}(hhh]j)}(hhh]h)}(h**Quick Quiz**:h](j)}(h**Quick Quiz**h]h Quick Quiz}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhj ubj)}(hhh]j)}(hhh]h)}(hSuppose that this ``rcu_node`` structure doesn't see a request for a very long time. Won't wrapping of the ``->gp_seq`` field cause problems?h](hSuppose that this }(hjDhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjDubhQ structure doesn’t see a request for a very long time. Won’t wrapping of the }(hjDhhhNhNubjL)}(h ``->gp_seq``h]h->gp_seq}(hj^hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjDubh field cause problems?}(hjDhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjAubah}(h]h ]h"]h$]h&]uh1jhj>ubah}(h]h ]h"]h$]h&]uh1jhj ubj)}(hhh]j)}(hhh]h)}(h **Answer**:h](j)}(h **Answer**h]hAnswer}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhj ubj)}(hhh]j)}(hhh]h)}(hNo, because if the ``->gp_seq_needed`` field lags behind the ``->gp_seq`` field, the ``->gp_seq_needed`` field will be updated at the end of the grace period. Modulo-arithmetic comparisons therefore will always get the correct answer, even with wrapping.h](hNo, because if the }(hjhhhNhNubjL)}(h``->gp_seq_needed``h]h->gp_seq_needed}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh field lags behind the }(hjhhhNhNubjL)}(h ``->gp_seq``h]h->gp_seq}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh field, the }(hjhhhNhNubjL)}(h``->gp_seq_needed``h]h->gp_seq_needed}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh field will be updated at the end of the grace period. Modulo-arithmetic comparisons therefore will always get the correct answer, even with wrapping.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhj ubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]colsKuh1jhjubah}(h]h ]h"]h$]h&]uh1j}hjhhhhhNubeh}(h](jid1eh ]h"]grace-period-tracking-1ah$]ju ah&]uh1hhj= hhhhhMyjw Kexpect_referenced_by_name}jjsexpect_referenced_by_id}jjsubh)}(hhh](h)}(hQuiescent-State Trackingh]hQuiescent-State Tracking}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj%hhhhhMubh)}(hNThese fields manage the propagation of quiescent states up the combining tree.h]hNThese fields manage the propagation of quiescent states up the combining tree.}(hj6hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj%hhubh)}(hAThis portion of the ``rcu_node`` structure has fields as follows:h](hThis portion of the }(hjDhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjDubh! structure has fields as follows:}(hjDhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj%hhubj)}(hq1 unsigned long qsmask; 2 unsigned long expmask; 3 unsigned long qsmaskinit; 4 unsigned long expmaskinit;h]hq1 unsigned long qsmask; 2 unsigned long expmask; 3 unsigned long qsmaskinit; 4 unsigned long expmaskinit;}hjdsbah}(h]h ]h"]h$]h&]jjuh1jhhhMhj%hhubh)}(hXmThe ``->qsmask`` field tracks which of this ``rcu_node`` structure's children still need to report quiescent states for the current normal grace period. Such children will have a value of 1 in their corresponding bit. Note that the leaf ``rcu_node`` structures should be thought of as having ``rcu_data`` structures as their children. Similarly, the ``->expmask`` field tracks which of this ``rcu_node`` structure's children still need to report quiescent states for the current expedited grace period. An expedited grace period has the same conceptual properties as a normal grace period, but the expedited implementation accepts extreme CPU overhead to obtain much lower grace-period latency, for example, consuming a few tens of microseconds worth of CPU time to reduce grace-period duration from milliseconds to tens of microseconds. The ``->qsmaskinit`` field tracks which of this ``rcu_node`` structure's children cover for at least one online CPU. This mask is used to initialize ``->qsmask``, and ``->expmaskinit`` is used to initialize ``->expmask`` and the beginning of the normal and expedited grace periods, respectively.h](hThe }(hjrhhhNhNubjL)}(h ``->qsmask``h]h->qsmask}(hjzhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjrubh field tracks which of this }(hjrhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjrubh structure’s children still need to report quiescent states for the current normal grace period. Such children will have a value of 1 in their corresponding bit. Note that the leaf }(hjrhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjrubh+ structures should be thought of as having }(hjrhhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjrubh. structures as their children. Similarly, the }(hjrhhhNhNubjL)}(h ``->expmask``h]h ->expmask}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjrubh field tracks which of this }hjrsbjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjrubhX structure’s children still need to report quiescent states for the current expedited grace period. An expedited grace period has the same conceptual properties as a normal grace period, but the expedited implementation accepts extreme CPU overhead to obtain much lower grace-period latency, for example, consuming a few tens of microseconds worth of CPU time to reduce grace-period duration from milliseconds to tens of microseconds. The }(hjrhhhNhNubjL)}(h``->qsmaskinit``h]h ->qsmaskinit}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjrubh field tracks which of this }(hjrhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjrubh[ structure’s children cover for at least one online CPU. This mask is used to initialize }(hjrhhhNhNubjL)}(h ``->qsmask``h]h->qsmask}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjrubh, and }(hjrhhhNhNubjL)}(h``->expmaskinit``h]h ->expmaskinit}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjrubh is used to initialize }(hjrhhhNhNubjL)}(h ``->expmask``h]h ->expmask}(hj.hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjrubhK and the beginning of the normal and expedited grace periods, respectively.}(hjrhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj%hhubj~)}(hhh]j)}(hhh](j)}(hhh]h}(h]h ]h"]h$]h&]colwidthKGuh1jhjIubj)}(hhh](j)}(hhh]j)}(hhh]h)}(h**Quick Quiz**:h](j)}(h**Quick Quiz**h]h Quick Quiz}(hjchhhNhNubah}(h]h ]h"]h$]h&]uh1jhj_ubh:}(hj_hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj\ubah}(h]h ]h"]h$]h&]uh1jhjYubah}(h]h ]h"]h$]h&]uh1jhjVubj)}(hhh]j)}(hhh]h)}(haWhy are these bitmasks protected by locking? Come on, haven't you heard of atomic instructions???h]hcWhy are these bitmasks protected by locking? Come on, haven’t you heard of atomic instructions???}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhjVubj)}(hhh]j)}(hhh]h)}(h **Answer**:h](j)}(h **Answer**h]hAnswer}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhjVubj)}(hhh]j)}(hhh](h)}(hqLockless grace-period computation! Such a tantalizing possibility! But consider the following sequence of events:h]hqLockless grace-period computation! Such a tantalizing possibility! But consider the following sequence of events:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubj)}(hhh](j)}(hCPU 0 has been in dyntick-idle mode for quite some time. When it wakes up, it notices that the current RCU grace period needs it to report in, so it sets a flag where the scheduling clock interrupt will find it.h]h)}(hCPU 0 has been in dyntick-idle mode for quite some time. When it wakes up, it notices that the current RCU grace period needs it to report in, so it sets a flag where the scheduling clock interrupt will find it.h]hCPU 0 has been in dyntick-idle mode for quite some time. When it wakes up, it notices that the current RCU grace period needs it to report in, so it sets a flag where the scheduling clock interrupt will find it.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hMeanwhile, CPU 1 is running ``force_quiescent_state()``, and notices that CPU 0 has been in dyntick idle mode, which qualifies as an extended quiescent state.h]h)}(hMeanwhile, CPU 1 is running ``force_quiescent_state()``, and notices that CPU 0 has been in dyntick idle mode, which qualifies as an extended quiescent state.h](hMeanwhile, CPU 1 is running }(hjhhhNhNubjL)}(h``force_quiescent_state()``h]hforce_quiescent_state()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhh, and notices that CPU 0 has been in dyntick idle mode, which qualifies as an extended quiescent state.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hCPU 0's scheduling clock interrupt fires in the middle of an RCU read-side critical section, and notices that the RCU core needs something, so commences RCU softirq processing.h]h)}(hCPU 0's scheduling clock interrupt fires in the middle of an RCU read-side critical section, and notices that the RCU core needs something, so commences RCU softirq processing.h]hCPU 0’s scheduling clock interrupt fires in the middle of an RCU read-side critical section, and notices that the RCU core needs something, so commences RCU softirq processing.}(hj2hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj.ubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hqCPU 0's softirq handler executes and is just about ready to report its quiescent state up the ``rcu_node`` tree.h]h)}(hqCPU 0's softirq handler executes and is just about ready to report its quiescent state up the ``rcu_node`` tree.h](haCPU 0’s softirq handler executes and is just about ready to report its quiescent state up the }(hjJhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjJubh tree.}(hjJhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjFubah}(h]h ]h"]h$]h&]uh1jhjubj)}(h]But CPU 1 beats it to the punch, completing the current grace period and starting a new one.h]h)}(h]But CPU 1 beats it to the punch, completing the current grace period and starting a new one.h]h]But CPU 1 beats it to the punch, completing the current grace period and starting a new one.}(hjthhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjpubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hCPU 0 now reports its quiescent state for the wrong grace period. That grace period might now end before the RCU read-side critical section. If that happens, disaster will ensue. h]h)}(hCPU 0 now reports its quiescent state for the wrong grace period. That grace period might now end before the RCU read-side critical section. If that happens, disaster will ensue.h]hCPU 0 now reports its quiescent state for the wrong grace period. That grace period might now end before the RCU read-side critical section. If that happens, disaster will ensue.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]jUjVjWhjXjYuh1jhjubh)}(hSo the locking is absolutely required in order to coordinate clearing of the bits with updating of the grace-period sequence number in ``->gp_seq``.h](hSo the locking is absolutely required in order to coordinate clearing of the bits with updating of the grace-period sequence number in }(hjhhhNhNubjL)}(h ``->gp_seq``h]h->gp_seq}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubeh}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhjVubeh}(h]h ]h"]h$]h&]uh1jhjIubeh}(h]h ]h"]h$]h&]colsKuh1jhjFubah}(h]h ]h"]h$]h&]uh1j}hj%hhhhhNubeh}(h]quiescent-state-trackingah ]h"]quiescent-state trackingah$]h&]uh1hhj= hhhhhMubh)}(hhh](h)}(hBlocked-Task Managementh]hBlocked-Task Management}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hXQ``PREEMPT_RCU`` allows tasks to be preempted in the midst of their RCU read-side critical sections, and these tasks must be tracked explicitly. The details of exactly why and how they are tracked will be covered in a separate article on RCU read-side processing. For now, it is enough to know that the ``rcu_node`` structure tracks them.h](jL)}(h``PREEMPT_RCU``h]h PREEMPT_RCU}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhX allows tasks to be preempted in the midst of their RCU read-side critical sections, and these tasks must be tracked explicitly. The details of exactly why and how they are tracked will be covered in a separate article on RCU read-side processing. For now, it is enough to know that the }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh structure tracks them.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(h{1 struct list_head blkd_tasks; 2 struct list_head *gp_tasks; 3 struct list_head *exp_tasks; 4 bool wait_blkd_tasks;h]h{1 struct list_head blkd_tasks; 2 struct list_head *gp_tasks; 3 struct list_head *exp_tasks; 4 bool wait_blkd_tasks;}hj,sbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(hX0The ``->blkd_tasks`` field is a list header for the list of blocked and preempted tasks. As tasks undergo context switches within RCU read-side critical sections, their ``task_struct`` structures are enqueued (via the ``task_struct``'s ``->rcu_node_entry`` field) onto the head of the ``->blkd_tasks`` list for the leaf ``rcu_node`` structure corresponding to the CPU on which the outgoing context switch executed. As these tasks later exit their RCU read-side critical sections, they remove themselves from the list. This list is therefore in reverse time order, so that if one of the tasks is blocking the current grace period, all subsequent tasks must also be blocking that same grace period. Therefore, a single pointer into this list suffices to track all tasks blocking a given grace period. That pointer is stored in ``->gp_tasks`` for normal grace periods and in ``->exp_tasks`` for expedited grace periods. These last two fields are ``NULL`` if either there is no grace period in flight or if there are no blocked tasks preventing that grace period from completing. If either of these two pointers is referencing a task that removes itself from the ``->blkd_tasks`` list, then that task must advance the pointer to the next task on the list, or set the pointer to ``NULL`` if there are no subsequent tasks on the list.h](hThe }(hj:hhhNhNubjL)}(h``->blkd_tasks``h]h ->blkd_tasks}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj:ubh field is a list header for the list of blocked and preempted tasks. As tasks undergo context switches within RCU read-side critical sections, their }(hj:hhhNhNubjL)}(h``task_struct``h]h task_struct}(hjThhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj:ubh" structures are enqueued (via the }(hj:hhhNhNubjL)}(h``task_struct``h]h task_struct}(hjfhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj:ubh’s }(hj:hhhNhNubjL)}(h``->rcu_node_entry``h]h->rcu_node_entry}(hjxhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj:ubh field) onto the head of the }(hj:hhhNhNubjL)}(h``->blkd_tasks``h]h ->blkd_tasks}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj:ubh list for the leaf }(hj:hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj:ubhX structure corresponding to the CPU on which the outgoing context switch executed. As these tasks later exit their RCU read-side critical sections, they remove themselves from the list. This list is therefore in reverse time order, so that if one of the tasks is blocking the current grace period, all subsequent tasks must also be blocking that same grace period. Therefore, a single pointer into this list suffices to track all tasks blocking a given grace period. That pointer is stored in }(hj:hhhNhNubjL)}(h``->gp_tasks``h]h ->gp_tasks}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj:ubh! for normal grace periods and in }(hj:hhhNhNubjL)}(h``->exp_tasks``h]h ->exp_tasks}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj:ubh8 for expedited grace periods. These last two fields are }(hj:hhhNhNubjL)}(h``NULL``h]hNULL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj:ubh if either there is no grace period in flight or if there are no blocked tasks preventing that grace period from completing. If either of these two pointers is referencing a task that removes itself from the }(hj:hhhNhNubjL)}(h``->blkd_tasks``h]h ->blkd_tasks}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj:ubhc list, then that task must advance the pointer to the next task on the list, or set the pointer to }(hj:hhhNhNubjL)}(h``NULL``h]hNULL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj:ubh. if there are no subsequent tasks on the list.}(hj:hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hXFor example, suppose that tasks T1, T2, and T3 are all hard-affinitied to the largest-numbered CPU in the system. Then if task T1 blocked in an RCU read-side critical section, then an expedited grace period started, then task T2 blocked in an RCU read-side critical section, then a normal grace period started, and finally task 3 blocked in an RCU read-side critical section, then the state of the last leaf ``rcu_node`` structure's blocked-task list would be as shown below:h](hXFor example, suppose that tasks T1, T2, and T3 are all hard-affinitied to the largest-numbered CPU in the system. Then if task T1 blocked in an RCU read-side critical section, then an expedited grace period started, then task T2 blocked in an RCU read-side critical section, then a normal grace period started, and finally task 3 blocked in an RCU read-side critical section, then the state of the last leaf }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh9 structure’s blocked-task list would be as shown below:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hhh]j")}(hhh]j')}(h!.. kernel-figure:: blkd_task.svg h]h}(h]h ]h"]h$]h&]uri(RCU/Design/Data-Structures/blkd_task.svgj4}j6j?suh1j&hj1hhhKubah}(h]h ]h"]h$]h&]uh1j!hj.ubah}(h]h ]h"]h$]h&]uh1jhjhhhhhMubh)}(hX{Task T1 is blocking both grace periods, task T2 is blocking only the normal grace period, and task T3 is blocking neither grace period. Note that these tasks will not remove themselves from this list immediately upon resuming execution. They will instead remain on the list until they execute the outermost ``rcu_read_unlock()`` that ends their RCU read-side critical section.h](hX6Task T1 is blocking both grace periods, task T2 is blocking only the normal grace period, and task T3 is blocking neither grace period. Note that these tasks will not remove themselves from this list immediately upon resuming execution. They will instead remain on the list until they execute the outermost }(hjMhhhNhNubjL)}(h``rcu_read_unlock()``h]hrcu_read_unlock()}(hjUhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjMubh0 that ends their RCU read-side critical section.}(hjMhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hoThe ``->wait_blkd_tasks`` field indicates whether or not the current grace period is waiting on a blocked task.h](hThe }(hjmhhhNhNubjL)}(h``->wait_blkd_tasks``h]h->wait_blkd_tasks}(hjuhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjmubhV field indicates whether or not the current grace period is waiting on a blocked task.}(hjmhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubeh}(h]blocked-task-managementah ]h"]blocked-task managementah$]h&]uh1hhj= hhhhhMubh)}(hhh](h)}(hSizing the ``rcu_node`` Arrayh](h Sizing the }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh Array}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hVThe ``rcu_node`` array is sized via a series of C-preprocessor expressions as follows:h](hThe }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhF array is sized via a series of C-preprocessor expressions as follows:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hX 1 #ifdef CONFIG_RCU_FANOUT 2 #define RCU_FANOUT CONFIG_RCU_FANOUT 3 #else 4 # ifdef CONFIG_64BIT 5 # define RCU_FANOUT 64 6 # else 7 # define RCU_FANOUT 32 8 # endif 9 #endif 10 11 #ifdef CONFIG_RCU_FANOUT_LEAF 12 #define RCU_FANOUT_LEAF CONFIG_RCU_FANOUT_LEAF 13 #else 14 # ifdef CONFIG_64BIT 15 # define RCU_FANOUT_LEAF 64 16 # else 17 # define RCU_FANOUT_LEAF 32 18 # endif 19 #endif 20 21 #define RCU_FANOUT_1 (RCU_FANOUT_LEAF) 22 #define RCU_FANOUT_2 (RCU_FANOUT_1 * RCU_FANOUT) 23 #define RCU_FANOUT_3 (RCU_FANOUT_2 * RCU_FANOUT) 24 #define RCU_FANOUT_4 (RCU_FANOUT_3 * RCU_FANOUT) 25 26 #if NR_CPUS <= RCU_FANOUT_1 27 # define RCU_NUM_LVLS 1 28 # define NUM_RCU_LVL_0 1 29 # define NUM_RCU_NODES NUM_RCU_LVL_0 30 # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0 } 31 # define RCU_NODE_NAME_INIT { "rcu_node_0" } 32 # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0" } 33 # define RCU_EXP_NAME_INIT { "rcu_node_exp_0" } 34 #elif NR_CPUS <= RCU_FANOUT_2 35 # define RCU_NUM_LVLS 2 36 # define NUM_RCU_LVL_0 1 37 # define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1) 38 # define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1) 39 # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1 } 40 # define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1" } 41 # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1" } 42 # define RCU_EXP_NAME_INIT { "rcu_node_exp_0", "rcu_node_exp_1" } 43 #elif NR_CPUS <= RCU_FANOUT_3 44 # define RCU_NUM_LVLS 3 45 # define NUM_RCU_LVL_0 1 46 # define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_2) 47 # define NUM_RCU_LVL_2 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1) 48 # define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2) 49 # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1, NUM_RCU_LVL_2 } 50 # define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1", "rcu_node_2" } 51 # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1", "rcu_node_fqs_2" } 52 # define RCU_EXP_NAME_INIT { "rcu_node_exp_0", "rcu_node_exp_1", "rcu_node_exp_2" } 53 #elif NR_CPUS <= RCU_FANOUT_4 54 # define RCU_NUM_LVLS 4 55 # define NUM_RCU_LVL_0 1 56 # define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_3) 57 # define NUM_RCU_LVL_2 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_2) 58 # define NUM_RCU_LVL_3 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1) 59 # define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2 + NUM_RCU_LVL_3) 60 # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1, NUM_RCU_LVL_2, NUM_RCU_LVL_3 } 61 # define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1", "rcu_node_2", "rcu_node_3" } 62 # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1", "rcu_node_fqs_2", "rcu_node_fqs_3" } 63 # define RCU_EXP_NAME_INIT { "rcu_node_exp_0", "rcu_node_exp_1", "rcu_node_exp_2", "rcu_node_exp_3" } 64 #else 65 # error "CONFIG_RCU_FANOUT insufficient for NR_CPUS" 66 #endifh]hX 1 #ifdef CONFIG_RCU_FANOUT 2 #define RCU_FANOUT CONFIG_RCU_FANOUT 3 #else 4 # ifdef CONFIG_64BIT 5 # define RCU_FANOUT 64 6 # else 7 # define RCU_FANOUT 32 8 # endif 9 #endif 10 11 #ifdef CONFIG_RCU_FANOUT_LEAF 12 #define RCU_FANOUT_LEAF CONFIG_RCU_FANOUT_LEAF 13 #else 14 # ifdef CONFIG_64BIT 15 # define RCU_FANOUT_LEAF 64 16 # else 17 # define RCU_FANOUT_LEAF 32 18 # endif 19 #endif 20 21 #define RCU_FANOUT_1 (RCU_FANOUT_LEAF) 22 #define RCU_FANOUT_2 (RCU_FANOUT_1 * RCU_FANOUT) 23 #define RCU_FANOUT_3 (RCU_FANOUT_2 * RCU_FANOUT) 24 #define RCU_FANOUT_4 (RCU_FANOUT_3 * RCU_FANOUT) 25 26 #if NR_CPUS <= RCU_FANOUT_1 27 # define RCU_NUM_LVLS 1 28 # define NUM_RCU_LVL_0 1 29 # define NUM_RCU_NODES NUM_RCU_LVL_0 30 # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0 } 31 # define RCU_NODE_NAME_INIT { "rcu_node_0" } 32 # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0" } 33 # define RCU_EXP_NAME_INIT { "rcu_node_exp_0" } 34 #elif NR_CPUS <= RCU_FANOUT_2 35 # define RCU_NUM_LVLS 2 36 # define NUM_RCU_LVL_0 1 37 # define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1) 38 # define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1) 39 # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1 } 40 # define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1" } 41 # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1" } 42 # define RCU_EXP_NAME_INIT { "rcu_node_exp_0", "rcu_node_exp_1" } 43 #elif NR_CPUS <= RCU_FANOUT_3 44 # define RCU_NUM_LVLS 3 45 # define NUM_RCU_LVL_0 1 46 # define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_2) 47 # define NUM_RCU_LVL_2 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1) 48 # define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2) 49 # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1, NUM_RCU_LVL_2 } 50 # define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1", "rcu_node_2" } 51 # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1", "rcu_node_fqs_2" } 52 # define RCU_EXP_NAME_INIT { "rcu_node_exp_0", "rcu_node_exp_1", "rcu_node_exp_2" } 53 #elif NR_CPUS <= RCU_FANOUT_4 54 # define RCU_NUM_LVLS 4 55 # define NUM_RCU_LVL_0 1 56 # define NUM_RCU_LVL_1 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_3) 57 # define NUM_RCU_LVL_2 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_2) 58 # define NUM_RCU_LVL_3 DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1) 59 # define NUM_RCU_NODES (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2 + NUM_RCU_LVL_3) 60 # define NUM_RCU_LVL_INIT { NUM_RCU_LVL_0, NUM_RCU_LVL_1, NUM_RCU_LVL_2, NUM_RCU_LVL_3 } 61 # define RCU_NODE_NAME_INIT { "rcu_node_0", "rcu_node_1", "rcu_node_2", "rcu_node_3" } 62 # define RCU_FQS_NAME_INIT { "rcu_node_fqs_0", "rcu_node_fqs_1", "rcu_node_fqs_2", "rcu_node_fqs_3" } 63 # define RCU_EXP_NAME_INIT { "rcu_node_exp_0", "rcu_node_exp_1", "rcu_node_exp_2", "rcu_node_exp_3" } 64 #else 65 # error "CONFIG_RCU_FANOUT insufficient for NR_CPUS" 66 #endif}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhM"hjhhubh)}(hXKThe maximum number of levels in the ``rcu_node`` structure is currently limited to four, as specified by lines 21-24 and the structure of the subsequent “if” statement. For 32-bit systems, this allows 16*32*32*32=524,288 CPUs, which should be sufficient for the next few years at least. For 64-bit systems, 16*64*64*64=4,194,304 CPUs is allowed, which should see us through the next decade or so. This four-level tree also allows kernels built with ``CONFIG_RCU_FANOUT=8`` to support up to 4096 CPUs, which might be useful in very large systems having eight CPUs per socket (but please note that no one has yet shown any measurable performance degradation due to misaligned socket and ``rcu_node`` boundaries). In addition, building kernels with a full four levels of ``rcu_node`` tree permits better testing of RCU's combining-tree code.h](h$The maximum number of levels in the }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhX structure is currently limited to four, as specified by lines 21-24 and the structure of the subsequent “if” statement. For 32-bit systems, this allows 16*32*32*32=524,288 CPUs, which should be sufficient for the next few years at least. For 64-bit systems, 16*64*64*64=4,194,304 CPUs is allowed, which should see us through the next decade or so. This four-level tree also allows kernels built with }(hjhhhNhNubjL)}(h``CONFIG_RCU_FANOUT=8``h]hCONFIG_RCU_FANOUT=8}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh to support up to 4096 CPUs, which might be useful in very large systems having eight CPUs per socket (but please note that no one has yet shown any measurable performance degradation due to misaligned socket and }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhG boundaries). In addition, building kernels with a full four levels of }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh< tree permits better testing of RCU’s combining-tree code.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMehjhhubh)}(hXThe ``RCU_FANOUT`` symbol controls how many children are permitted at each non-leaf level of the ``rcu_node`` tree. If the ``CONFIG_RCU_FANOUT`` Kconfig option is not specified, it is set based on the word size of the system, which is also the Kconfig default.h](hThe }(hj<hhhNhNubjL)}(h``RCU_FANOUT``h]h RCU_FANOUT}(hjDhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj<ubhO symbol controls how many children are permitted at each non-leaf level of the }(hj<hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjVhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj<ubh tree. If the }(hj<hhhNhNubjL)}(h``CONFIG_RCU_FANOUT``h]hCONFIG_RCU_FANOUT}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj<ubht Kconfig option is not specified, it is set based on the word size of the system, which is also the Kconfig default.}(hj<hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMshjhhubh)}(hXThe ``RCU_FANOUT_LEAF`` symbol controls how many CPUs are handled by each leaf ``rcu_node`` structure. Experience has shown that allowing a given leaf ``rcu_node`` structure to handle 64 CPUs, as permitted by the number of bits in the ``->qsmask`` field on a 64-bit system, results in excessive contention for the leaf ``rcu_node`` structures' ``->lock`` fields. The number of CPUs per leaf ``rcu_node`` structure is therefore limited to 16 given the default value of ``CONFIG_RCU_FANOUT_LEAF``. If ``CONFIG_RCU_FANOUT_LEAF`` is unspecified, the value selected is based on the word size of the system, just as for ``CONFIG_RCU_FANOUT``. Lines 11-19 perform this computation.h](hThe }(hjhhhNhNubjL)}(h``RCU_FANOUT_LEAF``h]hRCU_FANOUT_LEAF}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh8 symbol controls how many CPUs are handled by each leaf }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh< structure. Experience has shown that allowing a given leaf }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhH structure to handle 64 CPUs, as permitted by the number of bits in the }(hjhhhNhNubjL)}(h ``->qsmask``h]h->qsmask}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhH field on a 64-bit system, results in excessive contention for the leaf }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh structures’ }(hjhhhNhNubjL)}(h ``->lock``h]h->lock}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh% fields. The number of CPUs per leaf }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhA structure is therefore limited to 16 given the default value of }(hjhhhNhNubjL)}(h``CONFIG_RCU_FANOUT_LEAF``h]hCONFIG_RCU_FANOUT_LEAF}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh. If }(hjhhhNhNubjL)}(h``CONFIG_RCU_FANOUT_LEAF``h]hCONFIG_RCU_FANOUT_LEAF}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhY is unspecified, the value selected is based on the word size of the system, just as for }(hjhhhNhNubjL)}(h``CONFIG_RCU_FANOUT``h]hCONFIG_RCU_FANOUT}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh(. Lines 11-19 perform this computation.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMxhjhhubh)}(hXLines 21-24 compute the maximum number of CPUs supported by a single-level (which contains a single ``rcu_node`` structure), two-level, three-level, and four-level ``rcu_node`` tree, respectively, given the fanout specified by ``RCU_FANOUT`` and ``RCU_FANOUT_LEAF``. These numbers of CPUs are retained in the ``RCU_FANOUT_1``, ``RCU_FANOUT_2``, ``RCU_FANOUT_3``, and ``RCU_FANOUT_4`` C-preprocessor variables, respectively.h](heLines 21-24 compute the maximum number of CPUs supported by a single-level (which contains a single }(hjBhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjJhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjBubh4 structure), two-level, three-level, and four-level }(hjBhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj\hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjBubh3 tree, respectively, given the fanout specified by }(hjBhhhNhNubjL)}(h``RCU_FANOUT``h]h RCU_FANOUT}(hjnhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjBubh and }(hjBhhhNhNubjL)}(h``RCU_FANOUT_LEAF``h]hRCU_FANOUT_LEAF}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjBubh,. These numbers of CPUs are retained in the }(hjBhhhNhNubjL)}(h``RCU_FANOUT_1``h]h RCU_FANOUT_1}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjBubh, }(hjBhhhNhNubjL)}(h``RCU_FANOUT_2``h]h RCU_FANOUT_2}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjBubh, }(hjBhhhNhNubjL)}(h``RCU_FANOUT_3``h]h RCU_FANOUT_3}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjBubh, and }(hjBhhhNhNubjL)}(h``RCU_FANOUT_4``h]h RCU_FANOUT_4}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjBubh( C-preprocessor variables, respectively.}(hjBhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hXThese variables are used to control the C-preprocessor ``#if`` statement spanning lines 26-66 that computes the number of ``rcu_node`` structures required for each level of the tree, as well as the number of levels required. The number of levels is placed in the ``NUM_RCU_LVLS`` C-preprocessor variable by lines 27, 35, 44, and 54. The number of ``rcu_node`` structures for the topmost level of the tree is always exactly one, and this value is unconditionally placed into ``NUM_RCU_LVL_0`` by lines 28, 36, 45, and 55. The rest of the levels (if any) of the ``rcu_node`` tree are computed by dividing the maximum number of CPUs by the fanout supported by the number of levels from the current level down, rounding up. This computation is performed by lines 37, 46-47, and 56-58. Lines 31-33, 40-42, 50-52, and 62-63 create initializers for lockdep lock-class names. Finally, lines 64-66 produce an error if the maximum number of CPUs is too large for the specified fanout.h](h7These variables are used to control the C-preprocessor }(hjhhhNhNubjL)}(h``#if``h]h#if}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh= statement spanning lines 26-66 that computes the number of }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh structures required for each level of the tree, as well as the number of levels required. The number of levels is placed in the }(hjhhhNhNubjL)}(h``NUM_RCU_LVLS``h]h NUM_RCU_LVLS}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhF C-preprocessor variable by lines 27, 35, 44, and 54. The number of }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhs structures for the topmost level of the tree is always exactly one, and this value is unconditionally placed into }(hjhhhNhNubjL)}(h``NUM_RCU_LVL_0``h]h NUM_RCU_LVL_0}(hj0hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhG by lines 28, 36, 45, and 55. The rest of the levels (if any) of the }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhX tree are computed by dividing the maximum number of CPUs by the fanout supported by the number of levels from the current level down, rounding up. This computation is performed by lines 37, 46-47, and 56-58. Lines 31-33, 40-42, 50-52, and 62-63 create initializers for lockdep lock-class names. Finally, lines 64-66 produce an error if the maximum number of CPUs is too large for the specified fanout.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubeh}(h]sizing-the-rcu-node-arrayah ]h"]sizing the rcu_node arrayah$]h&]uh1hhj= hhhhhMubeh}(h]the-rcu-node-structureah ]h"]the rcu_node structureah$]h&]uh1hhhhhhhhM4ubh)}(hhh](h)}(hThe ``rcu_segcblist`` Structureh](hThe }(hjmhhhNhNubjL)}(h``rcu_segcblist``h]h rcu_segcblist}(hjuhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjmubh Structure}(hjmhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhjjhhhhhMubh)}(hSThe ``rcu_segcblist`` structure maintains a segmented list of callbacks as follows:h](hThe }(hjhhhNhNubjL)}(h``rcu_segcblist``h]h rcu_segcblist}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh> structure maintains a segmented list of callbacks as follows:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjjhhubj)}(hXh 1 #define RCU_DONE_TAIL 0 2 #define RCU_WAIT_TAIL 1 3 #define RCU_NEXT_READY_TAIL 2 4 #define RCU_NEXT_TAIL 3 5 #define RCU_CBLIST_NSEGS 4 6 7 struct rcu_segcblist { 8 struct rcu_head *head; 9 struct rcu_head **tails[RCU_CBLIST_NSEGS]; 10 unsigned long gp_seq[RCU_CBLIST_NSEGS]; 11 long len; 12 long len_lazy; 13 };h]hXh 1 #define RCU_DONE_TAIL 0 2 #define RCU_WAIT_TAIL 1 3 #define RCU_NEXT_READY_TAIL 2 4 #define RCU_NEXT_TAIL 3 5 #define RCU_CBLIST_NSEGS 4 6 7 struct rcu_segcblist { 8 struct rcu_head *head; 9 struct rcu_head **tails[RCU_CBLIST_NSEGS]; 10 unsigned long gp_seq[RCU_CBLIST_NSEGS]; 11 long len; 12 long len_lazy; 13 };}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjjhhubh)}(hThe segments are as follows:h]hThe segments are as follows:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjjhhubj)}(hhh](j)}(hg``RCU_DONE_TAIL``: Callbacks whose grace periods have elapsed. These callbacks are ready to be invoked.h]h)}(hg``RCU_DONE_TAIL``: Callbacks whose grace periods have elapsed. These callbacks are ready to be invoked.h](jL)}(h``RCU_DONE_TAIL``h]h RCU_DONE_TAIL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhV: Callbacks whose grace periods have elapsed. These callbacks are ready to be invoked.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(h``RCU_WAIT_TAIL``: Callbacks that are waiting for the current grace period. Note that different CPUs can have different ideas about which grace period is current, hence the ``->gp_seq`` field.h]h)}(h``RCU_WAIT_TAIL``: Callbacks that are waiting for the current grace period. Note that different CPUs can have different ideas about which grace period is current, hence the ``->gp_seq`` field.h](jL)}(h``RCU_WAIT_TAIL``h]h RCU_WAIT_TAIL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh: Callbacks that are waiting for the current grace period. Note that different CPUs can have different ideas about which grace period is current, hence the }(hjhhhNhNubjL)}(h ``->gp_seq``h]h->gp_seq}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh field.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(hN``RCU_NEXT_READY_TAIL``: Callbacks waiting for the next grace period to start.h]h)}(hN``RCU_NEXT_READY_TAIL``: Callbacks waiting for the next grace period to start.h](jL)}(h``RCU_NEXT_READY_TAIL``h]hRCU_NEXT_READY_TAIL}(hj2hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj.ubh7: Callbacks waiting for the next grace period to start.}(hj.hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj*ubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(hT``RCU_NEXT_TAIL``: Callbacks that have not yet been associated with a grace period. h]h)}(hS``RCU_NEXT_TAIL``: Callbacks that have not yet been associated with a grace period.h](jL)}(h``RCU_NEXT_TAIL``h]h RCU_NEXT_TAIL}(hjXhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjTubhB: Callbacks that have not yet been associated with a grace period.}(hjThhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjPubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubeh}(h]h ]h"]h$]h&]jUjVjWhjXjYuh1jhjjhhhhhMubh)}(hXThe ``->head`` pointer references the first callback or is ``NULL`` if the list contains no callbacks (which is *not* the same as being empty). Each element of the ``->tails[]`` array references the ``->next`` pointer of the last callback in the corresponding segment of the list, or the list's ``->head`` pointer if that segment and all previous segments are empty. If the corresponding segment is empty but some previous segment is not empty, then the array element is identical to its predecessor. Older callbacks are closer to the head of the list, and new callbacks are added at the tail. This relationship between the ``->head`` pointer, the ``->tails[]`` array, and the callbacks is shown in this diagram:h](hThe }(hj|hhhNhNubjL)}(h ``->head``h]h->head}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj|ubh- pointer references the first callback or is }(hj|hhhNhNubjL)}(h``NULL``h]hNULL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj|ubh- if the list contains no callbacks (which is }(hj|hhhNhNubhemphasis)}(h*not*h]hnot}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj|ubh/ the same as being empty). Each element of the }(hj|hhhNhNubjL)}(h ``->tails[]``h]h ->tails[]}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj|ubh array references the }(hj|hhhNhNubjL)}(h ``->next``h]h->next}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj|ubhX pointer of the last callback in the corresponding segment of the list, or the list’s }(hj|hhhNhNubjL)}(h ``->head``h]h->head}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj|ubhX? pointer if that segment and all previous segments are empty. If the corresponding segment is empty but some previous segment is not empty, then the array element is identical to its predecessor. Older callbacks are closer to the head of the list, and new callbacks are added at the tail. This relationship between the }(hj|hhhNhNubjL)}(h ``->head``h]h->head}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj|ubh pointer, the }(hj|hhhNhNubjL)}(h ``->tails[]``h]h ->tails[]}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj|ubh3 array, and the callbacks is shown in this diagram:}(hj|hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjjhhubj)}(hhh]j")}(hhh]j')}(h.. kernel-figure:: nxtlist.svg h]h}(h]h ]h"]h$]h&]uri&RCU/Design/Data-Structures/nxtlist.svgj4}j6j-suh1j&hjhhhKubah}(h]h ]h"]h$]h&]uh1j!hjubah}(h]h ]h"]h$]h&]uh1jhjjhhhhhMubh)}(hX=In this figure, the ``->head`` pointer references the first RCU callback in the list. The ``->tails[RCU_DONE_TAIL]`` array element references the ``->head`` pointer itself, indicating that none of the callbacks is ready to invoke. The ``->tails[RCU_WAIT_TAIL]`` array element references callback CB 2's ``->next`` pointer, which indicates that CB 1 and CB 2 are both waiting on the current grace period, give or take possible disagreements about exactly which grace period is the current one. The ``->tails[RCU_NEXT_READY_TAIL]`` array element references the same RCU callback that ``->tails[RCU_WAIT_TAIL]`` does, which indicates that there are no callbacks waiting on the next RCU grace period. The ``->tails[RCU_NEXT_TAIL]`` array element references CB 4's ``->next`` pointer, indicating that all the remaining RCU callbacks have not yet been assigned to an RCU grace period. Note that the ``->tails[RCU_NEXT_TAIL]`` array element always references the last RCU callback's ``->next`` pointer unless the callback list is empty, in which case it references the ``->head`` pointer.h](hIn this figure, the }(hj;hhhNhNubjL)}(h ``->head``h]h->head}(hjChhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj;ubh< pointer references the first RCU callback in the list. The }(hj;hhhNhNubjL)}(h``->tails[RCU_DONE_TAIL]``h]h->tails[RCU_DONE_TAIL]}(hjUhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj;ubh array element references the }(hj;hhhNhNubjL)}(h ``->head``h]h->head}(hjghhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj;ubhO pointer itself, indicating that none of the callbacks is ready to invoke. The }(hj;hhhNhNubjL)}(h``->tails[RCU_WAIT_TAIL]``h]h->tails[RCU_WAIT_TAIL]}(hjyhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj;ubh- array element references callback CB 2’s }(hj;hhhNhNubjL)}(h ``->next``h]h->next}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj;ubh pointer, which indicates that CB 1 and CB 2 are both waiting on the current grace period, give or take possible disagreements about exactly which grace period is the current one. The }(hj;hhhNhNubjL)}(h ``->tails[RCU_NEXT_READY_TAIL]``h]h->tails[RCU_NEXT_READY_TAIL]}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj;ubh5 array element references the same RCU callback that }(hj;hhhNhNubjL)}(h``->tails[RCU_WAIT_TAIL]``h]h->tails[RCU_WAIT_TAIL]}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj;ubh] does, which indicates that there are no callbacks waiting on the next RCU grace period. The }(hj;hhhNhNubjL)}(h``->tails[RCU_NEXT_TAIL]``h]h->tails[RCU_NEXT_TAIL]}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj;ubh$ array element references CB 4’s }(hj;hhhNhNubjL)}(h ``->next``h]h->next}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj;ubh{ pointer, indicating that all the remaining RCU callbacks have not yet been assigned to an RCU grace period. Note that the }(hj;hhhNhNubjL)}(h``->tails[RCU_NEXT_TAIL]``h]h->tails[RCU_NEXT_TAIL]}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj;ubh; array element always references the last RCU callback’s }(hj;hhhNhNubjL)}(h ``->next``h]h->next}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj;ubhL pointer unless the callback list is empty, in which case it references the }(hj;hhhNhNubjL)}(h ``->head``h]h->head}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj;ubh pointer.}(hj;hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjjhhubh)}(hX7There is one additional important special case for the ``->tails[RCU_NEXT_TAIL]`` array element: It can be ``NULL`` when this list is *disabled*. Lists are disabled when the corresponding CPU is offline or when the corresponding CPU's callbacks are offloaded to a kthread, both of which are described elsewhere.h](h7There is one additional important special case for the }(hj!hhhNhNubjL)}(h``->tails[RCU_NEXT_TAIL]``h]h->tails[RCU_NEXT_TAIL]}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj!ubh array element: It can be }(hj!hhhNhNubjL)}(h``NULL``h]hNULL}(hj;hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj!ubh when this list is }(hj!hhhNhNubj)}(h *disabled*h]hdisabled}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj!ubh. Lists are disabled when the corresponding CPU is offline or when the corresponding CPU’s callbacks are offloaded to a kthread, both of which are described elsewhere.}(hj!hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjjhhubh)}(hCPUs advance their callbacks from the ``RCU_NEXT_TAIL`` to the ``RCU_NEXT_READY_TAIL`` to the ``RCU_WAIT_TAIL`` to the ``RCU_DONE_TAIL`` list segments as grace periods advance.h](h&CPUs advance their callbacks from the }(hjehhhNhNubjL)}(h``RCU_NEXT_TAIL``h]h RCU_NEXT_TAIL}(hjmhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjeubh to the }(hjehhhNhNubjL)}(h``RCU_NEXT_READY_TAIL``h]hRCU_NEXT_READY_TAIL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjeubh to the }(hjehhhNhNubjL)}(h``RCU_WAIT_TAIL``h]h RCU_WAIT_TAIL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjeubh to the }hjesbjL)}(h``RCU_DONE_TAIL``h]h RCU_DONE_TAIL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjeubh( list segments as grace periods advance.}(hjehhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjjhhubh)}(hXThe ``->gp_seq[]`` array records grace-period numbers corresponding to the list segments. This is what allows different CPUs to have different ideas as to which is the current grace period while still avoiding premature invocation of their callbacks. In particular, this allows CPUs that go idle for extended periods to determine which of their callbacks are ready to be invoked after reawakening.h](hThe }(hjhhhNhNubjL)}(h``->gp_seq[]``h]h ->gp_seq[]}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhX{ array records grace-period numbers corresponding to the list segments. This is what allows different CPUs to have different ideas as to which is the current grace period while still avoiding premature invocation of their callbacks. In particular, this allows CPUs that go idle for extended periods to determine which of their callbacks are ready to be invoked after reawakening.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjjhhubh)}(hThe ``->len`` counter contains the number of callbacks in ``->head``, and the ``->len_lazy`` contains the number of those callbacks that are known to only free memory, and whose invocation can therefore be safely deferred.h](hThe }(hjhhhNhNubjL)}(h ``->len``h]h->len}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh- counter contains the number of callbacks in }(hjhhhNhNubjL)}(h ``->head``h]h->head}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh , and the }(hjhhhNhNubjL)}(h``->len_lazy``h]h ->len_lazy}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh contains the number of those callbacks that are known to only free memory, and whose invocation can therefore be safely deferred.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjjhhubh important)}(hXIt is the ``->len`` field that determines whether or not there are callbacks associated with this ``rcu_segcblist`` structure, *not* the ``->head`` pointer. The reason for this is that all the ready-to-invoke callbacks (that is, those in the ``RCU_DONE_TAIL`` segment) are extracted all at once at callback-invocation time (``rcu_do_batch``), due to which ``->head`` may be set to NULL if there are no not-done callbacks remaining in the ``rcu_segcblist``. If callback invocation must be postponed, for example, because a high-priority process just woke up on this CPU, then the remaining callbacks are placed back on the ``RCU_DONE_TAIL`` segment and ``->head`` once again points to the start of the segment. In short, the head field can briefly be ``NULL`` even though the CPU has callbacks present the entire time. Therefore, it is not appropriate to test the ``->head`` pointer for ``NULL``.h]h)}(hXIt is the ``->len`` field that determines whether or not there are callbacks associated with this ``rcu_segcblist`` structure, *not* the ``->head`` pointer. The reason for this is that all the ready-to-invoke callbacks (that is, those in the ``RCU_DONE_TAIL`` segment) are extracted all at once at callback-invocation time (``rcu_do_batch``), due to which ``->head`` may be set to NULL if there are no not-done callbacks remaining in the ``rcu_segcblist``. If callback invocation must be postponed, for example, because a high-priority process just woke up on this CPU, then the remaining callbacks are placed back on the ``RCU_DONE_TAIL`` segment and ``->head`` once again points to the start of the segment. In short, the head field can briefly be ``NULL`` even though the CPU has callbacks present the entire time. Therefore, it is not appropriate to test the ``->head`` pointer for ``NULL``.h](h It is the }(hj%hhhNhNubjL)}(h ``->len``h]h->len}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj%ubhO field that determines whether or not there are callbacks associated with this }(hj%hhhNhNubjL)}(h``rcu_segcblist``h]h rcu_segcblist}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj%ubh structure, }(hj%hhhNhNubj)}(h*not*h]hnot}(hjQhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj%ubh the }(hj%hhhNhNubjL)}(h ``->head``h]h->head}(hjchhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj%ubh_ pointer. The reason for this is that all the ready-to-invoke callbacks (that is, those in the }(hj%hhhNhNubjL)}(h``RCU_DONE_TAIL``h]h RCU_DONE_TAIL}(hjuhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj%ubhA segment) are extracted all at once at callback-invocation time (}(hj%hhhNhNubjL)}(h``rcu_do_batch``h]h rcu_do_batch}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj%ubh), due to which }(hj%hhhNhNubjL)}(h ``->head``h]h->head}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj%ubhH may be set to NULL if there are no not-done callbacks remaining in the }(hj%hhhNhNubjL)}(h``rcu_segcblist``h]h rcu_segcblist}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj%ubh. If callback invocation must be postponed, for example, because a high-priority process just woke up on this CPU, then the remaining callbacks are placed back on the }(hj%hhhNhNubjL)}(h``RCU_DONE_TAIL``h]h RCU_DONE_TAIL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj%ubh segment and }(hj%hhhNhNubjL)}(h ``->head``h]h->head}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj%ubhX once again points to the start of the segment. In short, the head field can briefly be }(hj%hhhNhNubjL)}(h``NULL``h]hNULL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj%ubhi even though the CPU has callbacks present the entire time. Therefore, it is not appropriate to test the }(hj%hhhNhNubjL)}(h ``->head``h]h->head}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj%ubh pointer for }(hj%hhhNhNubjL)}(h``NULL``h]hNULL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj%ubh.}(hj%hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj!ubah}(h]h ]h"]h$]h&]uh1jhjjhhhhhNubh)}(hXIn contrast, the ``->len`` and ``->len_lazy`` counts are adjusted only after the corresponding callbacks have been invoked. This means that the ``->len`` count is zero only if the ``rcu_segcblist`` structure really is devoid of callbacks. Of course, off-CPU sampling of the ``->len`` count requires careful use of appropriate synchronization, for example, memory barriers. This synchronization can be a bit subtle, particularly in the case of ``rcu_barrier()``.h](hIn contrast, the }(hj#hhhNhNubjL)}(h ``->len``h]h->len}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj#ubh and }(hj#hhhNhNubjL)}(h``->len_lazy``h]h ->len_lazy}(hj=hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj#ubhc counts are adjusted only after the corresponding callbacks have been invoked. This means that the }(hj#hhhNhNubjL)}(h ``->len``h]h->len}(hjOhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj#ubh count is zero only if the }(hj#hhhNhNubjL)}(h``rcu_segcblist``h]h rcu_segcblist}(hjahhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj#ubhM structure really is devoid of callbacks. Of course, off-CPU sampling of the }(hj#hhhNhNubjL)}(h ``->len``h]h->len}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj#ubh count requires careful use of appropriate synchronization, for example, memory barriers. This synchronization can be a bit subtle, particularly in the case of }(hj#hhhNhNubjL)}(h``rcu_barrier()``h]h rcu_barrier()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj#ubh.}(hj#hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjjhhubeh}(h]the-rcu-segcblist-structureah ]h"]the rcu_segcblist structureah$]h&]uh1hhhhhhhhMubh)}(hhh](h)}(hThe ``rcu_data`` Structureh](hThe }(hjhhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh Structure}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhjhhhhhM ubh)}(hXThe ``rcu_data`` maintains the per-CPU state for the RCU subsystem. The fields in this structure may be accessed only from the corresponding CPU (and from tracing) unless otherwise stated. This structure is the focus of quiescent-state detection and RCU callback queuing. It also tracks its relationship to the corresponding leaf ``rcu_node`` structure to allow more-efficient propagation of quiescent states up the ``rcu_node`` combining tree. Like the ``rcu_node`` structure, it provides a local copy of the grace-period information to allow for-free synchronized access to this information from the corresponding CPU. Finally, this structure records past dyntick-idle state for the corresponding CPU and also tracks statistics.h](hThe }(hjhhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhX: maintains the per-CPU state for the RCU subsystem. The fields in this structure may be accessed only from the corresponding CPU (and from tracing) unless otherwise stated. This structure is the focus of quiescent-state detection and RCU callback queuing. It also tracks its relationship to the corresponding leaf }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhJ structure to allow more-efficient propagation of quiescent states up the }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh combining tree. Like the }(hjhhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhX structure, it provides a local copy of the grace-period information to allow for-free synchronized access to this information from the corresponding CPU. Finally, this structure records past dyntick-idle state for the corresponding CPU and also tracks statistics.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hcThe ``rcu_data`` structure's fields are discussed, singly and in groups, in the following sections.h](hThe }(hjhhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhU structure’s fields are discussed, singly and in groups, in the following sections.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hhh](h)}(h#Connection to Other Data Structuresh]h#Connection to Other Data Structures}(hjAhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj>hhhhhMubh)}(hBThis portion of the ``rcu_data`` structure is declared as follows:h](hThis portion of the }(hjOhhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjOubh" structure is declared as follows:}(hjOhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM hj>hhubj)}(hY1 int cpu; 2 struct rcu_node *mynode; 3 unsigned long grpmask; 4 bool beenonline;h]hY1 int cpu; 2 struct rcu_node *mynode; 3 unsigned long grpmask; 4 bool beenonline;}hjosbah}(h]h ]h"]h$]h&]jjuh1jhhhM$hj>hhubh)}(hX*The ``->cpu`` field contains the number of the corresponding CPU and the ``->mynode`` field references the corresponding ``rcu_node`` structure. The ``->mynode`` is used to propagate quiescent states up the combining tree. These two fields are constant and therefore do not require synchronization.h](hThe }(hj}hhhNhNubjL)}(h ``->cpu``h]h->cpu}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj}ubh< field contains the number of the corresponding CPU and the }(hj}hhhNhNubjL)}(h ``->mynode``h]h->mynode}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj}ubh$ field references the corresponding }(hj}hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj}ubh structure. The }(hj}hhhNhNubjL)}(h ``->mynode``h]h->mynode}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj}ubh is used to propagate quiescent states up the combining tree. These two fields are constant and therefore do not require synchronization.}(hj}hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM)hj>hhubh)}(hXgThe ``->grpmask`` field indicates the bit in the ``->mynode->qsmask`` corresponding to this ``rcu_data`` structure, and is also used when propagating quiescent states. The ``->beenonline`` flag is set whenever the corresponding CPU comes online, which means that the debugfs tracing need not dump out any ``rcu_data`` structure for which this flag is not set.h](hThe }(hjhhhNhNubjL)}(h ``->grpmask``h]h ->grpmask}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh field indicates the bit in the }(hjhhhNhNubjL)}(h``->mynode->qsmask``h]h->mynode->qsmask}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh corresponding to this }(hjhhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhD structure, and is also used when propagating quiescent states. The }(hjhhhNhNubjL)}(h``->beenonline``h]h ->beenonline}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubhu flag is set whenever the corresponding CPU comes online, which means that the debugfs tracing need not dump out any }(hjhhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hj# hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjubh* structure for which this flag is not set.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM/hj>hhubeh}(h]#connection-to-other-data-structuresah ]h"]#connection to other data structuresah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(h)Quiescent-State and Grace-Period Trackingh]h)Quiescent-State and Grace-Period Tracking}(hjF hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjC hhhhhM7ubh)}(hBThis portion of the ``rcu_data`` structure is declared as follows:h](hThis portion of the }(hjT hhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hj\ hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjT ubh" structure is declared as follows:}(hjT hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM9hjC hhubj)}(hw1 unsigned long gp_seq; 2 unsigned long gp_seq_needed; 3 bool cpu_no_qs; 4 bool core_needs_qs; 5 bool gpwrap;h]hw1 unsigned long gp_seq; 2 unsigned long gp_seq_needed; 3 bool cpu_no_qs; 4 bool core_needs_qs; 5 bool gpwrap;}hjt sbah}(h]h ]h"]h$]h&]jjuh1jhhhM=hjC hhubh)}(hXuThe ``->gp_seq`` field is the counterpart of the field of the same name in the ``rcu_state`` and ``rcu_node`` structures. The ``->gp_seq_needed`` field is the counterpart of the field of the same name in the rcu_node structure. They may each lag up to one behind their ``rcu_node`` counterparts, but in ``CONFIG_NO_HZ_IDLE`` and ``CONFIG_NO_HZ_FULL`` kernels can lag arbitrarily far behind for CPUs in dyntick-idle mode (but these counters will catch up upon exit from dyntick-idle mode). If the lower two bits of a given ``rcu_data`` structure's ``->gp_seq`` are zero, then this ``rcu_data`` structure believes that RCU is idle.h](hThe }(hj hhhNhNubjL)}(h ``->gp_seq``h]h->gp_seq}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh? field is the counterpart of the field of the same name in the }(hj hhhNhNubjL)}(h ``rcu_state``h]h rcu_state}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh and }(hj hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh structures. The }(hj hhhNhNubjL)}(h``->gp_seq_needed``h]h->gp_seq_needed}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh| field is the counterpart of the field of the same name in the rcu_node structure. They may each lag up to one behind their }(hj hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh counterparts, but in }(hj hhhNhNubjL)}(h``CONFIG_NO_HZ_IDLE``h]hCONFIG_NO_HZ_IDLE}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh and }(hj hhhNhNubjL)}(h``CONFIG_NO_HZ_FULL``h]hCONFIG_NO_HZ_FULL}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh kernels can lag arbitrarily far behind for CPUs in dyntick-idle mode (but these counters will catch up upon exit from dyntick-idle mode). If the lower two bits of a given }(hj hhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh structure’s }(hj hhhNhNubjL)}(h ``->gp_seq``h]h->gp_seq}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh are zero, then this }(hj hhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hj,!hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj ubh% structure believes that RCU is idle.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMChjC hhubj~)}(hhh]j)}(hhh](j)}(hhh]h}(h]h ]h"]h$]h&]colwidthKGuh1jhjG!ubj)}(hhh](j)}(hhh]j)}(hhh]h)}(h**Quick Quiz**:h](j)}(h**Quick Quiz**h]h Quick Quiz}(hja!hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj]!ubh:}(hj]!hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMOhjZ!ubah}(h]h ]h"]h$]h&]uh1jhjW!ubah}(h]h ]h"]h$]h&]uh1jhjT!ubj)}(hhh]j)}(hhh]h)}(hAll this replication of the grace period numbers can only cause massive confusion. Why not just keep a global sequence number and be done with it???h]hAll this replication of the grace period numbers can only cause massive confusion. Why not just keep a global sequence number and be done with it???}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMQhj!ubah}(h]h ]h"]h$]h&]uh1jhj!ubah}(h]h ]h"]h$]h&]uh1jhjT!ubj)}(hhh]j)}(hhh]h)}(h **Answer**:h](j)}(h **Answer**h]hAnswer}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj!ubh:}(hj!hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMUhj!ubah}(h]h ]h"]h$]h&]uh1jhj!ubah}(h]h ]h"]h$]h&]uh1jhjT!ubj)}(hhh]j)}(hhh]h)}(hXBecause if there was only a single global sequence numbers, there would need to be a single global lock to allow safely accessing and updating it. And if we are not going to have a single global lock, we need to carefully manage the numbers on a per-node basis. Recall from the answer to a previous Quick Quiz that the consequences of applying a previously sampled quiescent state to the wrong grace period are quite severe.h]hXBecause if there was only a single global sequence numbers, there would need to be a single global lock to allow safely accessing and updating it. And if we are not going to have a single global lock, we need to carefully manage the numbers on a per-node basis. Recall from the answer to a previous Quick Quiz that the consequences of applying a previously sampled quiescent state to the wrong grace period are quite severe.}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMWhj!ubah}(h]h ]h"]h$]h&]uh1jhj!ubah}(h]h ]h"]h$]h&]uh1jhjT!ubeh}(h]h ]h"]h$]h&]uh1jhjG!ubeh}(h]h ]h"]h$]h&]colsKuh1jhjD!ubah}(h]h ]h"]h$]h&]uh1j}hjC hhhhhNubh)}(hXThe ``->cpu_no_qs`` flag indicates that the CPU has not yet passed through a quiescent state, while the ``->core_needs_qs`` flag indicates that the RCU core needs a quiescent state from the corresponding CPU. The ``->gpwrap`` field indicates that the corresponding CPU has remained idle for so long that the ``gp_seq`` counter is in danger of overflow, which will cause the CPU to disregard the values of its counters on its next exit from idle.h](hThe }(hj"hhhNhNubjL)}(h``->cpu_no_qs``h]h ->cpu_no_qs}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj"ubhU flag indicates that the CPU has not yet passed through a quiescent state, while the }(hj"hhhNhNubjL)}(h``->core_needs_qs``h]h->core_needs_qs}(hj "hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj"ubhZ flag indicates that the RCU core needs a quiescent state from the corresponding CPU. The }(hj"hhhNhNubjL)}(h ``->gpwrap``h]h->gpwrap}(hj2"hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj"ubhS field indicates that the corresponding CPU has remained idle for so long that the }(hj"hhhNhNubjL)}(h ``gp_seq``h]hgp_seq}(hjD"hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj"ubh counter is in danger of overflow, which will cause the CPU to disregard the values of its counters on its next exit from idle.}(hj"hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM`hjC hhubeh}(h])quiescent-state-and-grace-period-trackingah ]h"])quiescent-state and grace-period trackingah$]h&]uh1hhjhhhhhM7ubh)}(hhh](h)}(hRCU Callback Handlingh]hRCU Callback Handling}(hjg"hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjd"hhhhhMiubh)}(hXtIn the absence of CPU-hotplug events, RCU callbacks are invoked by the same CPU that registered them. This is strictly a cache-locality optimization: callbacks can and do get invoked on CPUs other than the one that registered them. After all, if the CPU that registered a given callback has gone offline before the callback can be invoked, there really is no other choice.h]hXtIn the absence of CPU-hotplug events, RCU callbacks are invoked by the same CPU that registered them. This is strictly a cache-locality optimization: callbacks can and do get invoked on CPUs other than the one that registered them. After all, if the CPU that registered a given callback has gone offline before the callback can be invoked, there really is no other choice.}(hju"hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMkhjd"hhubh)}(hBThis portion of the ``rcu_data`` structure is declared as follows:h](hThis portion of the }(hj"hhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj"ubh" structure is declared as follows:}(hj"hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMrhjd"hhubj)}(h1 struct rcu_segcblist cblist; 2 long qlen_last_fqs_check; 3 unsigned long n_cbs_invoked; 4 unsigned long n_nocbs_invoked; 5 unsigned long n_cbs_orphaned; 6 unsigned long n_cbs_adopted; 7 unsigned long n_force_qs_snap; 8 long blimit;h]h1 struct rcu_segcblist cblist; 2 long qlen_last_fqs_check; 3 unsigned long n_cbs_invoked; 4 unsigned long n_nocbs_invoked; 5 unsigned long n_cbs_orphaned; 6 unsigned long n_cbs_adopted; 7 unsigned long n_force_qs_snap; 8 long blimit;}hj"sbah}(h]h ]h"]h$]h&]jjuh1jhhhMvhjd"hhubh)}(hXThe ``->cblist`` structure is the segmented callback list described earlier. The CPU advances the callbacks in its ``rcu_data`` structure whenever it notices that another RCU grace period has completed. The CPU detects the completion of an RCU grace period by noticing that the value of its ``rcu_data`` structure's ``->gp_seq`` field differs from that of its leaf ``rcu_node`` structure. Recall that each ``rcu_node`` structure's ``->gp_seq`` field is updated at the beginnings and ends of each grace period.h](hThe }(hj"hhhNhNubjL)}(h ``->cblist``h]h->cblist}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj"ubhc structure is the segmented callback list described earlier. The CPU advances the callbacks in its }(hj"hhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj"ubh structure whenever it notices that another RCU grace period has completed. The CPU detects the completion of an RCU grace period by noticing that the value of its }(hj"hhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj"ubh structure’s }(hj"hhhNhNubjL)}(h ``->gp_seq``h]h->gp_seq}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj"ubh% field differs from that of its leaf }(hj"hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj"ubh structure. Recall that each }(hj"hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj"ubh structure’s }(hj"hhhNhNubjL)}(h ``->gp_seq``h]h->gp_seq}(hj%#hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj"ubhB field is updated at the beginnings and ends of each grace period.}(hj"hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjd"hhubh)}(hThe ``->qlen_last_fqs_check`` and ``->n_force_qs_snap`` coordinate the forcing of quiescent states from ``call_rcu()`` and friends when callback lists grow excessively long.h](hThe }(hj=#hhhNhNubjL)}(h``->qlen_last_fqs_check``h]h->qlen_last_fqs_check}(hjE#hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj=#ubh and }(hj=#hhhNhNubjL)}(h``->n_force_qs_snap``h]h->n_force_qs_snap}(hjW#hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj=#ubh1 coordinate the forcing of quiescent states from }(hj=#hhhNhNubjL)}(h``call_rcu()``h]h call_rcu()}(hji#hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj=#ubh7 and friends when callback lists grow excessively long.}(hj=#hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjd"hhubh)}(hX9The ``->n_cbs_invoked``, ``->n_cbs_orphaned``, and ``->n_cbs_adopted`` fields count the number of callbacks invoked, sent to other CPUs when this CPU goes offline, and received from other CPUs when those other CPUs go offline. The ``->n_nocbs_invoked`` is used when the CPU's callbacks are offloaded to a kthread.h](hThe }(hj#hhhNhNubjL)}(h``->n_cbs_invoked``h]h->n_cbs_invoked}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj#ubh, }(hj#hhhNhNubjL)}(h``->n_cbs_orphaned``h]h->n_cbs_orphaned}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj#ubh, and }(hj#hhhNhNubjL)}(h``->n_cbs_adopted``h]h->n_cbs_adopted}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj#ubh fields count the number of callbacks invoked, sent to other CPUs when this CPU goes offline, and received from other CPUs when those other CPUs go offline. The }(hj#hhhNhNubjL)}(h``->n_nocbs_invoked``h]h->n_nocbs_invoked}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj#ubh? is used when the CPU’s callbacks are offloaded to a kthread.}(hj#hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjd"hhubh)}(hmFinally, the ``->blimit`` counter is the maximum number of RCU callbacks that may be invoked at a given time.h](h Finally, the }(hj#hhhNhNubjL)}(h ``->blimit``h]h->blimit}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj#ubhT counter is the maximum number of RCU callbacks that may be invoked at a given time.}(hj#hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjd"hhubeh}(h]rcu-callback-handlingah ]h"]rcu callback handlingah$]h&]uh1hhjhhhhhMiubh)}(hhh](h)}(hDyntick-Idle Handlingh]hDyntick-Idle Handling}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj#hhhhhMubh)}(hBThis portion of the ``rcu_data`` structure is declared as follows:h](hThis portion of the }(hj$hhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj$ubh" structure is declared as follows:}(hj$hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj#hhubj)}(h61 int watching_snap; 2 unsigned long dynticks_fqs;h]h61 int watching_snap; 2 unsigned long dynticks_fqs;}hj0$sbah}(h]h ]h"]h$]h&]jjuh1jhhhMhj#hhubh)}(hX_The ``->watching_snap`` field is used to take a snapshot of the corresponding CPU's dyntick-idle state when forcing quiescent states, and is therefore accessed from other CPUs. Finally, the ``->dynticks_fqs`` field is used to count the number of times this CPU is determined to be in dyntick-idle state, and is used for tracing and debugging purposes.h](hThe }(hj>$hhhNhNubjL)}(h``->watching_snap``h]h->watching_snap}(hjF$hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj>$ubh field is used to take a snapshot of the corresponding CPU’s dyntick-idle state when forcing quiescent states, and is therefore accessed from other CPUs. Finally, the }(hj>$hhhNhNubjL)}(h``->dynticks_fqs``h]h->dynticks_fqs}(hjX$hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj>$ubh field is used to count the number of times this CPU is determined to be in dyntick-idle state, and is used for tracing and debugging purposes.}(hj>$hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj#hhubh)}(h>This portion of the rcu_data structure is declared as follows:h]h>This portion of the rcu_data structure is declared as follows:}(hjp$hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj#hhubj)}(hr1 long nesting; 2 long nmi_nesting; 3 atomic_t dynticks; 4 bool rcu_need_heavy_qs; 5 bool rcu_urgent_qs;h]hr1 long nesting; 2 long nmi_nesting; 3 atomic_t dynticks; 4 bool rcu_need_heavy_qs; 5 bool rcu_urgent_qs;}hj~$sbah}(h]h ]h"]h$]h&]jjuh1jhhhMhj#hhubh)}(hThese fields in the rcu_data structure maintain the per-CPU dyntick-idle state for the corresponding CPU. The fields may be accessed only from the corresponding CPU (and from tracing) unless otherwise stated.h]hThese fields in the rcu_data structure maintain the per-CPU dyntick-idle state for the corresponding CPU. The fields may be accessed only from the corresponding CPU (and from tracing) unless otherwise stated.}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj#hhubh)}(hXThe ``->nesting`` field counts the nesting depth of process execution, so that in normal circumstances this counter has value zero or one. NMIs, irqs, and tracers are counted by the ``->nmi_nesting`` field. Because NMIs cannot be masked, changes to this variable have to be undertaken carefully using an algorithm provided by Andy Lutomirski. The initial transition from idle adds one, and nested transitions add two, so that a nesting level of five is represented by a ``->nmi_nesting`` value of nine. This counter can therefore be thought of as counting the number of reasons why this CPU cannot be permitted to enter dyntick-idle mode, aside from process-level transitions.h](hThe }(hj$hhhNhNubjL)}(h ``->nesting``h]h ->nesting}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj$ubh field counts the nesting depth of process execution, so that in normal circumstances this counter has value zero or one. NMIs, irqs, and tracers are counted by the }(hj$hhhNhNubjL)}(h``->nmi_nesting``h]h ->nmi_nesting}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj$ubhX field. Because NMIs cannot be masked, changes to this variable have to be undertaken carefully using an algorithm provided by Andy Lutomirski. The initial transition from idle adds one, and nested transitions add two, so that a nesting level of five is represented by a }(hj$hhhNhNubjL)}(h``->nmi_nesting``h]h ->nmi_nesting}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj$ubh value of nine. This counter can therefore be thought of as counting the number of reasons why this CPU cannot be permitted to enter dyntick-idle mode, aside from process-level transitions.}(hj$hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj#hhubh)}(hXHowever, it turns out that when running in non-idle kernel context, the Linux kernel is fully capable of entering interrupt handlers that never exit and perhaps also vice versa. Therefore, whenever the ``->nesting`` field is incremented up from zero, the ``->nmi_nesting`` field is set to a large positive number, and whenever the ``->nesting`` field is decremented down to zero, the ``->nmi_nesting`` field is set to zero. Assuming that the number of misnested interrupts is not sufficient to overflow the counter, this approach corrects the ``->nmi_nesting`` field every time the corresponding CPU enters the idle loop from process context.h](hHowever, it turns out that when running in non-idle kernel context, the Linux kernel is fully capable of entering interrupt handlers that never exit and perhaps also vice versa. Therefore, whenever the }(hj$hhhNhNubjL)}(h ``->nesting``h]h ->nesting}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj$ubh( field is incremented up from zero, the }(hj$hhhNhNubjL)}(h``->nmi_nesting``h]h ->nmi_nesting}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj$ubh; field is set to a large positive number, and whenever the }(hj$hhhNhNubjL)}(h ``->nesting``h]h ->nesting}(hj %hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj$ubh( field is decremented down to zero, the }(hj$hhhNhNubjL)}(h``->nmi_nesting``h]h ->nmi_nesting}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj$ubh field is set to zero. Assuming that the number of misnested interrupts is not sufficient to overflow the counter, this approach corrects the }(hj$hhhNhNubjL)}(h``->nmi_nesting``h]h ->nmi_nesting}(hj.%hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj$ubhR field every time the corresponding CPU enters the idle loop from process context.}(hj$hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj#hhubh)}(hXfThe ``->dynticks`` field counts the corresponding CPU's transitions to and from either dyntick-idle or user mode, so that this counter has an even value when the CPU is in dyntick-idle mode or user mode and an odd value otherwise. The transitions to/from user mode need to be counted for user mode adaptive-ticks support (see Documentation/timers/no_hz.rst).h](hThe }(hjF%hhhNhNubjL)}(h``->dynticks``h]h ->dynticks}(hjN%hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjF%ubhXV field counts the corresponding CPU’s transitions to and from either dyntick-idle or user mode, so that this counter has an even value when the CPU is in dyntick-idle mode or user mode and an odd value otherwise. The transitions to/from user mode need to be counted for user mode adaptive-ticks support (see Documentation/timers/no_hz.rst).}(hjF%hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj#hhubh)}(hXkThe ``->rcu_need_heavy_qs`` field is used to record the fact that the RCU core code would really like to see a quiescent state from the corresponding CPU, so much so that it is willing to call for heavy-weight dyntick-counter operations. This flag is checked by RCU's context-switch and ``cond_resched()`` code, which provide a momentary idle sojourn in response.h](hThe }(hjf%hhhNhNubjL)}(h``->rcu_need_heavy_qs``h]h->rcu_need_heavy_qs}(hjn%hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjf%ubhX field is used to record the fact that the RCU core code would really like to see a quiescent state from the corresponding CPU, so much so that it is willing to call for heavy-weight dyntick-counter operations. This flag is checked by RCU’s context-switch and }(hjf%hhhNhNubjL)}(h``cond_resched()``h]hcond_resched()}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjf%ubh: code, which provide a momentary idle sojourn in response.}(hjf%hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj#hhubh)}(hXbFinally, the ``->rcu_urgent_qs`` field is used to record the fact that the RCU core code would really like to see a quiescent state from the corresponding CPU, with the various other fields indicating just how badly RCU wants this quiescent state. This flag is checked by RCU's context-switch path (``rcu_note_context_switch``) and the cond_resched code.h](h Finally, the }(hj%hhhNhNubjL)}(h``->rcu_urgent_qs``h]h->rcu_urgent_qs}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj%ubhX  field is used to record the fact that the RCU core code would really like to see a quiescent state from the corresponding CPU, with the various other fields indicating just how badly RCU wants this quiescent state. This flag is checked by RCU’s context-switch path (}(hj%hhhNhNubjL)}(h``rcu_note_context_switch``h]hrcu_note_context_switch}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj%ubh) and the cond_resched code.}(hj%hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj#hhubj~)}(hhh]j)}(hhh](j)}(hhh]h}(h]h ]h"]h$]h&]colwidthKGuh1jhj%ubj)}(hhh](j)}(hhh]j)}(hhh]h)}(h**Quick Quiz**:h](j)}(h**Quick Quiz**h]h Quick Quiz}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj%ubh:}(hj%hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj%ubah}(h]h ]h"]h$]h&]uh1jhj%ubah}(h]h ]h"]h$]h&]uh1jhj%ubj)}(hhh]j)}(hhh]h)}(hWhy not simply combine the ``->nesting`` and ``->nmi_nesting`` counters into a single counter that just counts the number of reasons that the corresponding CPU is non-idle?h](hWhy not simply combine the }(hj&hhhNhNubjL)}(h ``->nesting``h]h ->nesting}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj&ubh and }(hj&hhhNhNubjL)}(h``->nmi_nesting``h]h ->nmi_nesting}(hj+&hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj&ubhn counters into a single counter that just counts the number of reasons that the corresponding CPU is non-idle?}(hj&hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj&ubah}(h]h ]h"]h$]h&]uh1jhj &ubah}(h]h ]h"]h$]h&]uh1jhj%ubj)}(hhh]j)}(hhh]h)}(h **Answer**:h](j)}(h **Answer**h]hAnswer}(hjY&hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjU&ubh:}(hjU&hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjR&ubah}(h]h ]h"]h$]h&]uh1jhjO&ubah}(h]h ]h"]h$]h&]uh1jhj%ubj)}(hhh]j)}(hhh]h)}(hBecause this would fail in the presence of interrupts whose handlers never return and of handlers that manage to return from a made-up interrupt.h]hBecause this would fail in the presence of interrupts whose handlers never return and of handlers that manage to return from a made-up interrupt.}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj&ubah}(h]h ]h"]h$]h&]uh1jhj}&ubah}(h]h ]h"]h$]h&]uh1jhj%ubeh}(h]h ]h"]h$]h&]uh1jhj%ubeh}(h]h ]h"]h$]h&]colsKuh1jhj%ubah}(h]h ]h"]h$]h&]uh1j}hj#hhhhhNubh)}(h\Additional fields are present for some special-purpose builds, and are discussed separately.h]h\Additional fields are present for some special-purpose builds, and are discussed separately.}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj#hhubeh}(h]dyntick-idle-handlingah ]h"]dyntick-idle handlingah$]h&]uh1hhjhhhhhMubeh}(h]the-rcu-data-structureah ]h"]the rcu_data structureah$]h&]uh1hhhhhhhhM ubh)}(hhh](h)}(hThe ``rcu_head`` Structureh](hThe }(hj&hhhNhNubjL)}(h ``rcu_head``h]hrcu_head}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj&ubh Structure}(hj&hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhj&hhhhhMubh)}(hX5Each ``rcu_head`` structure represents an RCU callback. These structures are normally embedded within RCU-protected data structures whose algorithms use asynchronous grace periods. In contrast, when using algorithms that block waiting for RCU grace periods, RCU users need not provide ``rcu_head`` structures.h](hEach }(hj&hhhNhNubjL)}(h ``rcu_head``h]hrcu_head}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj&ubhX  structure represents an RCU callback. These structures are normally embedded within RCU-protected data structures whose algorithms use asynchronous grace periods. In contrast, when using algorithms that block waiting for RCU grace periods, RCU users need not provide }(hj&hhhNhNubjL)}(h ``rcu_head``h]hrcu_head}(hj 'hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj&ubh structures.}(hj&hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj&hhubh)}(h1The ``rcu_head`` structure has fields as follows:h](hThe }(hj#'hhhNhNubjL)}(h ``rcu_head``h]hrcu_head}(hj+'hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj#'ubh! structure has fields as follows:}(hj#'hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj&hhubj)}(hC1 struct rcu_head *next; 2 void (*func)(struct rcu_head *head);h]hC1 struct rcu_head *next; 2 void (*func)(struct rcu_head *head);}hjC'sbah}(h]h ]h"]h$]h&]jjuh1jhhhMhj&hhubh)}(hXThe ``->next`` field is used to link the ``rcu_head`` structures together in the lists within the ``rcu_data`` structures. The ``->func`` field is a pointer to the function to be called when the callback is ready to be invoked, and this function is passed a pointer to the ``rcu_head`` structure. However, ``kfree_rcu()`` uses the ``->func`` field to record the offset of the ``rcu_head`` structure within the enclosing RCU-protected data structure.h](hThe }(hjQ'hhhNhNubjL)}(h ``->next``h]h->next}(hjY'hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjQ'ubh field is used to link the }(hjQ'hhhNhNubjL)}(h ``rcu_head``h]hrcu_head}(hjk'hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjQ'ubh- structures together in the lists within the }(hjQ'hhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hj}'hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjQ'ubh structures. The }(hjQ'hhhNhNubjL)}(h ``->func``h]h->func}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjQ'ubh field is a pointer to the function to be called when the callback is ready to be invoked, and this function is passed a pointer to the }(hjQ'hhhNhNubjL)}(h ``rcu_head``h]hrcu_head}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjQ'ubh structure. However, }(hjQ'hhhNhNubjL)}(h``kfree_rcu()``h]h kfree_rcu()}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjQ'ubh uses the }(hjQ'hhhNhNubjL)}(h ``->func``h]h->func}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjQ'ubh# field to record the offset of the }(hjQ'hhhNhNubjL)}(h ``rcu_head``h]hrcu_head}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjQ'ubh= structure within the enclosing RCU-protected data structure.}(hjQ'hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj&hhubh)}(h{Both of these fields are used internally by RCU. From the viewpoint of RCU users, this structure is an opaque “cookie”.h]h{Both of these fields are used internally by RCU. From the viewpoint of RCU users, this structure is an opaque “cookie”.}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hj&hhubj~)}(hhh]j)}(hhh](j)}(hhh]h}(h]h ]h"]h$]h&]colwidthKGuh1jhj(ubj)}(hhh](j)}(hhh]j)}(hhh]h)}(h**Quick Quiz**:h](j)}(h**Quick Quiz**h]h Quick Quiz}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj(ubh:}(hj(hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM hj(ubah}(h]h ]h"]h$]h&]uh1jhj(ubah}(h]h ]h"]h$]h&]uh1jhj (ubj)}(hhh]j)}(hhh]h)}(hGiven that the callback function ``->func`` is passed a pointer to the ``rcu_head`` structure, how is that function supposed to find the beginning of the enclosing RCU-protected data structure?h](h!Given that the callback function }(hjD(hhhNhNubjL)}(h ``->func``h]h->func}(hjL(hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjD(ubh is passed a pointer to the }(hjD(hhhNhNubjL)}(h ``rcu_head``h]hrcu_head}(hj^(hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhjD(ubhn structure, how is that function supposed to find the beginning of the enclosing RCU-protected data structure?}(hjD(hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjA(ubah}(h]h ]h"]h$]h&]uh1jhj>(ubah}(h]h ]h"]h$]h&]uh1jhj (ubj)}(hhh]j)}(hhh]h)}(h **Answer**:h](j)}(h **Answer**h]hAnswer}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj(ubh:}(hj(hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj(ubah}(h]h ]h"]h$]h&]uh1jhj(ubah}(h]h ]h"]h$]h&]uh1jhj (ubj)}(hhh]j)}(hhh]h)}(hX8In actual practice, there is a separate callback function per type of RCU-protected data structure. The callback function can therefore use the ``container_of()`` macro in the Linux kernel (or other pointer-manipulation facilities in other software environments) to find the beginning of the enclosing structure.h](hIn actual practice, there is a separate callback function per type of RCU-protected data structure. The callback function can therefore use the }(hj(hhhNhNubjL)}(h``container_of()``h]hcontainer_of()}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj(ubh macro in the Linux kernel (or other pointer-manipulation facilities in other software environments) to find the beginning of the enclosing structure.}(hj(hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj(ubah}(h]h ]h"]h$]h&]uh1jhj(ubah}(h]h ]h"]h$]h&]uh1jhj (ubeh}(h]h ]h"]h$]h&]uh1jhj(ubeh}(h]h ]h"]h$]h&]colsKuh1jhj'ubah}(h]h ]h"]h$]h&]uh1j}hj&hhhhhNubeh}(h]the-rcu-head-structureah ]h"]the rcu_head structureah$]h&]uh1hhhhhhhhMubh)}(hhh](h)}(h4RCU-Specific Fields in the ``task_struct`` Structureh](hRCU-Specific Fields in the }(hj)hhhNhNubjL)}(h``task_struct``h]h task_struct}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj)ubh Structure}(hj)hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhj(hhhhhMubh)}(hgThe ``CONFIG_PREEMPT_RCU`` implementation uses some additional fields in the ``task_struct`` structure:h](hThe }(hj )hhhNhNubjL)}(h``CONFIG_PREEMPT_RCU``h]hCONFIG_PREEMPT_RCU}(hj()hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj )ubh3 implementation uses some additional fields in the }(hj )hhhNhNubjL)}(h``task_struct``h]h task_struct}(hj:)hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj )ubh structure:}(hj )hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj(hhubj)}(hX 1 #ifdef CONFIG_PREEMPT_RCU 2 int rcu_read_lock_nesting; 3 union rcu_special rcu_read_unlock_special; 4 struct list_head rcu_node_entry; 5 struct rcu_node *rcu_blocked_node; 6 #endif /* #ifdef CONFIG_PREEMPT_RCU */ 7 #ifdef CONFIG_TASKS_RCU 8 unsigned long rcu_tasks_nvcsw; 9 bool rcu_tasks_holdout; 10 struct list_head rcu_tasks_holdout_list; 11 int rcu_tasks_idle_cpu; 12 #endif /* #ifdef CONFIG_TASKS_RCU */h]hX 1 #ifdef CONFIG_PREEMPT_RCU 2 int rcu_read_lock_nesting; 3 union rcu_special rcu_read_unlock_special; 4 struct list_head rcu_node_entry; 5 struct rcu_node *rcu_blocked_node; 6 #endif /* #ifdef CONFIG_PREEMPT_RCU */ 7 #ifdef CONFIG_TASKS_RCU 8 unsigned long rcu_tasks_nvcsw; 9 bool rcu_tasks_holdout; 10 struct list_head rcu_tasks_holdout_list; 11 int rcu_tasks_idle_cpu; 12 #endif /* #ifdef CONFIG_TASKS_RCU */}hjR)sbah}(h]h ]h"]h$]h&]jjuh1jhhhM$hj(hhubh)}(hX@The ``->rcu_read_lock_nesting`` field records the nesting level for RCU read-side critical sections, and the ``->rcu_read_unlock_special`` field is a bitmask that records special conditions that require ``rcu_read_unlock()`` to do additional work. The ``->rcu_node_entry`` field is used to form lists of tasks that have blocked within preemptible-RCU read-side critical sections and the ``->rcu_blocked_node`` field references the ``rcu_node`` structure whose list this task is a member of, or ``NULL`` if it is not blocked within a preemptible-RCU read-side critical section.h](hThe }(hj`)hhhNhNubjL)}(h``->rcu_read_lock_nesting``h]h->rcu_read_lock_nesting}(hjh)hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj`)ubhN field records the nesting level for RCU read-side critical sections, and the }(hj`)hhhNhNubjL)}(h``->rcu_read_unlock_special``h]h->rcu_read_unlock_special}(hjz)hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj`)ubhA field is a bitmask that records special conditions that require }(hj`)hhhNhNubjL)}(h``rcu_read_unlock()``h]hrcu_read_unlock()}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj`)ubh to do additional work. The }(hj`)hhhNhNubjL)}(h``->rcu_node_entry``h]h->rcu_node_entry}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj`)ubhs field is used to form lists of tasks that have blocked within preemptible-RCU read-side critical sections and the }(hj`)hhhNhNubjL)}(h``->rcu_blocked_node``h]h->rcu_blocked_node}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj`)ubh field references the }(hj`)hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj`)ubh3 structure whose list this task is a member of, or }(hj`)hhhNhNubjL)}(h``NULL``h]hNULL}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj`)ubhJ if it is not blocked within a preemptible-RCU read-side critical section.}(hj`)hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM1hj(hhubh)}(hXThe ``->rcu_tasks_nvcsw`` field tracks the number of voluntary context switches that this task had undergone at the beginning of the current tasks-RCU grace period, ``->rcu_tasks_holdout`` is set if the current tasks-RCU grace period is waiting on this task, ``->rcu_tasks_holdout_list`` is a list element enqueuing this task on the holdout list, and ``->rcu_tasks_idle_cpu`` tracks which CPU this idle task is running, but only if the task is currently running, that is, if the CPU is currently idle.h](hThe }(hj)hhhNhNubjL)}(h``->rcu_tasks_nvcsw``h]h->rcu_tasks_nvcsw}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj)ubh field tracks the number of voluntary context switches that this task had undergone at the beginning of the current tasks-RCU grace period, }(hj)hhhNhNubjL)}(h``->rcu_tasks_holdout``h]h->rcu_tasks_holdout}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj)ubhG is set if the current tasks-RCU grace period is waiting on this task, }(hj)hhhNhNubjL)}(h``->rcu_tasks_holdout_list``h]h->rcu_tasks_holdout_list}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj)ubh@ is a list element enqueuing this task on the holdout list, and }(hj)hhhNhNubjL)}(h``->rcu_tasks_idle_cpu``h]h->rcu_tasks_idle_cpu}(hj**hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj)ubh~ tracks which CPU this idle task is running, but only if the task is currently running, that is, if the CPU is currently idle.}(hj)hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM;hj(hhubeh}(h]0rcu-specific-fields-in-the-task-struct-structureah ]h"]0rcu-specific fields in the task_struct structureah$]h&]uh1hhhhhhhhMubh)}(hhh](h)}(hAccessor Functionsh]hAccessor Functions}(hjM*hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjJ*hhhhhMEubh)}(hThe following listing shows the ``rcu_get_root()``, ``rcu_for_each_node_breadth_first`` and ``rcu_for_each_leaf_node()`` function and macros:h](h The following listing shows the }(hj[*hhhNhNubjL)}(h``rcu_get_root()``h]hrcu_get_root()}(hjc*hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj[*ubh, }(hj[*hhhNhNubjL)}(h#``rcu_for_each_node_breadth_first``h]hrcu_for_each_node_breadth_first}(hju*hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj[*ubh and }(hj[*hhhNhNubjL)}(h``rcu_for_each_leaf_node()``h]hrcu_for_each_leaf_node()}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj[*ubh function and macros:}(hj[*hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMGhjJ*hhubj)}(hX 1 static struct rcu_node *rcu_get_root(struct rcu_state *rsp) 2 { 3 return &rsp->node[0]; 4 } 5 6 #define rcu_for_each_node_breadth_first(rsp, rnp) \ 7 for ((rnp) = &(rsp)->node[0]; \ 8 (rnp) < &(rsp)->node[NUM_RCU_NODES]; (rnp)++) 9 10 #define rcu_for_each_leaf_node(rsp, rnp) \ 11 for ((rnp) = (rsp)->level[NUM_RCU_LVLS - 1]; \ 12 (rnp) < &(rsp)->node[NUM_RCU_NODES]; (rnp)++)h]hX 1 static struct rcu_node *rcu_get_root(struct rcu_state *rsp) 2 { 3 return &rsp->node[0]; 4 } 5 6 #define rcu_for_each_node_breadth_first(rsp, rnp) \ 7 for ((rnp) = &(rsp)->node[0]; \ 8 (rnp) < &(rsp)->node[NUM_RCU_NODES]; (rnp)++) 9 10 #define rcu_for_each_leaf_node(rsp, rnp) \ 11 for ((rnp) = (rsp)->level[NUM_RCU_LVLS - 1]; \ 12 (rnp) < &(rsp)->node[NUM_RCU_NODES]; (rnp)++)}hj*sbah}(h]h ]h"]h$]h&]jjuh1jhhhMMhjJ*hhubh)}(hThe ``rcu_get_root()`` simply returns a pointer to the first element of the specified ``rcu_state`` structure's ``->node[]`` array, which is the root ``rcu_node`` structure.h](hThe }(hj*hhhNhNubjL)}(h``rcu_get_root()``h]hrcu_get_root()}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj*ubh@ simply returns a pointer to the first element of the specified }(hj*hhhNhNubjL)}(h ``rcu_state``h]h rcu_state}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj*ubh structure’s }(hj*hhhNhNubjL)}(h ``->node[]``h]h->node[]}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj*ubh array, which is the root }(hj*hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj*ubh structure.}(hj*hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMZhjJ*hhubh)}(hXAs noted earlier, the ``rcu_for_each_node_breadth_first()`` macro takes advantage of the layout of the ``rcu_node`` structures in the ``rcu_state`` structure's ``->node[]`` array, performing a breadth-first traversal by simply traversing the array in order. Similarly, the ``rcu_for_each_leaf_node()`` macro traverses only the last part of the array, thus traversing only the leaf ``rcu_node`` structures.h](hAs noted earlier, the }(hj+hhhNhNubjL)}(h%``rcu_for_each_node_breadth_first()``h]h!rcu_for_each_node_breadth_first()}(hj +hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj+ubh, macro takes advantage of the layout of the }(hj+hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj+ubh structures in the }(hj+hhhNhNubjL)}(h ``rcu_state``h]h rcu_state}(hj/+hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj+ubh structure’s }(hj+hhhNhNubjL)}(h ``->node[]``h]h->node[]}(hjA+hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj+ubhe array, performing a breadth-first traversal by simply traversing the array in order. Similarly, the }(hj+hhhNhNubjL)}(h``rcu_for_each_leaf_node()``h]hrcu_for_each_leaf_node()}(hjS+hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj+ubhP macro traverses only the last part of the array, thus traversing only the leaf }(hj+hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hje+hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj+ubh structures.}(hj+hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM^hjJ*hhubj~)}(hhh]j)}(hhh](j)}(hhh]h}(h]h ]h"]h$]h&]colwidthKGuh1jhj+ubj)}(hhh](j)}(hhh]j)}(hhh]h)}(h**Quick Quiz**:h](j)}(h**Quick Quiz**h]h Quick Quiz}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj+ubh:}(hj+hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMfhj+ubah}(h]h ]h"]h$]h&]uh1jhj+ubah}(h]h ]h"]h$]h&]uh1jhj+ubj)}(hhh]j)}(hhh]h)}(h_What does ``rcu_for_each_leaf_node()`` do if the ``rcu_node`` tree contains only a single node?h](h What does }(hj+hhhNhNubjL)}(h``rcu_for_each_leaf_node()``h]hrcu_for_each_leaf_node()}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj+ubh do if the }(hj+hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj+ubh" tree contains only a single node?}(hj+hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhhj+ubah}(h]h ]h"]h$]h&]uh1jhj+ubah}(h]h ]h"]h$]h&]uh1jhj+ubj)}(hhh]j)}(hhh]h)}(h **Answer**:h](j)}(h **Answer**h]hAnswer}(hj ,hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj,ubh:}(hj,hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMkhj,ubah}(h]h ]h"]h$]h&]uh1jhj,ubah}(h]h ]h"]h$]h&]uh1jhj+ubj)}(hhh]j)}(hhh]h)}(hPIn the single-node case, ``rcu_for_each_leaf_node()`` traverses the single node.h](hIn the single-node case, }(hj6,hhhNhNubjL)}(h``rcu_for_each_leaf_node()``h]hrcu_for_each_leaf_node()}(hj>,hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj6,ubh traverses the single node.}(hj6,hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMmhj3,ubah}(h]h ]h"]h$]h&]uh1jhj0,ubah}(h]h ]h"]h$]h&]uh1jhj+ubeh}(h]h ]h"]h$]h&]uh1jhj+ubeh}(h]h ]h"]h$]h&]colsKuh1jhj}+ubah}(h]h ]h"]h$]h&]uh1j}hjJ*hhhhhNubeh}(h]accessor-functionsah ]h"]accessor functionsah$]h&]uh1hhhhhhhhMEubh)}(hhh](h)}(hSummaryh]hSummary}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj},hhhhhMrubh)}(hXSo the state of RCU is represented by an ``rcu_state`` structure, which contains a combining tree of ``rcu_node`` and ``rcu_data`` structures. Finally, in ``CONFIG_NO_HZ_IDLE`` kernels, each CPU's dyntick-idle state is tracked by dynticks-related fields in the ``rcu_data`` structure. If you made it this far, you are well prepared to read the code walkthroughs in the other articles in this series.h](h)So the state of RCU is represented by an }(hj,hhhNhNubjL)}(h ``rcu_state``h]h rcu_state}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj,ubh/ structure, which contains a combining tree of }(hj,hhhNhNubjL)}(h ``rcu_node``h]hrcu_node}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj,ubh and }(hj,hhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj,ubh structures. Finally, in }(hj,hhhNhNubjL)}(h``CONFIG_NO_HZ_IDLE``h]hCONFIG_NO_HZ_IDLE}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj,ubhW kernels, each CPU’s dyntick-idle state is tracked by dynticks-related fields in the }(hj,hhhNhNubjL)}(h ``rcu_data``h]hrcu_data}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1jKhj,ubh~ structure. If you made it this far, you are well prepared to read the code walkthroughs in the other articles in this series.}(hj,hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMthj},hhubeh}(h]summaryah ]h"]summaryah$]h&]uh1hhhhhhhhMrubh)}(hhh](h)}(hAcknowledgmentsh]hAcknowledgments}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj,hhhhhM|ubh)}(hI owe thanks to Cyrill Gorcunov, Mathieu Desnoyers, Dhaval Giani, Paul Turner, Abhishek Srivastava, Matt Kowalczyk, and Serge Hallyn for helping me get this document into a more human-readable state.h]hI owe thanks to Cyrill Gorcunov, Mathieu Desnoyers, Dhaval Giani, Paul Turner, Abhishek Srivastava, Matt Kowalczyk, and Serge Hallyn for helping me get this document into a more human-readable state.}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM~hj,hhubeh}(h]acknowledgmentsah ]h"]acknowledgmentsah$]h&]uh1hhhhhhhhM|ubh)}(hhh](h)}(hLegal Statementh]hLegal Statement}(hj(-hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj%-hhhhhMubh)}(h_This work represents the view of the author and does not necessarily represent the view of IBM.h]h_This work represents the view of the author and does not necessarily represent the view of IBM.}(hj6-hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj%-hhubh)}(h2Linux is a registered trademark of Linus Torvalds.h]h2Linux is a registered trademark of Linus Torvalds.}(hjD-hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj%-hhubh)}(hWOther company, product, and service names may be trademarks or service marks of others.h]hWOther company, product, and service names may be trademarks or service marks of others.}(hjR-hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj%-hhubeh}(h]legal-statementah ]h"]legal statementah$]h&]uh1hhhhhhhhMubeh}(h]data-structure-relationshipsah ]h"]data-structure relationshipsah$]h&]uh1hhhhhhhhKubeh}(h]1a-tour-through-tree-rcu-s-data-structures-lwn-netah ]h"]3a tour through tree_rcu's data structures [lwn.net]ah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksjfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerj-error_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}j]jasnameids}(ju-jr-hhjm-jj-j: j7 jK jH grace-period trackingNj2 j/ jgjdjDjAjjjjjjjjj_j\jjj&j&j@ j= ja"j^"j#j#j&j&j(j(jG*jD*jz,jw,j,j,j"-j-je-jb-u nametypes}(ju-hjm-j: jK j-j2 jgjDjjjjj_jj&j@ ja"j#j&j(jG*jz,j,j"-je-uh}(jr-hhhjj-hj7 j!jH jjq jN j/ jx jdj= jAj jjGjjjjjj%jjj\jjjjj&jj= j>j^"jC j#jd"j&j#j(j&jD*j(jw,jJ*j,j},j-j,jb-j%-u footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}j-KsRparse_messages]hsystem_message)}(hhh]h)}(h8Duplicate implicit target name: "grace-period tracking".h]h