网站大量收购独家精品文档,联系QQ:2885784924

对linux rcu机制的理解.doc

  1. 1、本文档共6页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
对linux rcu机制的理解

对linux rcu机制的理解 RCU( Read-copy update)锁机制是kernel2.6的重大进步,使用rcu可以获得比使用rwlock更高的性能,而且代码简单,不易死锁。 Linux 文档如下描述: 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原理的模型。 假定cpu处理报文的过程是原子的,这样可以认为处理完一个报文就经过了一个quiescent state,RCU引用的过时数据就可以释放了。接收报文开始进入一个新的周期,当发送报文后,标记一个周期的结束。假设有8个cpu,轮流处理报文,而报文处理依赖的信息存储在共享内存中。 那末,现在的问题是:请用rcu机制实现共享内存的释放。假设所有的cpu处理一个报文结束,就代表一个grace period (因为只有处理报文时才会使用共享内存),即每个cpu都经过了一个quiscent state . 那么现在就有三个问题: 如何确定所有的cpu都经过了一个quiscent state? 在rcu处理时,如何保证别的cpu不对要释放的数据操作? 在rcu处理后,如何开启和判断下一个rcu周期? 带着这三个问题,我们可以看一下linux是如何实现rcu机制的。 以下的分析是基于linux-2.6.27代码: Rcu有两个重要的数据结构: /* Global control variables for rcupdate callback mechanism. */ struct rcu_ctrlblk { long cur; /* Current batch number. */ long completed; /* Number of the last completed batch */ int next_pending; /* Is the next batch already waiting? */ int signaled; spinlock_t lock ____cacheline_internodealigned_in_smp; cpumask_t cpumask; /* CPUs that need to switch in order */ /* for current batch to proceed. */ } ____cacheline_internodealigned_in_smp; 上述结构是rcu全局控制结构 struct rcu_data { /* 1) quiescent state handling : */ long quiescbatch; /* Batch # for grace period */ int passed_quiesc; /* User-mode/idle loop etc. */ int qs_pending; /* core waits for quiesc state */ /* 2) batch handling */ long batch; /* Batch # for current RCU batch */ struct rcu_head *nxtlist; struct rcu_head **nxttail; long qlen; /* # of queued callbacks */ struct rcu_head *curlist; struct rcu_head **curtail; struct rcu_head *donelist; struct rcu_

文档评论(0)

xcs88858 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档