diff options
author | Ian Moffett <ian@osmora.org> | 2025-05-19 00:50:54 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-05-19 00:54:32 -0400 |
commit | d2275fbf73f55e202d8e64726d8b5c23b70b15b0 (patch) | |
tree | 9582d2e09534ed6abf0a6e559b274622332ca6d4 | |
parent | 0fa5f5f2c65d53bdc8d1a9337bc76e278dc304f2 (diff) |
kernel: sched: Rewrite context switch logic
Simplify and improve context switch logic, also stops the LAPIC from
being spammed with register accesses. This also updates the default
quantum to 9000 us to avoid cache thrashing and all kinds of other nasty
things.
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r-- | sys/include/sys/schedvar.h | 2 | ||||
-rw-r--r-- | sys/kern/kern_sched.c | 39 |
2 files changed, 6 insertions, 35 deletions
diff --git a/sys/include/sys/schedvar.h b/sys/include/sys/schedvar.h index 509e2c9..5ed9f5f 100644 --- a/sys/include/sys/schedvar.h +++ b/sys/include/sys/schedvar.h @@ -36,7 +36,7 @@ #include <machine/cdefs.h> #if defined(_KERNEL) -#define DEFAULT_TIMESLICE_USEC 500 +#define DEFAULT_TIMESLICE_USEC 9000 #define SHORT_TIMESLICE_USEC 10 #define SCHED_POLICY_MLFQ 0x00U /* Multilevel feedback queue */ diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c index 8e5c0e9..c22ea25 100644 --- a/sys/kern/kern_sched.c +++ b/sys/kern/kern_sched.c @@ -185,7 +185,6 @@ sched_switch(struct trapframe *tf) struct cpu_info *ci; struct pcb *pcbp; struct proc *next_td, *td; - bool use_current; ci = this_cpu(); td = ci->curtd; @@ -193,39 +192,12 @@ sched_switch(struct trapframe *tf) if (td != NULL) { dispatch_signals(td); td_pri_update(td); + sched_save_td(td, tf); } - /* - * Get the next thread and use it only if it isn't - * in the middle of an exit, exec, or whatever. - */ - do { - use_current = true; - if ((next_td = sched_dequeue_td()) == NULL) { - sched_oneshot(false); - return; - } - - /* - * If we are in the middle of an exec, don't use this - * thread. - */ - if (ISSET(next_td->flags, PROC_EXEC)) { - use_current = false; - } - - /* - * Don't use this thread if we are currently - * exiting. - */ - if (ISSET(next_td->flags, PROC_EXITING)) { - use_current = false; - } - } while (!use_current); - - /* Save the previous thread */ - if (td != NULL) { - sched_save_td(td, tf); + if ((next_td = sched_dequeue_td()) == NULL) { + sched_oneshot(false); + return; } memcpy(tf, &next_td->tf, sizeof(*tf)); @@ -243,9 +215,8 @@ void sched_enter(void) { md_inton(); - md_sync_all(); + sched_oneshot(false); for (;;) { - sched_oneshot(false); md_pause(); } } |