summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2019-10-15 10:05:44 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2019-10-15 10:05:44 +0000
commit07401344a87ce055bd1d392faac7b8a134106e5d (patch)
treeab7a057d65a111b3ad875390443ef036968e3dba
parentf544d4e116d3b1a0ea4ca1fed95f86adabba46eb (diff)
Reduce the number of places where `p_priority' and `p_stat' are set.
This refactoring will help future scheduler locking, in particular to shrink the SCHED_LOCK(). No intended behavior change. ok visa@
-rw-r--r--sys/arch/m88k/m88k/m88k_machdep.c6
-rw-r--r--sys/kern/kern_fork.c8
-rw-r--r--sys/kern/kern_sched.c26
-rw-r--r--sys/kern/kern_synch.c10
-rw-r--r--sys/kern/sched_bsd.c17
-rw-r--r--sys/sys/sched.h4
6 files changed, 34 insertions, 37 deletions
diff --git a/sys/arch/m88k/m88k/m88k_machdep.c b/sys/arch/m88k/m88k/m88k_machdep.c
index 46a20b8f44a..0a32f419679 100644
--- a/sys/arch/m88k/m88k/m88k_machdep.c
+++ b/sys/arch/m88k/m88k/m88k_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: m88k_machdep.c,v 1.69 2018/10/22 17:31:24 krw Exp $ */
+/* $OpenBSD: m88k_machdep.c,v 1.70 2019/10/15 10:05:43 mpi Exp $ */
/*
* Copyright (c) 1998, 1999, 2000, 2001 Steve Murphree, Jr.
* Copyright (c) 1996 Nivas Madhur
@@ -564,9 +564,7 @@ cpu_emergency_disable()
* to mi_switch().
*/
SCHED_LOCK(s);
- p->p_priority = p->p_usrpri;
- p->p_stat = SRUN;
- setrunqueue(p);
+ setrunqueue(p->p_cpu, p, p->p_usrpri);
p->p_ru.ru_nvcsw++;
SCHED_UNLOCK(s);
}
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 95180d9de31..9e8bd0aa802 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_fork.c,v 1.213 2019/06/21 09:39:48 visa Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.214 2019/10/15 10:05:43 mpi Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
@@ -326,12 +326,12 @@ fork_check_maxthread(uid_t uid)
static inline void
fork_thread_start(struct proc *p, struct proc *parent, int flags)
{
+ struct cpu_info *ci;
int s;
SCHED_LOCK(s);
- p->p_stat = SRUN;
- p->p_cpu = sched_choosecpu_fork(parent, flags);
- setrunqueue(p);
+ ci = sched_choosecpu_fork(parent, flags);
+ setrunqueue(ci, p, p->p_priority);
SCHED_UNLOCK(s);
}
diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c
index 74920d7030f..c1da4d51141 100644
--- a/sys/kern/kern_sched.c
+++ b/sys/kern/kern_sched.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sched.c,v 1.58 2019/06/01 14:11:17 mpi Exp $ */
+/* $OpenBSD: kern_sched.c,v 1.59 2019/10/15 10:05:43 mpi Exp $ */
/*
* Copyright (c) 2007, 2008 Artur Grabowski <art@openbsd.org>
*
@@ -244,12 +244,21 @@ sched_init_runqueues(void)
}
void
-setrunqueue(struct proc *p)
+setrunqueue(struct cpu_info *ci, struct proc *p, uint8_t prio)
{
struct schedstate_percpu *spc;
- int queue = p->p_priority >> 2;
+ int queue = prio >> 2;
+
+ if (ci == NULL)
+ ci = sched_choosecpu(p);
+ KASSERT(ci != NULL);
SCHED_ASSERT_LOCKED();
+
+ p->p_cpu = ci;
+ p->p_stat = SRUN;
+ p->p_priority = prio;
+
spc = &p->p_cpu->ci_schedstate;
spc->spc_nrun++;
@@ -294,8 +303,7 @@ sched_chooseproc(void)
for (queue = 0; queue < SCHED_NQS; queue++) {
while ((p = TAILQ_FIRST(&spc->spc_qs[queue]))) {
remrunqueue(p);
- p->p_cpu = sched_choosecpu(p);
- setrunqueue(p);
+ setrunqueue(NULL, p, p->p_priority);
if (p->p_cpu == curcpu()) {
KASSERT(p->p_flag & P_CPUPEG);
goto again;
@@ -317,7 +325,8 @@ again:
p = TAILQ_FIRST(&spc->spc_qs[queue]);
remrunqueue(p);
sched_noidle++;
- KASSERT(p->p_stat == SRUN);
+ if (p->p_stat != SRUN)
+ panic("thread %d not in SRUN: %d", p->p_tid, p->p_stat);
} else if ((p = sched_steal_proc(curcpu())) == NULL) {
p = spc->spc_idleproc;
if (p == NULL) {
@@ -610,11 +619,8 @@ sched_peg_curproc(struct cpu_info *ci)
int s;
SCHED_LOCK(s);
- p->p_priority = p->p_usrpri;
- p->p_stat = SRUN;
- p->p_cpu = ci;
atomic_setbits_int(&p->p_flag, P_CPUPEG);
- setrunqueue(p);
+ setrunqueue(ci, p, p->p_usrpri);
p->p_ru.ru_nvcsw++;
mi_switch();
SCHED_UNLOCK(s);
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
index fde7d58fb95..1aa80d925e9 100644
--- a/sys/kern/kern_synch.c
+++ b/sys/kern/kern_synch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_synch.c,v 1.152 2019/10/01 15:08:27 cheloha Exp $ */
+/* $OpenBSD: kern_synch.c,v 1.153 2019/10/15 10:05:43 mpi Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*
@@ -546,6 +546,7 @@ int
sys_sched_yield(struct proc *p, void *v, register_t *retval)
{
struct proc *q;
+ uint8_t newprio;
int s;
SCHED_LOCK(s);
@@ -554,11 +555,10 @@ sys_sched_yield(struct proc *p, void *v, register_t *retval)
* sched_yield(2), drop its priority to ensure its siblings
* can make some progress.
*/
- p->p_priority = p->p_usrpri;
+ newprio = p->p_usrpri;
TAILQ_FOREACH(q, &p->p_p->ps_threads, p_thr_link)
- p->p_priority = max(p->p_priority, q->p_priority);
- p->p_stat = SRUN;
- setrunqueue(p);
+ newprio = max(newprio, q->p_priority);
+ setrunqueue(p->p_cpu, p, newprio);
p->p_ru.ru_nvcsw++;
mi_switch();
SCHED_UNLOCK(s);
diff --git a/sys/kern/sched_bsd.c b/sys/kern/sched_bsd.c
index f4658d776ea..e9d10f0c00b 100644
--- a/sys/kern/sched_bsd.c
+++ b/sys/kern/sched_bsd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sched_bsd.c,v 1.55 2019/07/15 20:44:48 mpi Exp $ */
+/* $OpenBSD: sched_bsd.c,v 1.56 2019/10/15 10:05:43 mpi Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*-
@@ -261,8 +261,7 @@ schedcpu(void *arg)
(p->p_priority / SCHED_PPQ) !=
(p->p_usrpri / SCHED_PPQ)) {
remrunqueue(p);
- p->p_priority = p->p_usrpri;
- setrunqueue(p);
+ setrunqueue(p->p_cpu, p, p->p_usrpri);
} else
p->p_priority = p->p_usrpri;
}
@@ -310,9 +309,7 @@ yield(void)
NET_ASSERT_UNLOCKED();
SCHED_LOCK(s);
- p->p_priority = p->p_usrpri;
- p->p_stat = SRUN;
- setrunqueue(p);
+ setrunqueue(p->p_cpu, p, p->p_usrpri);
p->p_ru.ru_nvcsw++;
mi_switch();
SCHED_UNLOCK(s);
@@ -331,9 +328,7 @@ preempt(void)
int s;
SCHED_LOCK(s);
- p->p_priority = p->p_usrpri;
- p->p_stat = SRUN;
- setrunqueue(p);
+ setrunqueue(p->p_cpu, p, p->p_usrpri);
p->p_ru.ru_nivcsw++;
mi_switch();
SCHED_UNLOCK(s);
@@ -495,9 +490,7 @@ setrunnable(struct proc *p)
unsleep(p); /* e.g. when sending signals */
break;
}
- p->p_stat = SRUN;
- p->p_cpu = sched_choosecpu(p);
- setrunqueue(p);
+ setrunqueue(NULL, p, p->p_priority);
if (p->p_slptime > 1) {
uint32_t newcpu;
diff --git a/sys/sys/sched.h b/sys/sys/sched.h
index e4e9cdf6ee8..923b2727931 100644
--- a/sys/sys/sched.h
+++ b/sys/sys/sched.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sched.h,v 1.54 2019/07/15 20:44:48 mpi Exp $ */
+/* $OpenBSD: sched.h,v 1.55 2019/10/15 10:05:43 mpi Exp $ */
/* $NetBSD: sched.h,v 1.2 1999/02/28 18:14:58 ross Exp $ */
/*-
@@ -179,7 +179,7 @@ void sched_stop_secondary_cpus(void);
int cpu_is_online(struct cpu_info *);
void sched_init_runqueues(void);
-void setrunqueue(struct proc *);
+void setrunqueue(struct cpu_info *, struct proc *, uint8_t);
void remrunqueue(struct proc *);
/* Inherit the parent's scheduler history */