[内核文档]RCU相关概念

RCU Concepts

 

 

The basic idea behind RCU (read-copyupdate) is to split destructive operations into two parts, one that preventsanyone from seeing the data item being destroyed, and one that actually carriesout the destruction.

RCU最基本的思想是将破坏性操作分为2部分:其一用以阻止其它人看到被消耗的数据,令一部分则真正用以实现消耗操作。

A "grace period" must elapsebetween the two parts, and this grace period must be long enough that anyreaders accessing the item being deleted have since dropped theirreferences.  For example, anRCU-protected deletion from a linked list would first remove the item from thelist, wait for a grace period to elapse, then free the element.  See the listRCU.txt file for more informationon using RCU with linked lists.

[grace period: 宽限期]

Grace period是指两部分操作之间的时间。在graceperiod中,访问待删除数据项的所有读者都应解除它们对该数据项的应用。例如,一个使用RCU保护的链表删除操作首先将该数据项从链表中移除,在一个grace period后,再释放此数据项。关于在链表中使用RCU的方法,可以参见文件listRCU.txt.

 

Frequently Asked Questions

FAQ

o       Whywould anyone want to use RCU?

 

         Theadvantage of RCU's two-part approach is that RCU readers need not acquire any locks, perform any atomicinstructions, write to shared memory, or (on CPUs other than Alpha) execute anymemory barriers. The fact that these operations are quite expensive on modernCPUs is what gives RCU its performance advantages        in read-mostly situations. The fact that RCU readers need not  acquire locks can also greatly simplifydeadlock-avoidance code.

         为什么要使用RCU?

         RCU两步操作的特点是,在使用RCU时,读者不需要申请锁,无需原子操作,无需写共享内存,无需执行任何内存屏障(除了Alpha处理器)。在现代处理器上,这些操作的开销是很大的,因而RCU仅仅适用于读操作非常多的情况。由于读者不需要申请锁,因而可以避免死锁。

 

o       Howcan the updater tell when a grace period has completed if the RCU readers giveno indication when they are done?

         如果RCU的读者不知会它们已执行结束,那么更新者如何获知grace period已经结束。

        Justas with spinlocks, RCU readers are not permitted to block, switch to user-modeexecution, or enter the idle loop. Therefore, as soon as a CPU is seen passingthrough any of these three states, we know that that CPU has exited anyprevious RCU read-side critical sections. So, if we remove an item from a linked list, and then wait until allCPUs have switched context, executed in user mode, or executed in the idleloop, we can safely free up that item.

         类似于spinlock,RCU的读者不能阻塞,不能切换到用户空间,也不能进入空循环。因此,一旦CPU进入这三种状态中的任何一个,我们就可以断定CPU已经从之前的RCU读者所在的关键区中退出来了。因此,如果我们要从链表中移除一个数据项,就需要等到所有的CPU都进入了上述3个状态中的一个,然后便可以安全的释放这个数据项了。

         Preemptiblevariants of RCU (CONFIG_PREEMPT_RCU) get the same effect, but require that thereaders manipulate CPU-local         counters.These counters allow limited types of blocking within RCU read-side criticalsections. SRCU also uses CPU-local counters, and permits general blockingwithin RCU read-side critical sections. These two variants of RCU detect graceperiods by sampling these counters.

         RCU的可抢占变种(CONFIG_PREEMPT_RCU)也有类似的情况,但是,它要求读者只能操作本地CPU的计数器。这些计数器允许在RCU读者的临界区中进行特定类型的阻塞。SRCU利用本地CPU的计数器,允许RCU读者所在的临界区中进行一般的阻塞。这两种RCU的变种通过对这些计数器进行采样来获得grace period.

 

o       IfI am running on a uniprocessor kernel, which can only do one    thing at a time, why should I wait for agrace period?

         如果我们使用单处理器的内核,就是说一个时刻只能执行一件事,那么我们为什么还要等待grace period?

         Seethe UP.txt file in this directory.

         请参看本目录下的UP.txt文件。

o       Howcan I see where RCU is currently used in the Linux kernel?

         我们如何查看linux内核中的哪些地方使用了RCU?

         Searchfor "rcu_read_lock", "rcu_read_unlock","call_rcu", "rcu_read_lock_bh","rcu_read_unlock_bh", "call_rcu_bh",         "srcu_read_lock", "srcu_read_unlock","synchronize_rcu", "synchronize_net","synchronize_srcu", and the other RCU         primitives.

Or grab one ofthe cscope databases from:

http://www.rdrop.com/users/paulmck/RCU/linuxusage/rculocktab.html

         请搜索:"rcu_read_lock","rcu_read_unlock", "call_rcu",

         "rcu_read_lock_bh","rcu_read_unlock_bh", "call_rcu_bh",

         "srcu_read_lock","srcu_read_unlock", "synchronize_rcu",

         "synchronize_net","synchronize_srcu", 以及其它的RCU原语。

         或者从下面的地址上直接下载一个cscope数据库:

         http://www.rdrop.com/users/paulmck/RCU/linuxusage/rculocktab.html

 

o       Whatguidelines should I follow when writing code that uses RCU?

         当我们使用RCU编写代码时,应遵循什么规则?

         Seethe checklist.txt file in this directory.

         请参看本目录下的checklist.txt文件。

 

o       Whythe name "RCU"?

         为什么命名为“RCU”?

         "RCU"stands for "read-copy update". The file listRCU.txt has moreinformation on where this name came from, search for         "read-copy update" to find it.

       “RCU”代表“read-copyupdate”。文件listRCU.txt中更加详细地说明了此名字的出处,在该文件中搜索“read-copy update”,便可以找到。

 

o       Ihear that RCU is patented?  What is withthat?

         据说RCU被申请了专利保护,具体情况是什么?

 

         Yes,it is. There are several known patents related to RCU, search for the string"Patent" in RTFP.txt to find them. Of these, one was allowed to lapseby the assignee, and the others have been contributed to the Linux kernel underGPL.

         是的。现在已经有一些和RCU相关的专利,在文件RTFP.txt中搜索字符串“Patent”就能找到它们。其中一个委托给了代理人,其它的都在GPL协议下贡献给了Linux内核。

 

o       Ihear that RCU needs work in order to support realtime kernels?

         据说RCU还需要一些改进以支持实时内核?

 

         Thiswork is largely completed. Realtime-friendly RCU can be enabled via theCONFIG_PREEMPT_RCU kernel configuration parameter. However, work is in progressfor enabling priority boosting of   preemptedRCU read-side critical sections. This is needed if you have CPU-bound realtimethreads.

         大部分工作已经完成了。打开内核选项CONFIG_PREEMPT_RCU便可以使用实时RCU了。目前,针对可抢占RCU读者关键区的优先级增强功能(priority boosting)正在进行中。处理CPU受限的实时线程时,需要使用此项功能。

 

o       Wherecan I find more information on RCU?

         在哪里可以找到有关RCU的更多的信息。

 

         Seethe RTFP.txt file in this directory.

         Orpoint your browser at http://www.rdrop.com/users/paulmck/RCU/.

         请参见此目录下的RTFP.txt文件。或者在浏览器中打开:

         http://www.rdrop.com/users/paulmck/RCU/

 

o       Whatare all these files in this directory?

         本目录下的文件都描述了什么?

 

         NMI-RCU.txt

 

                   Describeshow to use RCU to implement dynamic NMI handlers, which can be revectored onthe fly, without rebooting.

                   描述如何使用RCU实现动态的NMI处理函数。此类函数可以在系统运行时重定向,而无需重启系统。

 

         RTFP.txt

 

                   Listof RCU-related publications and web sites.

                   列出了所有和RCU相关的出版物及网站。

 

         UP.txt

 

                   Discussionof RCU usage in UP kernels.

                   描述了单处理器内核中RCU的使用方法。

 

         arrayRCU.txt

 

                   Describeshow to use RCU to protect arrays, with         resizeablearrays whose elements reference other data structures being of the mostinterest.

                   描述了如何使用RCU保护数组,这些数组的大小是可调的,数组的元素则引用了其它的数据结构。

 

         checklist.txt

 

                   Liststhings to check for when inspecting code that uses RCU.

                   列出了使用RCU探测代码时,应该检查的内容。

 

         listRCU.txt

 

                   Describeshow to use RCU to protect linked lists.  Thisis the simplest and most common use of RCU in the Linux kernel.

                   描述了如何使用RCU保护链表。这是Linux内核中,最简单也是最常用的RCU。

 

         rcu.txt

 

                   Youare reading it!

                   正是本文档。

 

         rcuref.txt

 

                   Describeshow to combine use of reference counts with RCU.

                   描述了如何绑定引用计数与RCU。

 

         whatisRCU.txt

 

                   Overviewof how the RCU implementation works. Along    the way, presents aconceptual view of RCU.

                   概述了RCU的实现方法。随后,描述了RCU的一些概念。

 

©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值