简体   繁体   English

在xv6中实现内核级线程

[英]Implementing kernel level threads in xv6

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 ,但我不完全了解它的工作方式和原因。

I found out %gs points to to the line struct cpu *cpu; 我发现%gs指向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. 在struct cpu(在proc.h中定义)中,并在该行的正下方(在cpu指针后+ 4个字节),存储了cpu的当前进程: struct proc *proc; // The currently-running process. 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: 因此,为了增加线程支持,应更改此行以指向新的线程结构而不是进程结构,或者在“ proc”行下添加该线程并执行以下更改:

  1. add in proc.h the following decleration: extern struct thread *thread asm("%gs:8"); 在proc.h中添加以下内容: extern struct thread *thread asm("%gs:8");
  2. change in vm.c, in fucntion "seginit(void)" the line c->gdt[SEG_KCPU] = SEG(STA_W, &c->cpu, 8, 0); 在vm.c中更改,在功能“ seginit(void)”中更改行c->gdt[SEG_KCPU] = SEG(STA_W, &c->cpu, 8, 0); to c->gdt[SEG_KCPU] = SEG(STA_W, &c->cpu, 12, 0); c->gdt[SEG_KCPU] = SEG(STA_W, &c->cpu, 12, 0); in order to allocate space for the extra thread pointer. 为了为额外的线程指针分配空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM