Hi, This diff makes sure that a proc and its per-CPU structure which tracks when to schedule another proc in round-robin are in sync. No observable change in time spent compiling the bsd.mp kernel.
This diff in addition with another which replaces schedclock() with equivalent code, shaves approx 5 secs in real time from a bsd.mp kernel build. Thanks Index: kern/sched_bsd.c =================================================================== RCS file: /cvs/src/sys/kern/sched_bsd.c,v retrieving revision 1.62 diff -u -p -u -p -r1.62 sched_bsd.c --- kern/sched_bsd.c 30 Jan 2020 08:51:27 -0000 1.62 +++ kern/sched_bsd.c 11 Feb 2020 14:00:17 -0000 @@ -90,21 +90,13 @@ roundrobin(struct cpu_info *ci) { struct schedstate_percpu *spc = &ci->ci_schedstate; - spc->spc_rrticks = rrticks_init; - if (ci->ci_curproc != NULL) { - if (spc->spc_schedflags & SPCF_SEENRR) { - /* - * The process has already been through a roundrobin - * without switching and may be hogging the CPU. - * Indicate that the process should yield. - */ - atomic_setbits_int(&spc->spc_schedflags, - SPCF_SHOULDYIELD); - } else { - atomic_setbits_int(&spc->spc_schedflags, - SPCF_SEENRR); - } + /* + * The process is now completing a roundrobin + * without switching off the CPU and may be hogging the CPU. + * Indicate that the process should yield. + */ + atomic_setbits_int(&spc->spc_schedflags, SPCF_SHOULDYIELD); } if (spc->spc_nrun) @@ -384,6 +376,16 @@ mi_switch(void) * scheduling flags. */ atomic_clearbits_int(&spc->spc_schedflags, SPCF_SWITCHCLEAR); + + /* + * We start afresh here, sync the proc and the per-cpu state + * to match exactly on how much time to allow the proc to run. + * This gives a chance to a proc to get its full quantum, and + * not worry if there is a chance to have it taken off the CPU + * at way less than its alloted quantum or have another proc + * take way more than its alloted quantum. + */ + spc->spc_rrticks = rrticks_init; nextproc = sched_chooseproc(); Index: sys/sched.h =================================================================== RCS file: /cvs/src/sys/sys/sched.h,v retrieving revision 1.56 diff -u -p -u -p -r1.56 sched.h --- sys/sched.h 21 Oct 2019 10:24:01 -0000 1.56 +++ sys/sched.h 11 Feb 2020 14:00:17 -0000 @@ -131,9 +131,8 @@ struct cpustats { #ifdef _KERNEL /* spc_flags */ -#define SPCF_SEENRR 0x0001 /* process has seen roundrobin() */ #define SPCF_SHOULDYIELD 0x0002 /* process should yield the CPU */ -#define SPCF_SWITCHCLEAR (SPCF_SEENRR|SPCF_SHOULDYIELD) +#define SPCF_SWITCHCLEAR (SPCF_SHOULDYIELD) #define SPCF_SHOULDHALT 0x0004 /* CPU should be vacated */ #define SPCF_HALTED 0x0008 /* CPU has been halted */