内核中有许多地方需要获取当前活动的cpu id,这个是有smp_processor_id完成的,但是其具体的实现是和架构相关的。
这里以mips机构为列进行说明。
-
# define smp_processor_id() raw_smp_processor_id()
-
-
#define raw_smp_processor_id() (current_thread_info()->cpu)
-
-
/* How to get the thread information struct from C. */
-
static inline struct thread_info *current_thread_info(void)
-
{
-
register struct thread_info *__current_thread_info __asm__("$28");
-
-
return __current_thread_info;
-
}
可以看出cpu id实际上是通过thread_info结构中的成员cpu获取的,current_thread_info()->cpu.
而不同的架构,thread_info所放的位置也不同,所以获取的代码也不一样。从上面可以看到,thread_info是放在“$28”寄存器当中的,而其他架构,比如x86,或者arm一般是放在堆栈中的。
参考:http://blog.csdn.net/adaptiver/article/details/7442555
阅读(5253) | 评论(0) | 转发(0) |