该记录着重介绍下: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. Winsock解析

    一.基本知识 1.Winsock,一种标准API,一种网络编程接口,用于两个或多个应用程序(或进程)之间通过网络进行数据通信.具有两个版本: Winsock 1: Windows CE平台支持. 头文 ...

  2. gdb基本命令(非常详细)

    gdb基本命令 本文介绍使用gdb调试程序的常用命令. 主要内容: [简介] [举例] [其他] [简介] ============= GDB是GNU开源组织发布的一个强大的UNIX下的程序调试工具. ...

  3. JMX超详细解读<转>

    一.JMX的定义 JMX(Java Management Extensions)是一个为应用程序植入管理功能的框架.JMX是一套标准的代理和服务,实际上,用户可以在任何Java应用程序中使用这些代理和 ...

  4. Hibernate 查询说明

    1.Criteria setFetchSize实际上与分页操作并没有关系,它的作用是在查询中进行分批数据返回,其中的值就是每次分批查询的记录数,主要是为了提高查询性能的. 举个例子来说:如果你这次查询 ...

  5. shell+钉钉机器人完成java程序中断后自启动和实时监控

    java实时程序在运行过程中偶尔出现异常信息中断的情况,通过shell脚本即可完成自启动. 以下为监控一个实时的java程序的shell脚本. 通过每10秒检查一次java程序的进程,来判断程序是否处 ...

  6. Redis键

    Redis的keys命令用于管理键.使用Redis的keys命令语法如下所示: 语法 redis 127.0.0.1:6379> COMMAND KEY_NAME 例子 redis 127.0. ...

  7. 【LINUX】——FreeBSD中的一些常规配置

    一:在为终端的目录添加颜色: 在 ~/.cshrc 文件中添加以下两行: setenv CLICOLOR 1 setenv LSCOLORS Gxfxaxdxcxegedabagacad CLICOL ...

  8. 简介vsftpd及搭建配置 关闭selinux 不能创建文件

    简介vsftpd及搭建配置一.简介 FTP(文件传输协议)全称是:Very Secure FTP Server. Vsftpd是linux类操作系统上运行的ftp服务器软件. vsftp提供三种登陆方 ...

  9. 【html5】使用 html5 的十大原因

    你难道还没有考虑使用 html5? 当然我猜想你可能有自己的原因:它现在还没有被广泛的支持,在 ie 中不好使,或者你就是喜欢写比较严格的 xhtml 代码.html5 是 web 开发世界的一次重大 ...

  10. 【css】css 背景色渐变兼容写法

    最近在项目中,有很多地方都用到了线性渐变,比如:表单提交按钮的背景,数据展示的标题背景等等,按照以前的做法是切 1px 图片然后 repeat-x.下面我将介绍如何用 css 来完成该效果. css3 ...