该记录着重介绍下:2.6.34版本中非抢占式RCU的基本概念。

RCU保护的是指针,因为指针的赋值可以使用原子操作完成;

在非抢占式RCU中:

对于读者,RCU仅需要抢占失效,因此获得读锁和释放读锁分别定义为:
对于非抢占式RCU,在操作读取数据的过程中不允许进程切换,否则因为写者需要等待读者完成,写者进程也会一直被阻塞。
#define rcu_read_lock() preempt_disable()
#define rcu_read_unlock() preeempt_enable() 变种:
#define rcu_read_lock_bh() local_bh_disable()
#define rcut_read_unlock_bh() local_bh_enable()
每个变种只在修改是通过call_rcu_bh进行的情况下使用,因为call_rcu_bh将把softirq的执行完毕也认为是一个quiescent state,因此如果修改是通过call_rcu_bh进行的,在进程上下文的读段临界区必须使用这一变种)。 rcu_dereference(p)相当于p
rc_assign_pointer(p, v)相当于p = v; 注意,关于写者:
写者在访问被RCU保护的共享数据时不需要和读者竞争任何锁,只有在有多于一个写者的情况下需要获得某种锁以与其它写者同步。
写者修改数据前先拷贝一个被修改元素的副本,然后在副本上进行修改,修改完毕后将向垃圾回收器注册一个回调函数以便在适当的时机执行真正的修改操作。                                                                                         

如何判断当前的一个读者已经完成了相应的读操作?

grace period 与 quiescent state的定义:

grace period(宽限期):
The time waits for any currently executing RCU read-side critical sections to complete, and the length of this wait is known as a "grace period". quiescent state(静默状态):
CPU发生了上下文切换称为经历一次quiescent state grace period就是所有CPU都经历一次quiescent state所需要的等待时间。因为对于非抢占式RCU机制而言,当所有CPU都经过quiescent state就意味着所有读者完成了对共享临界区的访问。 垃圾收集器在grace period之后调用写者注册的回调函数来完成真正的数据释放、唤醒线程等操作。

下图,引述自:http://blog.csdn.net/junguo/article/details/8244530

对图中的remove(删除)与reclamation(销毁),RCU作者本人做了解释:

The basic idea behind RCU is to split updates into "removal" and "reclamation" phases. The removal phase removes references to data items within a data structure (possibly by replacing them with references to new versions of these data items), and can run concurrently with readers. The reason that it is safe to run the removal phase concurrently with readers is the semantics of modern CPUs guarantee that readers will see either the old or the new version of the data structure rather than a partially updated reference. The reclamation phase does the work of reclaiming (e.g., freeing) the data items removed from the data structure during the removal phase. Because reclaiming data items can disrupt any readers concurrently referencing those data items, the reclamation phase must not start until readers no longer hold references to those data items.

Splitting the update into removal and reclamation phases permits the updater to perform the removal phase immediately, and to defer the reclamation phase until all readers active during the removal phase have completed, either by blocking until they finish or by registering a callback that is invoked after they finish. Only readers that are active during the removal phase need be considered, because any reader starting after the removal phase will be unable to gain a reference to the removed data items, and therefore cannot be disrupted by the reclamation phase.

So the typical RCU update sequence goes something like the following:

a、Remove pointers to a data structure, so that subsequent readers cannot gain a reference to it.
b、Wait for all previous readers to complete their RCU read-side critical sections.
c、At this point, there cannot be any readers who hold references to the data structure, so it now may safely be reclaimed (e.g., kfree()d).

非抢占式RCU的优缺点,以及引入RCU机制给优先级带来的问题:

引述自:http://lwn.net/Articles/263130/

Advantages of RCU include performance, deadlock immunity, and realtime latency. 
There are, of course, limitations to RCU, including the fact that readers and updaters run concurrently, that low-priority RCU readers can block high-priority threads waiting for a grace period to elapse, and that grace-period latencies can extend for many milliseconds.

RCU与seqlock的不同:

Although seqlock readers can run concurrently with seqlock writers, whenever this happens, the read_seqretry() primitive will force the reader to retry. This means that any work done by a seqlock reader running concurrently with a seqlock updater will be discarded and redone. So seqlock readers can run concurrently with updaters, but they cannot actually get any work done in this case. 

RCU类似于“强引用计数机制”

Because grace periods are not allowed to complete while there is an RCU read-side critical section in progress, the RCU read-side primitives may be used as a restricted reference-counting mechanism.
The effect is that if any RCU-protected data element is accessed within an RCU read-side critical section, that data element is guaranteed to remain in existence for the duration of that RCU read-side critical section.

RCU机制不是简单的等待事件完成

One of RCU's great strengths is that it allows you to wait for each of thousands of different things to finish without having to explicitly track each and every one of them, and without having to worry about the performance degradation, scalability limitations, complex deadlock scenarios, and memory-leak hazards that are inherent in schemes that use explicit tracking.

非抢占式RCU中的一些概念的更多相关文章

  1. 非抢占式RCU中关于grace period的处理(限于方法)

    参考自:http://blog.csdn.net/junguo/article/details/8244530             Documentation/RCU/* TREE_RCU将所有的 ...

  2. 非抢占式RCU实现(一)

    关于RCU的实现,考虑如下情形: 1.非抢占式RCU 2.限于嵌入式系统4核.每核单线程 3.RCU_FANOUT = 32 此时,RCU_TREE退化为单节点,如下,针对rcu_sched_stat ...

  3. 抢占式内核与非抢占式内核中的自旋锁(spinlock)的差别

    一.概括 (1)自旋锁适用于SMP系统,UP系统用spinlock是作死. (2)保护模式下禁止内核抢占的方法:1.运行终端服务例程时2.运行软中断和tasklet时3.设置本地CPU计数器preem ...

  4. 非抢占式RCU实现(二),解释:为什么 RCU_NEXT_SIZE 宏值是4?

    参考:2.6.34 一个很奇怪的问题. 没有查找到为什么 RCU_NEXT_SIZE的值为4的原因(包括Documentation),主要是在rcu_state中定义了一个四级的list,感到很有意思 ...

  5. chapter9_4 非抢占式的多线程

    协同程序与常规的多线程不同之处:协同程序是非抢占式的. 当一个协同程序运行时,是无法从外部停止它的.只有当协同程序显式地调用yield时,它才会停止. 当不存在抢先时,编程会变得简单很多,无须为同步的 ...

  6. 一种基于C51单片机的非抢占式的操作系统架构

    摘 要:从Keil C51的内存空间管理方式入手,着重讨论实时操作系统在任务调度时的重入问题,分析一些解决重入的基本方式与方法:分析实时操作系统任务调度的占先性,提出非占先的任务调度是能更适合于Kei ...

  7. keepalived的抢占与非抢占模式

    目录 一:keepalived的抢占与非抢占模式 1.抢占模式 2.非抢占模式 二:接下来分4种情况说明 三:以上3种,只要级别高就会获取master,与state状态是无关的 一:keepalive ...

  8. socket网络编程中的同步,异步,阻塞式,非阻塞式,有何联系与区别?

    一.举个打电话的例子: 阻塞   block   是指,你拨通某人的电话,但是此人不在,于是你拿着电话等他回来,其间不能再用电话.同步大概和阻塞差不多. 非阻塞   nonblock   是指,你拨通 ...

  9. MVC的验证(模型注解和非侵入式脚本的结合使用) .Net中初探Redis .net通过代码发送邮件 Log4net (Log for .net) 使用GDI技术创建ASP.NET验证码 Razor模板引擎 (RazorEngine) .Net程序员应该掌握的正则表达式

    MVC的验证(模型注解和非侵入式脚本的结合使用)   @HtmlHrlper方式创建的标签,会自动生成一些属性,其中一些属性就是关于验证 如图示例: 模型注解 通过模型注解后,MVC的验证,包括前台客 ...

随机推荐

  1. ajaxfileupload.js ajax上传文件(含application/json)

    jQuery.extend({ createUploadIframe: function(id, uri) { //create frame var frameId = 'jUploadFrame' ...

  2. virtualbox问题收集

    The VM session was closed before any attempt to power it on. 返回 代码:E_FAIL (0x80004005)组件:SessionMach ...

  3. java二维码的生成与解析代码

    二维码,是一种采用黑白相间的平面几何图形通过相应的编码算法来记录文字.图片.网址等信息的条码图片.如下图 二维码的特点: 1.  高密度编码,信息容量大 可容纳多达1850个大写字母或2710个数字或 ...

  4. UltraEdit 常用快捷方式

    Ctrl+N :创建一个新文件 Ctrl+O :打开文件 Ctrl+Q :快速打开文件 Ctrl+F4 :关闭文件 Ctrl+S :保存活动文件 F12 :另存为 Ctrl+P :打印当前活动文件 C ...

  5. 学习MongoDB(二) Replica Set集群配置

    1.官方网址:https://docs.mongodb.org/manual/tutorial/deploy-replica-set-for-testing/ 2.Replica Set介绍: htt ...

  6. Java通过JDBC进行简单的增删改查(以MySQL为例)

    Java通过JDBC进行简单的增删改查(以MySQL为例) 目录: 前言:什么是JDBC 一.准备工作(一):MySQL安装配置和基础学习 二.准备工作(二):下载数据库对应的jar包并导入 三.JD ...

  7. winform上控件的拖拽小结

    这里罗列出几个相关的事件和属性,具体的实现介绍已有非常优秀的文章了,文章末尾我将会给出,大家可以去参考. 属性: AllowDrop: 目标控件必须设定为true,才能接受拖拽来的东西. 事件: It ...

  8. 【进阶修炼】——改善C#程序质量(7)

    113,声明变量时考虑最大值. Ushort的最大值是65535,用于不同的用途这个变量可能发生溢出,所以设计时应充分了解每个变量的最大值. 114,MD5不再安全. MD5多用于信息完整性的校验.R ...

  9. iframe中跨域页面访问parent的方法

    背景 如上图所示,系统www.a.com/index.html页面中嵌入一个iframe,iframe中访问不同域的www.b.com/index.html 然后b中有个按钮“保存”,想调用父页面a. ...

  10. es cat http://localhosts:9002/_cat/nodes?v

    http://localhosts:9002/_cat/nodes?v&h=http,version,jdk,disk.total,disk.used,disk.avail,disk.used ...