免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1905 | 回复: 3
打印 上一主题 下一主题

求教神们一个RCU的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-16 20:27 |只看该作者 |倒序浏览
读者在访问被RCU保护的共享数据期间不能被阻塞,这是RCU机制得以实现的一个基本前提,
也就说当读者在引用被RCU保护的共享数据期间,读者所在的CPU不能发生上下文切换
“读者所在的CPU不能发生上下文切换”请问这个是怎么保证的?

论坛徽章:
6
金牛座
日期:2013-10-08 10:19:10技术图书徽章
日期:2013-10-14 16:24:09CU十二周年纪念徽章
日期:2013-10-24 15:41:34狮子座
日期:2013-11-24 19:26:19未羊
日期:2014-01-23 15:50:002015年亚洲杯之阿联酋
日期:2015-05-09 14:36:15
2 [报告]
发表于 2011-12-16 22:55 |只看该作者
回复 1# kitiz
这个需要你的代码显示的实现禁止CPU切换的功能。比如rcu_read_lock()函数。

论坛徽章:
0
3 [报告]
发表于 2011-12-17 09:43 |只看该作者
回复  kitiz
这个需要你的代码显示的实现禁止CPU切换的功能。比如rcu_read_lock()函数。
瀚海书香 发表于 2011-12-16 22:55
  1. void __rcu_read_lock(void)
  2. {
  3.         int idx;
  4.         struct task_struct *t = current;
  5.         int nesting;

  6.         nesting = ACCESS_ONCE(t->rcu_read_lock_nesting);
  7.         if (nesting != 0) {

  8.                 /* An earlier rcu_read_lock() covers us, just count it. */

  9.                 t->rcu_read_lock_nesting = nesting + 1;

  10.         } else {
  11.                 unsigned long flags;

  12.                 /*
  13.                  * We disable interrupts for the following reasons:
  14.                  * - If we get scheduling clock interrupt here, and we
  15.                  *   end up acking the counter flip, it's like a promise
  16.                  *   that we will never increment the old counter again.
  17.                  *   Thus we will break that promise if that
  18.                  *   scheduling clock interrupt happens between the time
  19.                  *   we pick the .completed field and the time that we
  20.                  *   increment our counter.
  21.                  *
  22.                  * - We don't want to be preempted out here.
  23.                  *
  24.                  * NMIs can still occur, of course, and might themselves
  25.                  * contain rcu_read_lock().
  26.                  */

  27.                 local_irq_save(flags);

  28.                 /*
  29.                  * Outermost nesting of rcu_read_lock(), so increment
  30.                  * the current counter for the current CPU.  Use volatile
  31.                  * casts to prevent the compiler from reordering.
  32.                  */

  33.                 idx = ACCESS_ONCE(rcu_ctrlblk.completed) & 0x1;
  34.                 ACCESS_ONCE(RCU_DATA_ME()->rcu_flipctr[idx])++;

  35.                 /*
  36.                  * Now that the per-CPU counter has been incremented, we
  37.                  * are protected from races with rcu_read_lock() invoked
  38.                  * from NMI handlers on this CPU.  We can therefore safely
  39.                  * increment the nesting counter, relieving further NMIs
  40.                  * of the need to increment the per-CPU counter.
  41.                  */

  42.                 ACCESS_ONCE(t->rcu_read_lock_nesting) = nesting + 1;

  43.                 /*
  44.                  * Now that we have preventing any NMIs from storing
  45.                  * to the ->rcu_flipctr_idx, we can safely use it to
  46.                  * remember which counter to decrement in the matching
  47.                  * rcu_read_unlock().
  48.                  */

  49.                 ACCESS_ONCE(t->rcu_flipctr_idx) = idx;
  50.                 local_irq_restore(flags);
  51.         }
  52. }
复制代码

论坛徽章:
0
4 [报告]
发表于 2011-12-17 09:45 |只看该作者
有好多个__rcu_read_lock实现啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP