Download raw body.
Make scheduler round robin tick event-driven
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.
Was this diff written by an LLM?
> Did you mean this:
>
> > 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
> > @@ -35,6 +35,8 @@ void sched_kthreads_create(void *);
> > int sched_proc_to_cpu_cost(struct cpu_info *ci, struct proc *p);
> > struct proc *sched_steal_proc(struct cpu_info *);
> >
> > +uint64_t roundrobinperiod; /* round robin period in ns */
>
> to be
>
> extern uint64_t roundrobin_period;
>
> ??
>
>
>
> > /*
> > * To help choosing which cpu should run which process we keep track
> > * of cpus which are currently idle and which cpus have processes
> > @@ -358,8 +360,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 +542,7 @@ sched_steal_proc(struct cpu_info *self)
> >
> > remrunqueue(best);
> > best->p_cpu = self;
> > + clockintr_advance(&spc->spc_roundrobin, roundrobin_period);
> >
> > sched_stolen++;
> > #endif
> >
> >
>
Make scheduler round robin tick event-driven