如何保护RCU读卡器部分免于抢占?(How RCU reader section is protected from preemption?)

(来自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();

RCU更新操作将执行synchronize_rcu()以断言每个CPU切换上下文,因此每个RCU读取器已完成它的工作。 但RCU必须依靠读者不被抢先一步。 事实上,LWN接下来说:

虽然这种简单的方法适用于在RCU读取端关键部分禁用抢占的内核,换句话说,对于非CONFIG_PREEMPT和CONFIG_PREEMPT内核,它不适用于CONFIG_PREEMPT_RT实时(-rt)内核。

我理解对于非CONFIG_PREEMPT内核禁用抢占,但为什么CONFIG_PREEMPT内核也可以呢?

(From an article on 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. But RCU must rely on reader not being preempted. And indeed, LWN says next:

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.

I understand preemption is disabled for non-CONFIG_PREEMPT kernels, but why is it OK for CONFIG_PREEMPT kernels too?

最满意答案

在CONFIG_PREEMPT内核上没问题,因为在任务被抢占之前需要注意完成rcu read critical部分。 调度程序检查当前任务是否在rcu读取临界区中,如果是,则增强其优先级以使其完成临界区。 有关详细信息,请参阅此文章: http : //lwn.net/Articles/220677/

It is OK on CONFIG_PREEMPT kernels since care is taken to finish the rcu read critical section before the task is preempted. 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. For more details see this article: http://lwn.net/Articles/220677/

更多推荐