免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2066 | 回复: 3

[CPU及多核] 关于非SMP时的ptep_get_and_clear()的疑问 [复制链接]

论坛徽章:
4
酉鸡
日期:2014-03-21 23:19:50狮子座
日期:2014-08-01 22:11:40酉鸡
日期:2015-01-10 21:31:442015年辞旧岁徽章
日期:2015-03-03 16:54:15
发表于 2013-01-23 09:39 |显示全部楼层
10可用积分
from 3.6.10
我一直以为ptep_get_and_clear()会返回清除低12bit之后的pte,但是为何某种情况下不是这样的呢?

  1. #ifdef CONFIG_SMP
  2. static inline pte_t native_ptep_get_and_clear(pte_t *xp)
  3. {
  4.         return __pte(xchg(&xp->pte_low, 0));
  5. }
  6. #else
  7. #define native_ptep_get_and_clear(xp) native_local_ptep_get_and_clear(xp)<---here
  8. #endif
复制代码
  1. /* local pte updates need not use xchg for locking */
  2. static inline pte_t native_local_ptep_get_and_clear(pte_t *ptep)
  3. {
  4.         pte_t res = *ptep;

  5.         /* Pure native function needs no input for mm, addr */
  6.         native_pte_clear(NULL, 0, ptep);
  7.         return res;<---------返回的是未清除低12bit的原始pte???
  8. }
复制代码
UNP时native_local_ptep_get_and_clear()没有返回清低12bit之后的pte,貌似做了其它处理,何意?求助!

最佳答案

查看完整内容

回复 1# chishanmingshen 个人理解:ptep_get_and_clear()会获取原来的页表项值并清除,返回的应该是原始的页表项值下面是xchg在x86 32下的实现:

论坛徽章:
0
发表于 2013-01-23 09:39 |显示全部楼层
回复 1# chishanmingshen
个人理解:
ptep_get_and_clear()会获取原来的页表项值并清除,返回的应该是原始的页表项值
  1. #ifdef CONFIG_SMP
  2. static inline pte_t native_ptep_get_and_clear(pte_t *xp)
  3. {
  4.         return __pte(xchg(&xp->pte_low, 0)); //这里返回的也是原值,xchg的动作是设置新值并返回旧值
  5. }
  6. #else
  7. #define native_ptep_get_and_clear(xp) native_local_ptep_get_and_clear(xp)<---here
  8. #endif
复制代码
下面是xchg在x86 32下的实现:

  1. #define __xchg(x, ptr, size)                                                \
  2. ({                                                                        \
  3.         __typeof(*(ptr)) __x = (x);        /*这里先传入新值*/                        \
  4.         switch (size) {                                                        \
  5.         case 1:                                                                \
  6.                 asm volatile("xchgb %b0,%1"                                \
  7.                              : "=q" (__x), "+m" (*__xg(ptr))                \
  8.                              : "0" (__x)                                \
  9.                              : "memory");          /* 这里xchgb指令会把__x和*ptr里的内容交换 */                        \
  10.                 break;                                                        \
  11.         case 2:                                                                \
  12.                 asm volatile("xchgw %w0,%1"                                \
  13.                              : "=r" (__x), "+m" (*__xg(ptr))                \
  14.                              : "0" (__x)                                \
  15.                              : "memory");        /* 这里xchg2指令会把__x和*ptr里的内容交换 */                        \
  16.                 break;                                                        \
  17.         case 4:                                                                \
  18.                 asm volatile("xchgl %0,%1"                                \
  19.                              : "=r" (__x), "+m" (*__xg(ptr))                \
  20.                              : "0" (__x)                                \
  21.                              : "memory");        /* 这里xchgl指令会把__x和*ptr里的内容交换 */                        \
  22.                 break;                                                        \
  23.         default:                                                        \
  24.                 __xchg_wrong_size();                                        \
  25.         }                                                                \
  26.         __x;         /*这里返回旧值*/                                                        \
  27. })
复制代码

论坛徽章:
4
酉鸡
日期:2014-03-21 23:19:50狮子座
日期:2014-08-01 22:11:40酉鸡
日期:2015-01-10 21:31:442015年辞旧岁徽章
日期:2015-03-03 16:54:15
发表于 2013-02-03 16:27 来自手机 |显示全部楼层
求解!谢谢

论坛徽章:
4
酉鸡
日期:2014-03-21 23:19:50狮子座
日期:2014-08-01 22:11:40酉鸡
日期:2015-01-10 21:31:442015年辞旧岁徽章
日期:2015-03-03 16:54:15
发表于 2013-04-13 20:12 |显示全部楼层
回复 2# junnyg

哦,都是返回原值,呵呵。
   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP