Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15190
  • 博文数量: 3
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 40
  • 用 户 组: 普通用户
  • 注册时间: 2015-08-02 16:54
文章分类

全部博文(3)

文章存档

2015年(3)

我的朋友

分类: LINUX

2015-08-02 20:39:54

  内核中有许多地方需要获取当前活动的cpu id,这个是有smp_processor_id完成的,但是其具体的实现是和架构相关的。
 这里以mips机构为列进行说明。
 

点击(此处)折叠或打开

  1. # define smp_processor_id() raw_smp_processor_id()

  2. #define raw_smp_processor_id() (current_thread_info()->cpu)

  3. /* How to get the thread information struct from C. */
  4. static inline struct thread_info *current_thread_info(void)
  5. {
  6.     register struct thread_info *__current_thread_info __asm__("$28");

  7.     return __current_thread_info;
  8. }
   可以看出cpu id实际上是通过thread_info结构中的成员cpu获取的,current_thread_info()->cpu.
  而不同的架构,thread_info所放的位置也不同,所以获取的代码也不一样。从上面可以看到,thread_info是放在“$28”寄存器当中的,而其他架构,比如x86,或者arm一般是放在堆栈中的。
  
  参考:http://blog.csdn.net/adaptiver/article/details/7442555
    
阅读(5042) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:基于mips架构的smp启动过程(1)

给主人留下些什么吧!~~