




已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
对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 subsequentreaders cannot gain a reference to it.b.Wait for all previous readers to complete their RCU read-sidecritical sections.c.At this point, there cannot be any readers who hold referencesto 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 . 那么现在就有三个问题:1 如何确定所有的cpu都经过了一个quiscent state?2 在rcu处理时,如何保证别的cpu不对要释放的数据操作?3 在rcu处理后,如何开启和判断下一个rcu周期?带着这三个问题,我们可以看一下linux是如何实现rcu机制的。以下的分析是基于linux-2.6.27代码:Rcu有两个重要的数据结构:/* Global control variables for rcupdate callback mechanism. */struct rcu_ctrlblk longcur;/* Current batch number. */longcompleted;/* Number of the last completed batch */intnext_pending;/* Is the next batch already waiting? */intsignaled;spinlock_tlock_cacheline_internodealigned_in_smp;cpumask_tcpumask; /* CPUs that need to switch in order */ /* for current batch to proceed. */ _cacheline_internodealigned_in_smp;上述结构是rcu全局控制结构struct rcu_data /* 1) quiescent state handling : */longquiescbatch; /* Batch # for grace period */intpassed_quiesc; /* User-mode/idle loop etc. */intqs_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_head *donetail;longblimit; /* Upper limit on a processed batch */int cpu;struct rcu_head barrier;上述结构是每个cpu用的rcu数据结构。DECLARE_PER_CPU(struct rcu_data, rcu_data);static struct rcu_ctrlblk rcu_ctrlblk = .cur = -300,.completed = -300,.lock = _SPIN_LOCK_UNLOCKED(&rcu_ctrlblk.lock),.cpumask = CPU_MASK_NONE,;Linux在rcu代码中声明了两个全局变量,一个是rcu_data,每个cpu一个;一个是rcu_ctrlblk,全局一个。Linux rcu 处理流程图:Linux rcu 状态转换图一:Init-start new period,注意rdp,rcp的数据变化Linux rcu 状态转换图二最后引用rcu代码中的一段注释作为总结/* * Grace period handling: * The grace period handling consists out of two steps: * - A new grace period is started. * This is done by rcu_start_batch. The start is not broadcasted to * all cpus, they must pick this up by comparing rcp-cur with * rdp-quiescbatch. All cpus are recorded in the * rcu_ctrlblk.cpumask bitmap. * - All cpus must go through a quiescent state. * Since the start of the grace period is not broadcasted, at least two * calls to rcu_check_quiescent_state are required: * The first call just notices that a new grace period is running. The * following calls check if there was a quiescent state since the beginning * of the grace period. If so, it updates rcu_ctrlblk.cpumask. If * the
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 纪委办案安全知识培训课件
- 七上上海期中数学试卷
- 2024年广州市天河区棠福学校招聘教师笔试真题
- 七下苏州名校数学试卷
- 青花瓷数学试卷
- 七年级拔高数学试卷
- 期末奖品高中数学试卷
- 2024年武汉市江岸区招聘聘用教师考试真题
- 2025年秋季学期大中小班教研组工作计划
- 2024年内蒙古呼和浩特玉泉区招聘公益性岗位人员笔试真题
- 【真题】2023年淮安市中考道德与法治试卷(含答案解析)
- 中国慢性肾脏病患者高血压管理指南(2023年版)解读
- TCALC 003-2023 手术室患者人文关怀管理规范
- 微创外科进展课件
- 学校幼儿园食品安全培训课件
- 水利工程中常见机电设备的基本知识
- 居家养老服务创新创业项目计划书
- 初中英语2023年中考专题训练阅读理解-记叙文篇
- 家具行业常用中英文对照
- 英语四六级词汇汇总(带音标+免费下载)
- 插板机安全操作规程
评论
0/150
提交评论