Index | Thread | Search

From:
Tim Leslie <tleslie@protonmail.com>
Subject:
Re: Make scheduler round robin tick event-driven
To:
Stuart Henderson <stu@spacehopper.org>
Cc:
Damien Miller <djm@mindrot.org>, "tech@openbsd.org" <tech@openbsd.org>
Date:
Mon, 06 Oct 2025 21:29:13 +0000

Download raw body.

Thread
On Monday, October 6th, 2025 at 8:25 AM, Stuart Henderson <stu@spacehopper.org> wrote:

> On 2025/10/06 17:04, Damien Miller wrote:
> 
> > On Fri, 3 Oct 2025, Tim Leslie wrote:
> > 
> > > Tech,
> > > 
> > > Attached is a patch to make the scheduler's round robin tick more event-driven.
> > > - The tick is stopped when the CPU goes idle, rather than firing continuously.
> > > - When scheduling a new process, arm the tick for a full quantum rather than run the tick as a background metronome.
> > > 
> > > This change primarily affects systems with high CPU counts and frequent idle periods. The intent is to minimize timer interrupts, ensure quantum enforcement when needed, and reduce scheduler overhead on larger SMP/VM systems.
> > > 
> > > Feedback appreciated.
> > 
> > I'm not familiar with the scheduler but this diff does not appear to
> > be correct. Nothing ever sets roundrobinperiod in kern_sched.c and
> > the variable name doesn't even match its later use as roundrobin_period.
> 

Updated diff below addresses mistake noted by Damien and also fixes logic where the tick was being started in the donor cpu's clock, not in the stealer's.

Tim

--

diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c
--- a/sys/kern/kern_sched.c
+++ b/sys/kern/kern_sched.c
@@ -358,8 +358,10 @@ again:
 		sched_noidle++;
 		if (p->p_stat != SRUN)
 			panic("thread %d not in SRUN: %d", p->p_tid, p->p_stat);
+		clockintr_advance(&spc->spc_roundrobin, roundrobin_period);
 	} else if ((p = sched_steal_proc(curcpu())) == NULL) {
 		p = spc->spc_idleproc;
+		clockintr_cancel(&spc->spc_roundrobin);
 		if (p == NULL)
 			panic("no idleproc set on CPU%d",
 			    CPU_INFO_UNIT(curcpu()));
@@ -538,6 +540,7 @@ sched_steal_proc(struct cpu_info *self)
 
 	remrunqueue(best);
 	best->p_cpu = self;
+	clockintr_advance(&self->ci_schedstate.spc_roundrobin, roundrobin_period);
 
 	sched_stolen++;
 #endif