[英]How RCU reader section is protected from preemption?
(From an article on LWN ) (来自LWN上的一篇文章)
1 rcu_read_lock();
2 list_for_each_entry_rcu(p, head, list) {
3 do_something_with(p->a, p->b, p->c);
4 }
5 rcu_read_unlock();
The RCU update operation will do synchronize_rcu() in order to assert each CPU switched the context and therefore each RCU-reader has completed it's job. RCU更新操作将执行synchronize_rcu()以断言每个CPU切换上下文,因此每个RCU读取器已完成它的工作。 But RCU must rely on reader not being preempted.
但RCU必须依靠读者不被抢先一步。 And indeed, LWN says next:
事实上,LWN接着说:
Although this simple approach works for kernels in which preemption is disabled across RCU read-side critical sections, in other words, for non-CONFIG_PREEMPT and CONFIG_PREEMPT kernels, it does not work for CONFIG_PREEMPT_RT realtime (-rt) kernels.
虽然这种简单的方法适用于在RCU读取端关键部分禁用抢占的内核,换句话说,对于非CONFIG_PREEMPT和CONFIG_PREEMPT内核,它不适用于CONFIG_PREEMPT_RT实时(-rt)内核。
I understand preemption is disabled for non-CONFIG_PREEMPT kernels, but why is it OK for CONFIG_PREEMPT kernels too? 我理解对于非CONFIG_PREEMPT内核禁用抢占,但为什么CONFIG_PREEMPT内核也可以呢?
It is OK on CONFIG_PREEMPT kernels since care is taken to finish the rcu read critical section before the task is preempted. 在CONFIG_PREEMPT内核上没问题,因为在任务被抢占之前需要注意完成rcu read critical部分。 The scheduler checks if the current task is in a rcu read critical section and if so, it boosts its priority so that it finishes the critical section.
调度程序检查当前任务是否在rcu读取临界区中,如果是,则增强其优先级以使其完成临界区。 For more details see this article: http://lwn.net/Articles/220677/
有关详细信息,请参阅此文章: http : //lwn.net/Articles/220677/
We need RCU for CONFIG_PREEMPT kernels. 我们需要RCU用于CONFIG_PREEMPT内核。 If there was no pre-emption or blocking then we wouldn't in this synchronization mess.
如果没有先发制人或阻止,那么我们就不会在同步混乱中。 There are two types of RCU implementations:
RCU实现有两种类型:
1) Non-preemptible RCU implementation
2) Preemptible RCU implementation
When synchronize_rcu() is invoked on one CPU while other CPUs are within RCU read-side critical sections, then the synchronize_rcu() is guaranteed to block until after all the other CPUs exit their critical sections. 当在一个CPU上调用synchronize_rcu()而其他CPU在RCU读取端关键部分内时,则同步_rcu()保证阻塞,直到所有其他CPU退出其关键部分。 Similarly, if call_rcu() is invoked on one CPU while other CPUs are within RCU read-side critical sections, invocation of the corresponding RCU callback is deferred until after the all the other CPUs exit their critical sections.
类似地,如果在一个CPU上调用call_rcu()而其他CPU在RCU读取端关键部分内,则调用相应的RCU回调,直到所有其他CPU退出其关键部分。
In non-preemptible RCU implementations it is illegal to block while in an RCU read-side critical section. 在不可抢占的RCU实现中,在RCU读取端关键部分中阻塞是非法的。 In preemptible RCU implementations (PREEMPT_RCU) in CONFIG_PREEMPT kernel builds, RCU read-side critical sections may be preempted, but explicit blocking is illegal.
在CONFIG_PREEMPT内核构建中的可抢占RCU实现(PREEMPT_RCU)中,RCU读取端关键部分可能被抢占,但显式阻塞是非法的。 Finally, in preemptible RCU implementations in real-time (with -rt patchset) kernel builds, RCU read-side critical sections may be preempted and they may also block, but only when acquiring spinlocks that are subject to priority inheritance.
最后,在实时(带有-rt补丁集)内核构建的可抢占RCU实现中,RCU读取端关键部分可能被抢占并且它们也可能阻塞,但仅在获取受优先级继承影响的自旋锁时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.