pagetable lab initialized

This commit is contained in:
2025-05-06 11:20:36 +08:00
parent 0e751d690f
commit 38997cbef6
42 changed files with 1963 additions and 1154 deletions

View File

@ -5,9 +5,6 @@
#include "spinlock.h"
#include "proc.h"
#include "defs.h"
#include "sysinfo.h"
uint64 current_load = 0;
struct cpu cpus[NCPU];
@ -149,9 +146,6 @@ found:
p->context.ra = (uint64)forkret;
p->context.sp = p->kstack + PGSIZE;
// 初始化计数器
memset(p->syscall_counts, 0, sizeof(p->syscall_counts));
return p;
}
@ -316,8 +310,6 @@ fork(void)
safestrcpy(np->name, p->name, sizeof(p->name));
// 复制掩码
np->tracemask = p->tracemask;
pid = np->pid;
release(&np->lock);
@ -454,7 +446,6 @@ scheduler(void)
{
struct proc *p;
struct cpu *c = mycpu();
/*update_load_avg();*/
c->proc = 0;
for(;;){
@ -463,6 +454,7 @@ scheduler(void)
// processes are waiting.
intr_on();
int found = 0;
for(p = proc; p < &proc[NPROC]; p++) {
acquire(&p->lock);
if(p->state == RUNNABLE) {
@ -471,15 +463,20 @@ scheduler(void)
// before jumping back to us.
p->state = RUNNING;
c->proc = p;
current_load += 1;
swtch(&c->context, &p->context);
// Process is done running for now.
// It should have changed its p->state before coming back.
c->proc = 0;
found = 1;
}
release(&p->lock);
}
if(found == 0) {
// nothing to run; stop running on this core until an interrupt.
intr_on();
asm volatile("wfi");
}
}
}
@ -696,18 +693,3 @@ procdump(void)
printf("\n");
}
}
int
proc_size()
{
int i =0, n = 0;
for (; i < NPROC; ++i) {
if (proc[i].state != UNUSED) n += 1;
}
return n;
}
int
update_load() {
return current_load;
}