diff options
author | Ian Moffett <ian@osmora.org> | 2025-05-31 01:22:50 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-05-31 01:52:35 -0400 |
commit | d3d30751c49cadf015c4ebb5eaebe6dcefd982b4 (patch) | |
tree | 707d3b2ce7bc01114ea77aaf36007f1baf853971 /sys | |
parent | 2bb882d1b394109f555789ba30e2cedc727c58e1 (diff) |
kernel: sched: Add sched_switch_to()
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys')
-rw-r--r-- | sys/include/sys/sched.h | 2 | ||||
-rw-r--r-- | sys/kern/kern_sched.c | 26 |
2 files changed, 21 insertions, 7 deletions
diff --git a/sys/include/sys/sched.h b/sys/include/sys/sched.h index 80f4d1c..7d17607 100644 --- a/sys/include/sys/sched.h +++ b/sys/include/sys/sched.h @@ -37,6 +37,8 @@ void sched_init(void); void sched_yield(void); + +void sched_switch_to(struct trapframe *tf, struct proc *td); void sched_detach(struct proc *td); __dead void sched_enter(void); diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c index 2fe0f32..65e08d7 100644 --- a/sys/kern/kern_sched.c +++ b/sys/kern/kern_sched.c @@ -176,15 +176,31 @@ td_pri_update(struct proc *td) } } +void +sched_switch_to(struct trapframe *tf, struct proc *td) +{ + struct cpu_info *ci; + struct pcb *pcbp; + + ci = this_cpu(); + + if (tf != NULL) { + memcpy(tf, &td->tf, sizeof(*tf)); + } + + ci->curtd = td; + pcbp = &td->pcb; + pmap_switch_vas(pcbp->addrsp); +} + /* * Perform a context switch. */ void sched_switch(struct trapframe *tf) { - struct cpu_info *ci; - struct pcb *pcbp; struct proc *next_td, *td; + struct cpu_info *ci; ci = this_cpu(); td = ci->curtd; @@ -203,11 +219,7 @@ sched_switch(struct trapframe *tf) return; } - memcpy(tf, &next_td->tf, sizeof(*tf)); - ci->curtd = next_td; - pcbp = &next_td->pcb; - - pmap_switch_vas(pcbp->addrsp); + sched_switch_to(tf, next_td); sched_oneshot(false); } |