I am trying to implement kernel level threads in xv6.
我试图在xv6中实现内核级线程。
My main problem at the moment is to understand how the CPU gets its information about the current process and how to modify it to point to the current thread instead.
我目前的主要问题是了解CPU如何获取有关当前进程的信息以及如何将其修改为指向当前线程。
I know it is somehow linked to this line:
我知道它以某种方式链接到这一行:
extern struct proc *proc asm("%gs:4");
in proc.h
, but I do not fully understand how and why it works.
在proc.h中,但我不完全理解它的工作原理和原因。
1 个解决方案
#1
3
I found out %gs points to to the line struct cpu *cpu;
in the struct cpu (defined at proc.h), and right below that line (+ 4 bytes after the cpu pointer) the current process of the cpu is stored: struct proc *proc; // The currently-running process.
so in order to add thread support one should either alter this line to point to the new thread struct instead of process struct or alternatively, add the thread below the "proc" line and perform the following changes:
我发现%gs指向行struct cpu * cpu;在struct cpu(在proc.h中定义),并在该行的正下方(cpu指针后的+ 4个字节),存储cpu的当前进程:struct proc * proc; //当前正在运行的进程所以为了添加线程支持,应该更改此行以指向新的线程结构而不是进程结构,或者在“proc”行下面添加线程并执行以下更改:
- add in proc.h the following decleration:
extern struct thread *thread asm("%gs:8");
- change in vm.c, in fucntion "seginit(void)" the line
c->gdt[SEG_KCPU] = SEG(STA_W, &c->cpu, 8, 0);
toc->gdt[SEG_KCPU] = SEG(STA_W, &c->cpu, 12, 0);
in order to allocate space for the extra thread pointer.
在proc.h中添加以下decleration:extern struct thread * thread asm(“%gs:8”);
更改为vm.c,在函数“seginit(void)”中,行c-> gdt [SEG_KCPU] = SEG(STA_W,&c-> cpu,8,0);到c-> gdt [SEG_KCPU] = SEG(STA_W,&c-> cpu,12,0);为了额外的线程指针分配空间。
#1
3
I found out %gs points to to the line struct cpu *cpu;
in the struct cpu (defined at proc.h), and right below that line (+ 4 bytes after the cpu pointer) the current process of the cpu is stored: struct proc *proc; // The currently-running process.
so in order to add thread support one should either alter this line to point to the new thread struct instead of process struct or alternatively, add the thread below the "proc" line and perform the following changes:
我发现%gs指向行struct cpu * cpu;在struct cpu(在proc.h中定义),并在该行的正下方(cpu指针后的+ 4个字节),存储cpu的当前进程:struct proc * proc; //当前正在运行的进程所以为了添加线程支持,应该更改此行以指向新的线程结构而不是进程结构,或者在“proc”行下面添加线程并执行以下更改:
- add in proc.h the following decleration:
extern struct thread *thread asm("%gs:8");
- change in vm.c, in fucntion "seginit(void)" the line
c->gdt[SEG_KCPU] = SEG(STA_W, &c->cpu, 8, 0);
toc->gdt[SEG_KCPU] = SEG(STA_W, &c->cpu, 12, 0);
in order to allocate space for the extra thread pointer.
在proc.h中添加以下decleration:extern struct thread * thread asm(“%gs:8”);
更改为vm.c,在函数“seginit(void)”中,行c-> gdt [SEG_KCPU] = SEG(STA_W,&c-> cpu,8,0);到c-> gdt [SEG_KCPU] = SEG(STA_W,&c-> cpu,12,0);为了额外的线程指针分配空间。