summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2019-11-01 20:58:02 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2019-11-01 20:58:02 +0000
commit2ec9c2d7f0bb1131c0952ff1f52e06f432cafc35 (patch)
tree3ec85ccbdbca79d4ed3171af6cfeafab13c36f24
parentcef5ebe64baa3f846ee7b4636948f1f8dff0e0ec (diff)
Kill resched_proc() and instead call need_resched() when a thread is
added to the runqueue of a CPU. This fix out-of-sync cases when the priority of a thread wasn't reflecting the runqueue it was sitting in leading to unnecessary context switch. ok visa@
-rw-r--r--sys/kern/kern_sched.c5
-rw-r--r--sys/kern/sched_bsd.c28
2 files changed, 5 insertions, 28 deletions
diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c
index c1da4d51141..a32dbba110d 100644
--- a/sys/kern/kern_sched.c
+++ b/sys/kern/kern_sched.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sched.c,v 1.59 2019/10/15 10:05:43 mpi Exp $ */
+/* $OpenBSD: kern_sched.c,v 1.60 2019/11/01 20:58:01 mpi Exp $ */
/*
* Copyright (c) 2007, 2008 Artur Grabowski <art@openbsd.org>
*
@@ -268,6 +268,9 @@ setrunqueue(struct cpu_info *ci, struct proc *p, uint8_t prio)
if (cpuset_isset(&sched_idle_cpus, p->p_cpu))
cpu_unidle(p->p_cpu);
+
+ if (prio < spc->spc_curpriority)
+ need_resched(ci);
}
void
diff --git a/sys/kern/sched_bsd.c b/sys/kern/sched_bsd.c
index e9d10f0c00b..c237dac5bad 100644
--- a/sys/kern/sched_bsd.c
+++ b/sys/kern/sched_bsd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sched_bsd.c,v 1.56 2019/10/15 10:05:43 mpi Exp $ */
+/* $OpenBSD: sched_bsd.c,v 1.57 2019/11/01 20:58:01 mpi Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*-
@@ -63,7 +63,6 @@ struct __mp_lock sched_lock;
void schedcpu(void *);
uint32_t decay_aftersleep(uint32_t, uint32_t);
-static inline void resched_proc(struct proc *, u_char);
void
scheduler_start(void)
@@ -254,7 +253,6 @@ schedcpu(void *arg)
p->p_cpticks = 0;
newcpu = (u_int) decay_cpu(loadfac, p->p_estcpu);
setpriority(p, newcpu, p->p_p->ps_nice);
- resched_proc(p, p->p_usrpri);
if (p->p_priority >= PUSER) {
if (p->p_stat == SRUN &&
@@ -438,29 +436,6 @@ mi_switch(void)
#endif
}
-static inline void
-resched_proc(struct proc *p, u_char pri)
-{
- struct cpu_info *ci;
-
- /*
- * XXXSMP
- * This does not handle the case where its last
- * CPU is running a higher-priority process, but every
- * other CPU is running a lower-priority process. There
- * are ways to handle this situation, but they're not
- * currently very pretty, and we also need to weigh the
- * cost of moving a process from one CPU to another.
- *
- * XXXSMP
- * There is also the issue of locking the other CPU's
- * sched state, which we currently do not do.
- */
- ci = (p->p_cpu != NULL) ? p->p_cpu : curcpu();
- if (pri < ci->ci_schedstate.spc_curpriority)
- need_resched(ci);
-}
-
/*
* Change process state to be runnable,
* placing it on the run queue if it is in memory,
@@ -498,7 +473,6 @@ setrunnable(struct proc *p)
setpriority(p, newcpu, p->p_p->ps_nice);
}
p->p_slptime = 0;
- resched_proc(p, MIN(p->p_priority, p->p_usrpri));
}
/*