Skip to content

Commit

Permalink
Removes wfi() from scheduler when waiting on process start.
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrik Karlsson committed Oct 24, 2023
1 parent d84c4f0 commit ea85188
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 3 additions & 3 deletions kernel/src/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ void sched(proc_t *p)
p = sched_fetch(hartid, &start_time, &end_time);
} while (!p);

timeout_set(hartid, start_time);
while (!(csrr_mip() & MIP_MTIP))
wfi();
timeout_set(hartid, end_time);
while (time_get() < start_time)
;

trap_exit(p);
}
14 changes: 10 additions & 4 deletions kernel/src/trap.S
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
trap_entry:
/* Save user tp to scratch, load PCB pointer */
csrrw a0,mscratch,a0
beqz a0,__hang
beqz a0,_machine_yield

sd ra,PROC_RA(a0)
sd sp,PROC_SP(a0)
Expand Down Expand Up @@ -79,14 +79,19 @@ _syscall:
csrw mstatus,x0
tail handle_syscall

_machine_yield:
csrrw a0,mscratch,a0
ld_sp t0
csrr t0,mcause

_yield:
li t1,(7 | 1 << 63)
bne t0,t1,__hang
li t1,0x8000000000000007
bne t0,t1,__hang
/* Call scheduler */
tail sched

trap_exit:

csrw mstatus,MSTATUS_MIE
/* Load PMP registers */
ld s0,PROC_PMPADDR0(a0)
ld s1,PROC_PMPADDR1(a0)
Expand All @@ -108,6 +113,7 @@ trap_exit:
csrw pmpcfg0,s8
beqz s8,trap_exit
trap_resume:
csrw mstatus,MSTATUS_MIE

/* Load call-used registers, ra, sp, gp, tp, pc */
ld t0,PROC_PC(a0)
Expand Down

0 comments on commit ea85188

Please sign in to comment.