1 .. _up_doc: 2 3 RCU on Uniprocessor Systems 4 =========================== 5 6 A common misconception is that, on UP systems, 7 may immediately invoke its function. The basi 8 is that since there is only one CPU, it should 9 wait for anything else to get done, since ther 10 anything else to be happening on. Although th 11 work a surprising amount of the time, it is a 12 This document presents three examples that dem 13 an idea this is. 14 15 Example 1: softirq Suicide 16 -------------------------- 17 18 Suppose that an RCU-based algorithm scans a li 19 elements A, B, and C in process context, and c 20 this same list in softirq context. Suppose th 21 is referencing element B when it is interrupte 22 which deletes element B, and then invokes call 23 after a grace period. 24 25 Now, if call_rcu() were to directly invoke its 26 from softirq, the list scan would find itself 27 element B. This situation can greatly decreas 28 your kernel. 29 30 This same problem can occur if call_rcu() is i 31 interrupt handler. 32 33 Example 2: Function-Call Fatality 34 --------------------------------- 35 36 Of course, one could avert the suicide describ 37 by having call_rcu() directly invoke its argum 38 from process context. However, this can fail 39 40 Suppose that an RCU-based algorithm again scan 41 elements A, B, and C in process context, but t 42 on each element as it is scanned. Suppose fur 43 deletes element B from the list, then passes i 44 freeing. This may be a bit unconventional, bu 45 RCU usage, since call_rcu() must wait for a gr 46 Therefore, in this case, allowing call_rcu() t 47 its arguments would cause it to fail to make t 48 underlying RCU, namely that call_rcu() defers 49 all RCU read-side critical sections currently 50 51 Quick Quiz #1: 52 Why is it *not* legal to invoke synchr 53 54 :ref:`Answers to Quick Quiz <answer_quick_quiz 55 56 Example 3: Death by Deadlock 57 ---------------------------- 58 59 Suppose that call_rcu() is invoked while holdi 60 callback function must acquire this same lock. 61 call_rcu() were to directly invoke the callbac 62 be self-deadlock *even if* this invocation occ 63 call_rcu() invocation a full grace period late 64 65 In some cases, it would possible to restructur 66 the call_rcu() is delayed until after the lock 67 there are cases where this can be quite ugly: 68 69 1. If a number of items need to be passed 70 the same critical section, then the co 71 a list of them, then traverse the list 72 released. 73 74 2. In some cases, the lock will be held a 75 so that delaying the call_rcu() until 76 requires that the data item be passed 77 It is far better to guarantee that cal 78 with no locks held than to have to mod 79 arbitrary data items to be passed back 80 81 If call_rcu() directly invokes the callback, p 82 or API changes would be required. 83 84 Quick Quiz #2: 85 What locking restriction must RCU call 86 87 :ref:`Answers to Quick Quiz <answer_quick_quiz 88 89 It is important to note that userspace RCU imp 90 permit call_rcu() to directly invoke callbacks 91 grace period has elapsed since those callbacks 92 the case because some userspace environments a 93 Nevertheless, people writing userspace RCU imp 94 encouraged to avoid invoking callbacks from ca 95 the deadlock-avoidance benefits called out abo 96 97 Summary 98 ------- 99 100 Permitting call_rcu() to immediately invoke it 101 even on a UP system. So do not do it! Even o 102 infrastructure *must* respect grace periods, a 103 from a known environment in which no locks are 104 105 Note that it *is* safe for synchronize_rcu() t 106 UP systems, including PREEMPT SMP builds runni 107 108 Quick Quiz #3: 109 Why can't synchronize_rcu() return imm 110 preemptible RCU? 111 112 .. _answer_quick_quiz_up: 113 114 Answer to Quick Quiz #1: 115 Why is it *not* legal to invoke synchr 116 117 Because the calling function is scanni 118 list, and is therefore within an RCU r 119 Therefore, the called function has bee 120 read-side critical section, and is not 121 122 Answer to Quick Quiz #2: 123 What locking restriction must RCU call 124 125 Any lock that is acquired within an RC 126 elsewhere using an _bh variant of the 127 For example, if "mylock" is acquired b 128 a process-context acquisition of this 129 like spin_lock_bh() to acquire the loc 130 it is also OK to use _irq variants of 131 spin_lock_irqsave(). 132 133 If the process-context code were to si 134 then, since RCU callbacks can be invok 135 the callback might be called from a so 136 the process-context critical section. 137 self-deadlock. 138 139 This restriction might seem gratuitous 140 callbacks acquire locks directly. How 141 callbacks do acquire locks *indirectly 142 the kfree() primitive. 143 144 Answer to Quick Quiz #3: 145 Why can't synchronize_rcu() return imm 146 running preemptible RCU? 147 148 Because some other task might have bee 149 of an RCU read-side critical section. 150 simply immediately returned, it would 151 end of the grace period, which would c 152 that other thread when it started runn
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.