Commit 2a5b0c84 authored by Jiunn Chang's avatar Jiunn Chang Committed by Jonathan Corbet

Documentation: RCU: Convert RCU UP systems to reST

RCU UP systems reST markup.
Reviewed-by: default avatarJoel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: default avatarJiunn Chang <c0d1n61at3@gmail.com>
Signed-off-by: default avatarJonathan Corbet <corbet@lwn.net>
parent 9422dc24
RCU on Uniprocessor Systems .. _up_doc:
RCU on Uniprocessor Systems
===========================
A common misconception is that, on UP systems, the call_rcu() primitive A common misconception is that, on UP systems, the call_rcu() primitive
may immediately invoke its function. The basis of this misconception may immediately invoke its function. The basis of this misconception
is that since there is only one CPU, it should not be necessary to is that since there is only one CPU, it should not be necessary to
wait for anything else to get done, since there are no other CPUs for wait for anything else to get done, since there are no other CPUs for
anything else to be happening on. Although this approach will -sort- -of- anything else to be happening on. Although this approach will *sort of*
work a surprising amount of the time, it is a very bad idea in general. work a surprising amount of the time, it is a very bad idea in general.
This document presents three examples that demonstrate exactly how bad This document presents three examples that demonstrate exactly how bad
an idea this is. an idea this is.
Example 1: softirq Suicide Example 1: softirq Suicide
--------------------------
Suppose that an RCU-based algorithm scans a linked list containing Suppose that an RCU-based algorithm scans a linked list containing
elements A, B, and C in process context, and can delete elements from elements A, B, and C in process context, and can delete elements from
...@@ -28,8 +30,8 @@ your kernel. ...@@ -28,8 +30,8 @@ your kernel.
This same problem can occur if call_rcu() is invoked from a hardware This same problem can occur if call_rcu() is invoked from a hardware
interrupt handler. interrupt handler.
Example 2: Function-Call Fatality Example 2: Function-Call Fatality
---------------------------------
Of course, one could avert the suicide described in the preceding example Of course, one could avert the suicide described in the preceding example
by having call_rcu() directly invoke its arguments only if it was called by having call_rcu() directly invoke its arguments only if it was called
...@@ -46,11 +48,13 @@ its arguments would cause it to fail to make the fundamental guarantee ...@@ -46,11 +48,13 @@ its arguments would cause it to fail to make the fundamental guarantee
underlying RCU, namely that call_rcu() defers invoking its arguments until underlying RCU, namely that call_rcu() defers invoking its arguments until
all RCU read-side critical sections currently executing have completed. all RCU read-side critical sections currently executing have completed.
Quick Quiz #1: why is it -not- legal to invoke synchronize_rcu() in Quick Quiz #1:
this case? Why is it *not* legal to invoke synchronize_rcu() in this case?
:ref:`Answers to Quick Quiz <answer_quick_quiz_up>`
Example 3: Death by Deadlock Example 3: Death by Deadlock
----------------------------
Suppose that call_rcu() is invoked while holding a lock, and that the Suppose that call_rcu() is invoked while holding a lock, and that the
callback function must acquire this same lock. In this case, if callback function must acquire this same lock. In this case, if
...@@ -76,25 +80,30 @@ there are cases where this can be quite ugly: ...@@ -76,25 +80,30 @@ there are cases where this can be quite ugly:
If call_rcu() directly invokes the callback, painful locking restrictions If call_rcu() directly invokes the callback, painful locking restrictions
or API changes would be required. or API changes would be required.
Quick Quiz #2: What locking restriction must RCU callbacks respect? Quick Quiz #2:
What locking restriction must RCU callbacks respect?
:ref:`Answers to Quick Quiz <answer_quick_quiz_up>`
Summary Summary
-------
Permitting call_rcu() to immediately invoke its arguments breaks RCU, Permitting call_rcu() to immediately invoke its arguments breaks RCU,
even on a UP system. So do not do it! Even on a UP system, the RCU even on a UP system. So do not do it! Even on a UP system, the RCU
infrastructure -must- respect grace periods, and -must- invoke callbacks infrastructure *must* respect grace periods, and *must* invoke callbacks
from a known environment in which no locks are held. from a known environment in which no locks are held.
Note that it -is- safe for synchronize_rcu() to return immediately on Note that it *is* safe for synchronize_rcu() to return immediately on
UP systems, including !PREEMPT SMP builds running on UP systems. UP systems, including PREEMPT SMP builds running on UP systems.
Quick Quiz #3: Why can't synchronize_rcu() return immediately on Quick Quiz #3:
UP systems running preemptable RCU? Why can't synchronize_rcu() return immediately on UP systems running
preemptable RCU?
.. _answer_quick_quiz_up:
Answer to Quick Quiz #1: Answer to Quick Quiz #1:
Why is it -not- legal to invoke synchronize_rcu() in this case? Why is it *not* legal to invoke synchronize_rcu() in this case?
Because the calling function is scanning an RCU-protected linked Because the calling function is scanning an RCU-protected linked
list, and is therefore within an RCU read-side critical section. list, and is therefore within an RCU read-side critical section.
...@@ -119,7 +128,7 @@ Answer to Quick Quiz #2: ...@@ -119,7 +128,7 @@ Answer to Quick Quiz #2:
This restriction might seem gratuitous, since very few RCU This restriction might seem gratuitous, since very few RCU
callbacks acquire locks directly. However, a great many RCU callbacks acquire locks directly. However, a great many RCU
callbacks do acquire locks -indirectly-, for example, via callbacks do acquire locks *indirectly*, for example, via
the kfree() primitive. the kfree() primitive.
Answer to Quick Quiz #3: Answer to Quick Quiz #3:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment