-/* $OpenBSD: drm_linux.c,v 1.112 2024/03/30 13:33:20 mpi Exp $ */
+/* $OpenBSD: drm_linux.c,v 1.113 2024/06/03 12:48:25 claudio Exp $ */
/*
* Copyright (c) 2013 Jonathan Gray <jsg@openbsd.org>
* Copyright (c) 2015, 2016 Mark Kettenis <kettenis@openbsd.org>
__set_current_state(int state)
{
struct proc *p = curproc;
- int s;
KASSERT(state == TASK_RUNNING);
- SCHED_LOCK(s);
+ SCHED_LOCK();
unsleep(p);
p->p_stat = SONPROC;
atomic_clearbits_int(&p->p_flag, P_WSLEEP);
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
}
void
int
wake_up_process(struct proc *p)
{
- int s, rv;
+ int rv;
- SCHED_LOCK(s);
+ SCHED_LOCK();
rv = wakeup_proc(p, 0);
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
return rv;
}
-/* $OpenBSD: kern_exit.c,v 1.221 2024/05/20 10:32:20 claudio Exp $ */
+/* $OpenBSD: kern_exit.c,v 1.222 2024/06/03 12:48:25 claudio Exp $ */
/* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */
/*
struct process *pr, *qr, *nqr;
struct rusage *rup;
struct timespec ts;
- int s;
atomic_setbits_int(&p->p_flag, P_WEXIT);
timespecclear(&ts);
else
timespecsub(&ts, &curcpu()->ci_schedstate.spc_runtime, &ts);
- SCHED_LOCK(s);
+ SCHED_LOCK();
tuagg_locked(pr, p, &ts);
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
/*
* clear %cpu usage during swap
-/* $OpenBSD: kern_fork.c,v 1.259 2024/05/29 18:55:45 claudio Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.260 2024/06/03 12:48:25 claudio Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
fork_thread_start(struct proc *p, struct proc *parent, int flags)
{
struct cpu_info *ci;
- int s;
- SCHED_LOCK(s);
+ SCHED_LOCK();
ci = sched_choosecpu_fork(parent, flags);
TRACEPOINT(sched, fork, p->p_tid + THREAD_PID_OFFSET,
p->p_p->ps_pid, CPU_INFO_UNIT(ci));
setrunqueue(ci, p, p->p_usrpri);
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
}
int
-/* $OpenBSD: kern_resource.c,v 1.83 2024/05/22 09:20:22 claudio Exp $ */
+/* $OpenBSD: kern_resource.c,v 1.84 2024/06/03 12:48:25 claudio Exp $ */
/* $NetBSD: kern_resource.c,v 1.38 1996/10/23 07:19:38 matthias Exp $ */
/*-
{
struct ucred *ucred = curp->p_ucred;
struct proc *p;
- int s;
if (ucred->cr_uid != 0 && ucred->cr_ruid != 0 &&
ucred->cr_uid != chgpr->ps_ucred->cr_uid &&
return (EACCES);
chgpr->ps_nice = n;
mtx_enter(&chgpr->ps_mtx);
- SCHED_LOCK(s);
+ SCHED_LOCK();
TAILQ_FOREACH(p, &chgpr->ps_threads, p_thr_link) {
setpriority(p, p->p_estcpu, n);
}
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
mtx_leave(&chgpr->ps_mtx);
return (0);
}
void
tuagg(struct process *pr, struct proc *p)
{
- int s;
-
- SCHED_LOCK(s);
+ SCHED_LOCK();
tuagg_locked(pr, p, NULL);
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
}
/*
struct rlimit rlim;
struct process *pr = arg;
time_t runtime;
- int s;
KERNEL_ASSERT_LOCKED();
- SCHED_LOCK(s);
+ SCHED_LOCK();
runtime = pr->ps_tu.tu_runtime.tv_sec;
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
mtx_enter(&pr->ps_mtx);
rlim = pr->ps_limit->pl_rlimit[RLIMIT_CPU];
-/* $OpenBSD: kern_sched.c,v 1.95 2024/02/28 13:43:44 mpi Exp $ */
+/* $OpenBSD: kern_sched.c,v 1.96 2024/06/03 12:48:25 claudio Exp $ */
/*
* Copyright (c) 2007, 2008 Artur Grabowski <art@openbsd.org>
*
struct schedstate_percpu *spc;
struct proc *p = curproc;
struct cpu_info *ci = v;
- int s;
KERNEL_UNLOCK();
* First time we enter here, we're not supposed to idle,
* just go away for a while.
*/
- SCHED_LOCK(s);
+ SCHED_LOCK();
cpuset_add(&sched_idle_cpus, ci);
p->p_stat = SSLEEP;
p->p_cpu = ci;
atomic_setbits_int(&p->p_flag, P_CPUPEG);
mi_switch();
cpuset_del(&sched_idle_cpus, ci);
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
KASSERT(ci == curcpu());
KASSERT(curproc == spc->spc_idleproc);
while (!cpu_is_idle(curcpu())) {
struct proc *dead;
- SCHED_LOCK(s);
+ SCHED_LOCK();
p->p_stat = SSLEEP;
mi_switch();
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
while ((dead = LIST_FIRST(&spc->spc_deadproc))) {
LIST_REMOVE(dead, p_hash);
if (spc->spc_schedflags & SPCF_SHOULDHALT &&
(spc->spc_schedflags & SPCF_HALTED) == 0) {
cpuset_del(&sched_idle_cpus, ci);
- SCHED_LOCK(s);
+ SCHED_LOCK();
atomic_setbits_int(&spc->spc_schedflags,
spc->spc_whichqs ? 0 : SPCF_HALTED);
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
wakeup(spc);
}
#endif
{
struct schedstate_percpu *spc = &curcpu()->ci_schedstate;
struct proc *idle;
- int s;
#ifdef MULTIPROCESSOR
/* This process no longer needs to hold the kernel lock. */
atomic_clearbits_int(&spc->spc_schedflags, SPCF_SWITCHCLEAR);
- SCHED_LOCK(s);
-
+ SCHED_LOCK();
idle = spc->spc_idleproc;
idle->p_stat = SRUN;
sched_peg_curproc(struct cpu_info *ci)
{
struct proc *p = curproc;
- int s;
- SCHED_LOCK(s);
+ SCHED_LOCK();
atomic_setbits_int(&p->p_flag, P_CPUPEG);
setrunqueue(ci, p, p->p_usrpri);
p->p_ru.ru_nvcsw++;
mi_switch();
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
}
#ifdef MULTIPROCESSOR
-/* $OpenBSD: kern_sig.c,v 1.329 2024/05/22 09:22:55 claudio Exp $ */
+/* $OpenBSD: kern_sig.c,v 1.330 2024/06/03 12:48:25 claudio Exp $ */
/* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */
/*
*/
if (((pr->ps_flags & (PS_TRACED | PS_PPWAIT)) == PS_TRACED) &&
signum != SIGKILL && (p->p_sigmask & mask) != 0) {
- int s;
-
single_thread_set(p, SINGLE_SUSPEND | SINGLE_NOWAIT);
pr->ps_xsig = signum;
- SCHED_LOCK(s);
+ SCHED_LOCK();
proc_stop(p, 1);
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
signum = pr->ps_xsig;
single_thread_clear(p, 0);
void
ptsignal(struct proc *p, int signum, enum signal_type type)
{
- int s, prop;
+ int prop;
sig_t action, altaction = SIG_DFL;
sigset_t mask, sigmask;
int *siglist;
if (q != p)
ptsignal(q, signum, SPROPAGATED);
- SCHED_LOCK(s);
+ SCHED_LOCK();
switch (p->p_stat) {
atomic_clearbits_int(&p->p_flag, P_CONTINUED);
}
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
if (wakeparent)
wakeup(pr->ps_pptr);
}
struct process *pr = p->p_p;
int signum, mask, prop;
sigset_t ps_siglist;
- int s;
KASSERT(p == curproc);
single_thread_set(p, SINGLE_SUSPEND | SINGLE_NOWAIT);
pr->ps_xsig = signum;
- SCHED_LOCK(s);
+ SCHED_LOCK();
proc_stop(p, 1);
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
/*
* re-take the signal before releasing
prop & SA_TTYSTOP))
break; /* == ignore */
pr->ps_xsig = signum;
- SCHED_LOCK(s);
+ SCHED_LOCK();
proc_stop(p, 1);
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
break;
} else if (prop & SA_IGNORE) {
/*
single_thread_check_locked(struct proc *p, int deep)
{
struct process *pr = p->p_p;
- int s;
MUTEX_ASSERT_LOCKED(&pr->ps_mtx);
/* not exiting and don't need to unwind, so suspend */
mtx_leave(&pr->ps_mtx);
- SCHED_LOCK(s);
+ SCHED_LOCK();
p->p_stat = SSTOP;
mi_switch();
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
mtx_enter(&pr->ps_mtx);
} while (pr->ps_single != NULL);
{
struct process *pr = p->p_p;
struct proc *q;
- int error, s, mode = flags & SINGLE_MASK;
+ int error, mode = flags & SINGLE_MASK;
KASSERT(curproc == p);
TAILQ_FOREACH(q, &pr->ps_threads, p_thr_link) {
if (q == p)
continue;
- SCHED_LOCK(s);
+ SCHED_LOCK();
atomic_setbits_int(&q->p_flag, P_SUSPSINGLE);
switch (q->p_stat) {
case SIDL:
case SRUN:
break;
}
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
}
/* count ourselfs out */
{
struct process *pr = p->p_p;
struct proc *q;
- int s;
KASSERT(pr->ps_single == p);
KASSERT(curproc == p);
* then clearing that either makes it runnable or puts
* it back into some sleep queue
*/
- SCHED_LOCK(s);
+ SCHED_LOCK();
if (q->p_stat == SSTOP && (q->p_flag & flag) == 0) {
if (q->p_wchan == NULL)
setrunnable(q);
q->p_stat = SSLEEP;
}
}
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
}
mtx_leave(&pr->ps_mtx);
}
-/* $OpenBSD: kern_synch.c,v 1.204 2024/05/22 09:24:11 claudio Exp $ */
+/* $OpenBSD: kern_synch.c,v 1.205 2024/06/03 12:48:25 claudio Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*
sleep_setup(const volatile void *ident, int prio, const char *wmesg)
{
struct proc *p = curproc;
- int s;
#ifdef DIAGNOSTIC
if (p->p_flag & P_CANTSLEEP)
if (p->p_flag & P_WEXIT)
CLR(prio, PCATCH);
- SCHED_LOCK(s);
+ SCHED_LOCK();
TRACEPOINT(sched, sleep, NULL);
atomic_setbits_int(&p->p_flag, P_SINTR);
p->p_stat = SSLEEP;
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
}
int
sleep_finish(int timo, int do_sleep)
{
struct proc *p = curproc;
- int s, catch, error = 0, error1 = 0;
+ int catch, error = 0, error1 = 0;
catch = p->p_flag & P_SINTR;
}
}
- SCHED_LOCK(s);
+ SCHED_LOCK();
/*
* If the wakeup happens while going to sleep, p->p_wchan
* will be NULL. In that case unwind immediately but still
#endif
p->p_cpu->ci_schedstate.spc_curpriority = p->p_usrpri;
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
/*
* Even though this belongs to the signal handling part of sleep,
endtsleep(void *arg)
{
struct proc *p = arg;
- int s;
- SCHED_LOCK(s);
+ SCHED_LOCK();
wakeup_proc(p, P_TIMEOUT);
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
}
/*
struct slpque *qp, wakeq;
struct proc *p;
struct proc *pnext;
- int s;
TAILQ_INIT(&wakeq);
- SCHED_LOCK(s);
+ SCHED_LOCK();
qp = &slpque[LOOKUP(ident)];
for (p = TAILQ_FIRST(qp); p != NULL && n != 0; p = pnext) {
pnext = TAILQ_NEXT(p, p_runq);
if (p->p_stat == SSLEEP)
setrunnable(p);
}
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
}
/*
{
struct proc *q;
uint8_t newprio;
- int s;
/*
* If one of the threads of a multi-threaded process called
newprio = max(newprio, q->p_runpri);
mtx_leave(&p->p_p->ps_mtx);
- SCHED_LOCK(s);
+ SCHED_LOCK();
setrunqueue(p->p_cpu, p, newprio);
p->p_ru.ru_nvcsw++;
mi_switch();
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
return (0);
}
-/* $OpenBSD: sched_bsd.c,v 1.92 2024/05/29 18:55:45 claudio Exp $ */
+/* $OpenBSD: sched_bsd.c,v 1.93 2024/06/03 12:48:25 claudio Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*-
static struct timeout to = TIMEOUT_INITIALIZER(schedcpu, NULL);
fixpt_t loadfac = loadfactor(averunnable.ldavg[0]);
struct proc *p;
- int s;
unsigned int newcpu;
LIST_FOREACH(p, &allproc, p_list) {
*/
if (p->p_slptime > 1)
continue;
- SCHED_LOCK(s);
+ SCHED_LOCK();
/*
* p_pctcpu is only for diagnostic tools such as ps.
*/
remrunqueue(p);
setrunqueue(p->p_cpu, p, p->p_usrpri);
}
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
}
wakeup(&lbolt);
timeout_add_sec(&to, 1);
yield(void)
{
struct proc *p = curproc;
- int s;
- SCHED_LOCK(s);
+ SCHED_LOCK();
setrunqueue(p->p_cpu, p, p->p_usrpri);
p->p_ru.ru_nvcsw++;
mi_switch();
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
}
/*
preempt(void)
{
struct proc *p = curproc;
- int s;
- SCHED_LOCK(s);
+ SCHED_LOCK();
setrunqueue(p->p_cpu, p, p->p_usrpri);
p->p_ru.ru_nivcsw++;
mi_switch();
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
}
void
struct proc *nextproc;
struct process *pr = p->p_p;
struct timespec ts;
- int oldipl, s;
+ int oldipl;
#ifdef MULTIPROCESSOR
int hold_count;
#endif
/* Restore proc's IPL. */
MUTEX_OLDIPL(&sched_lock) = oldipl;
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
SCHED_ASSERT_UNLOCKED();
if (hold_count)
__mp_acquire_count(&kernel_lock, hold_count);
#endif
- SCHED_LOCK(s);
+ SCHED_LOCK();
}
/*
struct cpu_info *ci = curcpu();
struct schedstate_percpu *spc = &ci->ci_schedstate;
uint32_t newcpu;
- int s;
if (p == spc->spc_idleproc || spc->spc_spinning)
return;
- SCHED_LOCK(s);
+ SCHED_LOCK();
newcpu = ESTCPULIM(p->p_estcpu + 1);
setpriority(p, newcpu, p->p_p->ps_nice);
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
}
void (*cpu_setperf)(int);
-/* $OpenBSD: sys_process.c,v 1.97 2024/04/02 08:27:22 deraadt Exp $ */
+/* $OpenBSD: sys_process.c,v 1.98 2024/06/03 12:48:25 claudio Exp $ */
/* $NetBSD: sys_process.c,v 1.55 1996/05/15 06:17:47 tls Exp $ */
/*-
struct proc *t; /* target thread */
struct process *tr; /* target process */
int error = 0;
- int s;
switch (req) {
case PT_TRACE_ME:
/* Finally, deliver the requested signal (or none). */
if (t->p_stat == SSTOP) {
tr->ps_xsig = data;
- SCHED_LOCK(s);
+ SCHED_LOCK();
unsleep(t);
setrunnable(t);
- SCHED_UNLOCK(s);
+ SCHED_UNLOCK();
} else {
if (data != 0)
psignal(t, data);
-/* $OpenBSD: sched.h,v 1.71 2024/05/29 18:55:45 claudio Exp $ */
+/* $OpenBSD: sched.h,v 1.72 2024/06/03 12:48:25 claudio Exp $ */
/* $NetBSD: sched.h,v 1.2 1999/02/28 18:14:58 ross Exp $ */
/*-
extern struct mutex sched_lock;
-#define SCHED_ASSERT_LOCKED() \
-do { \
- MUTEX_ASSERT_LOCKED(&sched_lock); \
-} while (0)
-#define SCHED_ASSERT_UNLOCKED() \
-do { \
- MUTEX_ASSERT_UNLOCKED(&sched_lock); \
-} while (0)
+#define SCHED_ASSERT_LOCKED() MUTEX_ASSERT_LOCKED(&sched_lock)
+#define SCHED_ASSERT_UNLOCKED() MUTEX_ASSERT_UNLOCKED(&sched_lock)
#define SCHED_LOCK_INIT() mtx_init(&sched_lock, IPL_SCHED)
-
-#define SCHED_LOCK(s) \
-do { \
- (s) = 0; /* XXX cleanup useless argument */ \
- mtx_enter(&sched_lock); \
-} while (/* CONSTCOND */ 0)
-
-#define SCHED_UNLOCK(s) \
-do { \
- (void)s; /* XXX cleanup useless argument */ \
- mtx_leave(&sched_lock); \
-} while (/* CONSTCOND */ 0)
+#define SCHED_LOCK() mtx_enter(&sched_lock)
+#define SCHED_UNLOCK() mtx_leave(&sched_lock)
#endif /* _KERNEL */
#endif /* _SYS_SCHED_H_ */