《Linux内核情景分析》经典解说--进程

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lovelycheng/article/details/78359951
get_current 使用宏的原因
==================== include/asmi386/
current.h 6 13 ====================
6 static inline struct task_struct * get_current(void)
7 {
8 struct task_struct *current;
9 __asm__("andl %%esp,%0; ":"=r" (current) : "0" (~8191UL));
10 return current;
11 }
12
13 #define current get_current()

一条AND指令的执行只需4个CPU时钟周期,而一条从寄存器到寄存器的MOV指令也才2个CPU时钟周期,所有,像这样在需要时才临时把它计算出来反而效率比直接使用current全局变量要高。

猜你喜欢

转载自blog.csdn.net/lovelycheng/article/details/78359951