xv6是一个支持多处理器的Unix-like操作系统,近日阅读源码时发现xv6在记录当前CPU和进程状态时非常tricky 首先,上代码: 1 extern struct cpu cpus[NCPU]; 2 extern int ncpu; 3 4 // Per-CPU v ...
xv6是一个支持多处理器的Unix-like操作系统,
近日阅读源码时发现xv6在记录当前CPU和进程状态时非常tricky
首先,上代码:
1 extern struct cpu cpus[NCPU]; 2 extern int ncpu; 3 4 // Per-CPU variables, holding pointers to the 5 // current cpu and to the current process. 6 // The asm suffix tells gcc to use "%gs:0" to refer to cpu 7 // and "%gs:4" to refer to proc. seginit sets up the 8 // %gs segment register so that %gs refers to the memory 9 // holding those two variables in the local cpu's struct cpu.10 // This is similar to how thread-local variables are implemented11 // in thread libraries such as Linux pthreads.12 extern struct cpu *cpu asm("%gs:0"); // &cpus[cpunum()]13 extern struct proc *proc asm("%gs:4"); // cpus[cpunum()].proc
原标题:xv6中存储cpu和进程信息的技巧
关键词:进程
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。