As discussed in the hackroom. If a thread cross the tick boundary at
which schedclock() is executed while spinning do not account for such
time as "being running".
This has two benefits:
- reduce possible contention on the SCHED_LOCK() when many threads are
spinning on the KERNEL_LOCK()
- do not decrease the priority of a thread for the amount of time it
has been spinning
The simple diff below might introduce unwanted side effects. Checking
for spc_spinning might result in a (multiple) off-by-one in the
calculation of a priority. However the current logic hasn't been
designed for the architecture we run on. So it might even be a positive
side effects.
Please test & report what you see.
Index: kern/sched_bsd.c
===================================================================
RCS file: /cvs/src/sys/kern/sched_bsd.c,v
retrieving revision 1.50
diff -u -p -r1.50 sched_bsd.c
--- kern/sched_bsd.c 26 Feb 2019 14:24:21 -0000 1.50
+++ kern/sched_bsd.c 12 May 2019 17:30:45 -0000
@@ -542,7 +542,7 @@ schedclock(struct proc *p)
struct schedstate_percpu *spc = &ci->ci_schedstate;
int s;
- if (p == spc->spc_idleproc)
+ if (p == spc->spc_idleproc || spc->spc_spinning)
return;
SCHED_LOCK(s);