// Per-CPU state struct cpu { uchar id; // Local APIC ID; index into cpus[] below struct context *scheduler; // scheduler context,即scheduler运行环境信息 struct taskstate ts; // 用于interrupt时寻找进程的内核栈 struct segdesc gdt[NSEGS]; // x86 global descriptor table volatile uint started; // Has the CPU started? int ncli; // Depth of pushcli nesting. int intena; // Were interrupts enabled before pushcli? // Cpu-local storage variables struct cpu *cpu; struct proc *proc; // The currently-running process. };
// Per-process state struct proc { uint sz; // Size of process memory (bytes) pde_t* pgdir; // Page table,页表,代表用户进程地址空间 char *kstack; // Bottom of kernel stack for this process,代表进程的内核栈 enum procstate state; // Process state volatileint pid; // Process ID struct proc *parent; // Parent process struct trapframe *tf; // Trap frame for current syscall struct context *context; // swtch() here to run process void *chan; // If non-zero, sleeping on chan int killed; // If non-zero, have been killed struct file *ofile[NOFILE]; // Open files struct inode *cwd; // Current directory char name[16]; // Process name (debugging) };