-/* $OpenBSD: cpu.c,v 1.47 2023/06/15 22:18:06 cheloha Exp $ */
+/* $OpenBSD: cpu.c,v 1.48 2023/10/24 13:20:09 claudio Exp $ */
/* $NetBSD: cpu.c,v 1.44 2000/05/23 05:12:53 thorpej Exp $ */
/*-
{
u_long cpu_id = cpu_number();
u_long cpumask = (1UL << cpu_id);
- int s;
/* Mark the kernel pmap active on this processor. */
atomic_setbits_ulong(&pmap_kernel()->pm_cpus, cpumask);
clockqueue_init(&ci->ci_queue);
KERNEL_LOCK();
sched_init_cpu(ci);
- nanouptime(&ci->ci_schedstate.spc_runtime);
ci->ci_curproc = ci->ci_fpcurproc = NULL;
ci->ci_randseed = (arc4random() & 0x7fffffff) + 1;
KERNEL_UNLOCK();
clockintr_cpu_init(NULL);
(void) alpha_pal_swpipl(ALPHA_PSL_IPL_0);
- SCHED_LOCK(s);
- cpu_switchto(NULL, sched_chooseproc());
+ sched_toidle();
/* NOTREACHED */
}
-/* $OpenBSD: locore.s,v 1.51 2023/01/31 15:18:51 deraadt Exp $ */
+/* $OpenBSD: locore.s,v 1.52 2023/10/24 13:20:09 claudio Exp $ */
/* $NetBSD: locore.s,v 1.94 2001/04/26 03:10:44 ross Exp $ */
/*-
* by the s2 register.
*/
LEAF(proc_trampoline, 0)
-#if defined(MULTIPROCESSOR)
- CALL(proc_trampoline_mp)
-#endif
+ CALL(proc_trampoline_mi)
mov s0, pv
mov s1, ra
mov s2, a0
-/* $OpenBSD: vm_machdep.c,v 1.51 2023/04/11 00:45:07 jsg Exp $ */
+/* $OpenBSD: vm_machdep.c,v 1.52 2023/10/24 13:20:09 claudio Exp $ */
/* $NetBSD: vm_machdep.c,v 1.55 2000/03/29 03:49:48 simonb Exp $ */
/*
up->u_pcb.pcb_context[2] = (u_int64_t)arg;
up->u_pcb.pcb_context[7] =
(u_int64_t)proc_trampoline; /* ra: assembly magic */
-#ifdef MULTIPROCESSOR
- /*
- * MULTIPROCESSOR kernels will reuse the IPL of the parent
- * process, and will lower to IPL_NONE in proc_trampoline_mp().
- */
up->u_pcb.pcb_context[8] = IPL_SCHED; /* ps: IPL */
-#else
- up->u_pcb.pcb_context[8] = IPL_NONE; /* ps: IPL */
-#endif
}
struct kmem_va_mode kv_physwait = {
-/* $OpenBSD: cpu.c,v 1.175 2023/07/31 04:01:07 guenther Exp $ */
+/* $OpenBSD: cpu.c,v 1.176 2023/10/24 13:20:09 claudio Exp $ */
/* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */
/*-
s = splhigh();
lcr8(0);
intr_enable();
-
- nanouptime(&ci->ci_schedstate.spc_runtime);
splx(s);
lapic_startclock();
- SCHED_LOCK(s);
- cpu_switchto(NULL, sched_chooseproc());
+ sched_toidle();
}
#if defined(DDB)
-/* $OpenBSD: locore.S,v 1.140 2023/07/31 04:01:07 guenther Exp $ */
+/* $OpenBSD: locore.S,v 1.141 2023/10/24 13:20:09 claudio Exp $ */
/* $NetBSD: locore.S,v 1.13 2004/03/25 18:33:17 drochner Exp $ */
/*
#endif
NENTRY(proc_trampoline)
-#ifdef MULTIPROCESSOR
- call proc_trampoline_mp
-#endif
- movl $IPL_NONE,CPUVAR(ILEVEL)
+ call proc_trampoline_mi
movq %r13,%rdi
movq %r12,%rax
call retpoline_rax
-/* $OpenBSD: cpu.c,v 1.58 2023/06/15 22:18:06 cheloha Exp $ */
+/* $OpenBSD: cpu.c,v 1.59 2023/10/24 13:20:09 claudio Exp $ */
/* $NetBSD: cpu.c,v 1.56 2004/04/14 04:01:49 bsh Exp $ */
arm_intr_cpu_enable();
cpu_startclock();
- nanouptime(&ci->ci_schedstate.spc_runtime);
-
atomic_setbits_int(&ci->ci_flags, CPUF_RUNNING);
__asm volatile("dsb sy; sev");
spllower(IPL_NONE);
- SCHED_LOCK(s);
- cpu_switchto(NULL, sched_chooseproc());
+ sched_toidle();
}
void
-/* $OpenBSD: cpuswitch7.S,v 1.17 2022/12/08 01:25:44 guenther Exp $ */
+/* $OpenBSD: cpuswitch7.S,v 1.18 2023/10/24 13:20:09 claudio Exp $ */
/* $NetBSD: cpuswitch.S,v 1.41 2003/11/15 08:44:18 scw Exp $ */
/*
ENTRY(proc_trampoline)
-#ifdef MULTIPROCESSOR
- bl proc_trampoline_mp
-#endif
- mov r0, #(IPL_NONE)
- bl _spllower
+ bl proc_trampoline_mi
mov r0, r5
mov r1, sp
-/* $OpenBSD: cpu.c,v 1.98 2023/08/10 19:29:32 kettenis Exp $ */
+/* $OpenBSD: cpu.c,v 1.99 2023/10/24 13:20:09 claudio Exp $ */
/*
* Copyright (c) 2016 Dale Rahn <drahn@dalerahn.com>
arm_intr_cpu_enable();
cpu_startclock();
- nanouptime(&ci->ci_schedstate.spc_runtime);
-
atomic_setbits_int(&ci->ci_flags, CPUF_RUNNING);
__asm volatile("dsb sy; sev" ::: "memory");
spllower(IPL_NONE);
- SCHED_LOCK(s);
- cpu_switchto(NULL, sched_chooseproc());
+ sched_toidle();
}
void
-/* $OpenBSD: cpuswitch.S,v 1.6 2022/12/08 01:25:44 guenther Exp $ */
+/* $OpenBSD: cpuswitch.S,v 1.7 2023/10/24 13:20:09 claudio Exp $ */
/*
* Copyright (c) 2015 Dale Rahn <drahn@dalerahn.com>
*
ret
ENTRY(proc_trampoline)
-#ifdef MULTIPROCESSOR
- bl proc_trampoline_mp
-#endif
- // call it or just set the variable?
- mov x0, IPL_NONE
- bl spllower
+ bl proc_trampoline_mi
mov x0, x20
blr x19
b syscall_return
-
-/* $OpenBSD: cpu.c,v 1.46 2023/08/29 16:19:34 claudio Exp $ */
+/* $OpenBSD: cpu.c,v 1.47 2023/10/24 13:20:09 claudio Exp $ */
/*
* Copyright (c) 1998-2003 Michael Shalayeff
cpu_hatch(void)
{
struct cpu_info *ci = curcpu();
- int s;
/* Initialise IPIs. */
hppa_ipi_init(ci);
while (!start_secondary_cpu)
;
- s = splhigh();
- nanouptime(&ci->ci_schedstate.spc_runtime);
- splx(s);
-
- SCHED_LOCK(s);
- cpu_switchto(NULL, sched_chooseproc());
+ sched_toidle();
}
void
-/* $OpenBSD: locore.S,v 1.204 2022/10/25 15:15:38 guenther Exp $ */
+/* $OpenBSD: locore.S,v 1.205 2023/10/24 13:20:10 claudio Exp $ */
/*
* Copyright (c) 1998-2004 Michael Shalayeff
ENTRY(proc_trampoline,0)
copy r0, r3
-#ifdef MULTIPROCESSOR
copy t4, r5
copy arg0, r4
- bl proc_trampoline_mp, rp
+ bl proc_trampoline_mi, rp
nop
copy r4, arg0
copy r5, t4
-#endif
- mfctl cr29, t1
- stw r0, CI_CPL(t1)
.call
blr r0, rp
bv,n r0(t4)
-/* $OpenBSD: cpu.c,v 1.113 2023/07/21 04:04:52 guenther Exp $ */
+/* $OpenBSD: cpu.c,v 1.114 2023/10/24 13:20:10 claudio Exp $ */
/* $NetBSD: cpu.c,v 1.1.2.7 2000/06/26 02:04:05 sommerfeld Exp $ */
/*-
if (mp_verbose)
printf("%s: CPU at apid %ld running\n",
ci->ci_dev->dv_xname, ci->ci_cpuid);
- nanouptime(&ci->ci_schedstate.spc_runtime);
splx(s);
lapic_startclock();
- SCHED_LOCK(s);
- cpu_switchto(NULL, sched_chooseproc());
+ sched_toidle();
}
void
-/* $OpenBSD: locore.s,v 1.201 2023/04/16 05:40:25 guenther Exp $ */
+/* $OpenBSD: locore.s,v 1.202 2023/10/24 13:20:10 claudio Exp $ */
/* $NetBSD: locore.s,v 1.145 1996/05/03 19:41:19 christos Exp $ */
/*-
.text
NENTRY(proc_trampoline)
-#ifdef MULTIPROCESSOR
- call proc_trampoline_mp
-#endif
- movl $IPL_NONE,CPL
+ call proc_trampoline_mi
pushl %ebx
call *%esi
addl $4,%esp
-/* $OpenBSD: machdep.c,v 1.100 2022/08/10 12:20:05 miod Exp $ */
+/* $OpenBSD: machdep.c,v 1.101 2023/10/24 13:20:10 claudio Exp $ */
/*
* Copyright (c) 2009, 2010, 2014 Miodrag Vallat.
void
hw_cpu_hatch(struct cpu_info *ci)
{
- int s;
-
/*
* Set curcpu address on this processor.
*/
spl0();
(void)updateimask(0);
- SCHED_LOCK(s);
- cpu_switchto(NULL, sched_chooseproc());
+ sched_toidle();
}
void
-/* $OpenBSD: machdep.c,v 1.143 2023/06/15 22:18:07 cheloha Exp $ */
+/* $OpenBSD: machdep.c,v 1.144 2023/10/24 13:20:10 claudio Exp $ */
/*
* Copyright (c) 1998, 1999, 2000, 2001 Steve Murphree, Jr.
* Copyright (c) 1996 Nivas Madhur
secondary_main()
{
struct cpu_info *ci = curcpu();
- int s;
cpu_configuration_print(0);
ncpus++;
clockqueue_init(&ci->ci_queue);
sched_init_cpu(ci);
- nanouptime(&ci->ci_schedstate.spc_runtime);
ci->ci_curproc = NULL;
ci->ci_randseed = (arc4random() & 0x7fffffff) + 1;
clockintr_cpu_init(NULL);
spl0();
- SCHED_LOCK(s);
set_psr(get_psr() & ~PSR_IND);
SET(ci->ci_flags, CIF_ALIVE);
- cpu_switchto(NULL, sched_chooseproc());
+ sched_toidle();
}
#endif /* MULTIPROCESSOR */
-/* $OpenBSD: eh_common.S,v 1.64 2022/12/06 18:50:59 guenther Exp $ */
+/* $OpenBSD: eh_common.S,v 1.65 2023/10/24 13:20:10 claudio Exp $ */
/*
* Mach Operating System
* Copyright (c) 1993-1991 Carnegie Mellon University
*/
ENTRY(proc_trampoline)
-#ifdef MULTIPROCESSOR
- bsr proc_trampoline_mp
-#endif
-
- bsr.n setipl /* setipl(IPL_NONE) */
- or %r2, %r0, %r0
+ bsr proc_trampoline_mi
ld %r1, %r31, 0 /* load func */
ld %r2, %r31, 4 /* load arg */
-/* $OpenBSD: cpu.c,v 1.86 2023/06/15 22:18:07 cheloha Exp $ */
+/* $OpenBSD: cpu.c,v 1.87 2023/10/24 13:20:10 claudio Exp $ */
/*
* Copyright (c) 1997 Per Fogelstrom
cpu_hatch(void)
{
volatile struct cpu_hatch_data *h = cpu_hatch_data;
- int intrstate, s;
+ int intrstate;
/* Initialize timebase. */
ppc_mttb(0);
curcpu()->ci_ipending = 0;
curcpu()->ci_cpl = 0;
- s = splhigh();
- nanouptime(&curcpu()->ci_schedstate.spc_runtime);
- splx(s);
-
intrstate = ppc_intr_disable();
cpu_startclock();
ppc_intr_enable(intrstate);
/* Enable inter-processor interrupts. */
openpic_set_priority(curcpu()->ci_cpuid, 14);
- SCHED_LOCK(s);
- cpu_switchto(NULL, sched_chooseproc());
+ sched_toidle();
}
#endif
-/* $OpenBSD: locore.S,v 1.61 2022/12/08 01:25:45 guenther Exp $ */
+/* $OpenBSD: locore.S,v 1.62 2023/10/24 13:20:10 claudio Exp $ */
/* $NetBSD: locore.S,v 1.2 1996/10/16 19:33:09 ws Exp $ */
/*
.globl proc_trampoline
.type proc_trampoline,@function
proc_trampoline:
-#ifdef MULTIPROCESSOR
- bl proc_trampoline_mp
-#endif
- li %r3,0
- bl lcsplx
+ bl proc_trampoline_mi
mtlr %r31
mr %r3,%r30
blrl /* jump indirect to r31 */
-/* $OpenBSD: machdep.c,v 1.199 2022/10/30 17:43:39 guenther Exp $ */
+/* $OpenBSD: machdep.c,v 1.200 2023/10/24 13:20:10 claudio Exp $ */
/* $NetBSD: machdep.c,v 1.4 1996/10/16 19:33:11 ws Exp $ */
/*
int pwr_action = 1;
void dumpsys(void);
-int lcsplx(int ipl); /* called from LCore */
void *ppc_intr_establish(void *lcv, pci_intr_handle_t ih, int type,
int level, int (*func)(void *), void *arg, const char *name);
}
-int
-lcsplx(int ipl)
-{
- return spllower(ipl);
-}
-
/*
* Halt or reboot the machine after syncing/dumping according to howto.
*/
-/* $OpenBSD: clock.c,v 1.53 2023/09/17 14:50:51 cheloha Exp $ */
+/* $OpenBSD: clock.c,v 1.54 2023/10/24 13:20:10 claudio Exp $ */
/*
* Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com)
int s;
if (!CPU_IS_PRIMARY(ci)) {
- s = splhigh();
- nanouptime(&ci->ci_schedstate.spc_runtime);
- splx(s);
-
/* try to avoid getting clock interrupts early */
cp0_set_compare(cp0_get_count() - 1);
-/* $OpenBSD: context.S,v 1.65 2023/08/05 05:46:36 guenther Exp $ */
+/* $OpenBSD: context.S,v 1.66 2023/10/24 13:20:10 claudio Exp $ */
/*
* Copyright (c) 2002-2003 Opsycon AB (www.opsycon.se / www.opsycon.com)
#ifdef DDB
move zero, ra
#endif
-#ifdef MULTIPROCESSOR
- jal proc_trampoline_mp
+ jal proc_trampoline_mi
NOP
-#endif
- /*
- * Enable interrupts, since we want kernel threads to
- * start at spl0 and with interrupts enabled, and these
- * won't ``return to userland''.
- */
-#ifndef MULTIPROCESSOR /* done by proc_trampoline_mp() */
- jal splx
- xor a0, a0
-#endif
jal updateimask # Make sure SR imask is updated
xor a0, a0 # and interrupts enabled
-/* $OpenBSD: machdep.c,v 1.136 2023/02/04 19:19:36 cheloha Exp $ */
+/* $OpenBSD: machdep.c,v 1.137 2023/10/24 13:20:10 claudio Exp $ */
/*
* Copyright (c) 2009, 2010 Miodrag Vallat.
void
hw_cpu_hatch(struct cpu_info *ci)
{
- int s;
-
/*
* Set curcpu address on this processor.
*/
spl0();
(void)updateimask(0);
- SCHED_LOCK(s);
- cpu_switchto(NULL, sched_chooseproc());
+ sched_toidle();
}
#endif /* MULTIPROCESSOR */
-/* $OpenBSD: cpu.c,v 1.27 2023/08/19 00:47:51 gkoehler Exp $ */
+/* $OpenBSD: cpu.c,v 1.28 2023/10/24 13:20:10 claudio Exp $ */
/*
* Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
s = splhigh();
cpu_startclock();
- nanouptime(&ci->ci_schedstate.spc_runtime);
-
atomic_setbits_int(&ci->ci_flags, CPUF_RUNNING);
membar_sync();
spllower(IPL_NONE);
- SCHED_LOCK(s);
- cpu_switchto(NULL, sched_chooseproc());
+ sched_toidle();
}
void
-/* $OpenBSD: locore.S,v 1.45 2023/08/21 01:35:43 guenther Exp $ */
+/* $OpenBSD: locore.S,v 1.46 2023/10/24 13:20:10 claudio Exp $ */
/*
* Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
.globl proc_trampoline
.type proc_trampoline, @function
proc_trampoline:
-#ifdef MULTIPROCESSOR
- bl proc_trampoline_mp
-#endif
- li %r3, IPL_NONE
- bl splx
+ bl proc_trampoline_mi
mr %r12, %r31
mr %r3, %r30
mtctr %r12
-/* $OpenBSD: cpu.c,v 1.15 2023/09/19 19:20:33 kettenis Exp $ */
+/* $OpenBSD: cpu.c,v 1.16 2023/10/24 13:20:10 claudio Exp $ */
/*
* Copyright (c) 2016 Dale Rahn <drahn@dalerahn.com>
csr_clear(sstatus, SSTATUS_FS_MASK);
csr_set(sie, SIE_SSIE);
- nanouptime(&ci->ci_schedstate.spc_runtime);
-
atomic_setbits_int(&ci->ci_flags, CPUF_RUNNING);
membar_producer();
spllower(IPL_NONE);
intr_enable();
- SCHED_LOCK(s);
- cpu_switchto(NULL, sched_chooseproc());
+ sched_toidle();
}
void
-/* $OpenBSD: cpuswitch.S,v 1.7 2022/12/02 12:27:08 jca Exp $ */
+/* $OpenBSD: cpuswitch.S,v 1.8 2023/10/24 13:20:10 claudio Exp $ */
/*
* Copyright (c) 2015 Dale Rahn <drahn@dalerahn.com>
END(cpu_switch_asm)
ENTRY(proc_trampoline)
-#ifdef MULTIPROCESSOR
- la t0, proc_trampoline_mp
- jalr t0
-#endif
- // call it or just set the variable?
- li a0, IPL_NONE
- la t0, spllower
+ la t0, proc_trampoline_mi
jalr t0
mv a0, s2
jalr s1
-/* $OpenBSD: locore_subr.S,v 1.16 2023/08/14 07:40:08 miod Exp $ */
+/* $OpenBSD: locore_subr.S,v 1.17 2023/10/24 13:20:10 claudio Exp $ */
/* $NetBSD: locore_subr.S,v 1.28 2006/01/23 22:52:09 uwe Exp $ */
/*
* respectively. set by cpu_fork().
*/
NENTRY(proc_trampoline)
+ mov.l .L_proc_trampoline_mi, r1
+ jsr @r1 /* proc_trampoline_mi() */
+ nop
jsr @r12
mov r11, r4
__EXCEPTION_RETURN
/* NOTREACHED */
+.L_proc_trampoline_mi:
+ .long proc_trampoline_mi
SET_ENTRY_SIZE(proc_trampoline)
-/* $OpenBSD: vm_machdep.c,v 1.17 2022/05/27 18:55:30 kettenis Exp $ */
+/* $OpenBSD: vm_machdep.c,v 1.18 2023/10/24 13:20:10 claudio Exp $ */
/* $NetBSD: vm_machdep.c,v 1.53 2006/08/31 16:49:21 matt Exp $ */
/*
* Enable interrupt when switch frame is restored, since
* kernel thread begin to run without restoring trapframe.
*/
- sf->sf_sr = PSL_MD; /* kernel mode, interrupt enable */
+ sf->sf_sr = PSL_MD | /* kernel mode, interrupt enable */
+ (IPL_SCHED << 4);
#ifdef SH4
if (CPU_IS_SH4) {
-/* $OpenBSD: cpu.c,v 1.74 2023/06/15 22:18:08 cheloha Exp $ */
+/* $OpenBSD: cpu.c,v 1.75 2023/10/24 13:20:10 claudio Exp $ */
/* $NetBSD: cpu.c,v 1.13 2001/05/26 21:27:15 chs Exp $ */
/*
cpu_hatch(void)
{
struct cpu_info *ci = curcpu();
- int s;
cpu_init(ci);
ci->ci_flags |= CPUF_RUNNING;
membar_sync();
- s = splhigh();
- nanouptime(&ci->ci_schedstate.spc_runtime);
- splx(s);
-
cpu_start_clock();
- SCHED_LOCK(s);
- cpu_switchto(NULL, sched_chooseproc());
+ sched_toidle();
}
#endif
-/* $OpenBSD: locore.s,v 1.201 2023/04/28 18:27:55 cheloha Exp $ */
+/* $OpenBSD: locore.s,v 1.202 2023/10/24 13:20:11 claudio Exp $ */
/* $NetBSD: locore.s,v 1.137 2001/08/13 06:10:10 jdolecek Exp $ */
/*
/*
* cpu_set_kpc() and cpu_fork() arrange for proc_trampoline() to run
- * after after a process gets chosen in switch(). The stack frame will
+ * after a process gets chosen in mi_switch(). The stack frame will
* contain a function pointer in %l0, and an argument to pass to it in %l2.
*
* If the function *(%l0) returns, we arrange for an immediate return
* and when returning a child to user mode after a fork(2).
*/
ENTRY(proc_trampoline)
-#ifdef MULTIPROCESSOR
save %sp, -CC64FSZ, %sp
- call proc_trampoline_mp
+ call proc_trampoline_mi
nop
restore
-#endif
- wrpr %g0, 0, %pil ! Reset interrupt level
call %l0 ! re-use current frame
mov %l1, %o0
-/* $OpenBSD: kern_fork.c,v 1.252 2023/09/13 14:25:49 claudio Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.253 2023/10/24 13:20:11 claudio Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
#include <sys/acct.h>
#include <sys/ktrace.h>
#include <sys/sched.h>
+#include <sys/smr.h>
#include <sys/sysctl.h>
#include <sys/pool.h>
#include <sys/mman.h>
oldpids[idx++ % nitems(oldpids)] = pid;
}
-#if defined(MULTIPROCESSOR)
-/*
- * XXX This is a slight hack to get newly-formed processes to
- * XXX acquire the kernel lock as soon as they run.
- */
+/* Do machine independent parts of switching to a new process */
void
-proc_trampoline_mp(void)
+proc_trampoline_mi(void)
{
+ struct schedstate_percpu *spc = &curcpu()->ci_schedstate;
+ struct proc *p = curproc;
+
SCHED_ASSERT_LOCKED();
+
+ clear_resched(curcpu());
+
+#if defined(MULTIPROCESSOR)
__mp_unlock(&sched_lock);
+#endif
spl0();
+
SCHED_ASSERT_UNLOCKED();
KERNEL_ASSERT_UNLOCKED();
+ assertwaitok();
+ smr_idle();
+
+ /* Start any optional clock interrupts needed by the thread. */
+ if (ISSET(p->p_p->ps_flags, PS_ITIMER)) {
+ atomic_setbits_int(&spc->spc_schedflags, SPCF_ITIMER);
+ clockintr_advance(spc->spc_itimer, hardclock_period);
+ }
+ if (ISSET(p->p_p->ps_flags, PS_PROFIL)) {
+ atomic_setbits_int(&spc->spc_schedflags, SPCF_PROFCLOCK);
+ clockintr_advance(spc->spc_profclock, profclock_period);
+ }
+ nanouptime(&spc->spc_runtime);
KERNEL_LOCK();
}
-#endif
-/* $OpenBSD: kern_sched.c,v 1.92 2023/09/19 11:31:51 claudio Exp $ */
+/* $OpenBSD: kern_sched.c,v 1.93 2023/10/24 13:20:11 claudio Exp $ */
/*
* Copyright (c) 2007, 2008 Artur Grabowski <art@openbsd.org>
*
*/
void
sched_exit(struct proc *p)
+{
+ struct schedstate_percpu *spc = &curcpu()->ci_schedstate;
+
+ LIST_INSERT_HEAD(&spc->spc_deadproc, p, p_hash);
+
+ KERNEL_ASSERT_LOCKED();
+ sched_toidle();
+}
+
+void
+sched_toidle(void)
{
struct schedstate_percpu *spc = &curcpu()->ci_schedstate;
struct proc *idle;
int s;
+#ifdef MULTIPROCESSOR
+ /* This process no longer needs to hold the kernel lock. */
+ if (_kernel_lock_held())
+ __mp_release_all(&kernel_lock);
+#endif
+
if (ISSET(spc->spc_schedflags, SPCF_ITIMER)) {
atomic_clearbits_int(&spc->spc_schedflags, SPCF_ITIMER);
clockintr_cancel(spc->spc_itimer);
clockintr_cancel(spc->spc_profclock);
}
- LIST_INSERT_HEAD(&spc->spc_deadproc, p, p_hash);
-
-#ifdef MULTIPROCESSOR
- /* This process no longer needs to hold the kernel lock. */
- KERNEL_ASSERT_LOCKED();
- __mp_release_all(&kernel_lock);
-#endif
+ atomic_clearbits_int(&spc->spc_schedflags, SPCF_SWITCHCLEAR);
SCHED_LOCK(s);
+
idle = spc->spc_idleproc;
idle->p_stat = SRUN;
+
+ uvmexp.swtch++;
+ TRACEPOINT(sched, off__cpu, idle->p_tid + THREAD_PID_OFFSET,
+ idle->p_p->ps_pid);
cpu_switchto(NULL, idle);
panic("cpu_switchto returned");
}
}
}
p = spc->spc_idleproc;
- KASSERT(p);
- KASSERT(p->p_wchan == NULL);
+ if (p == NULL)
+ panic("no idleproc set on CPU%d",
+ CPU_INFO_UNIT(curcpu()));
p->p_stat = SRUN;
+ KASSERT(p->p_wchan == NULL);
return (p);
}
+again:
#endif
-again:
if (spc->spc_whichqs) {
queue = ffs(spc->spc_whichqs) - 1;
p = TAILQ_FIRST(&spc->spc_qs[queue]);
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) {
- int s;
- /*
- * We get here if someone decides to switch during
- * boot before forking kthreads, bleh.
- * This is kind of like a stupid idle loop.
- */
-#ifdef MULTIPROCESSOR
- __mp_unlock(&sched_lock);
-#endif
- spl0();
- delay(10);
- SCHED_LOCK(s);
- goto again;
- }
- KASSERT(p);
+ if (p == NULL)
+ panic("no idleproc set on CPU%d",
+ CPU_INFO_UNIT(curcpu()));
p->p_stat = SRUN;
}
-/* $OpenBSD: sched.h,v 1.66 2023/10/17 00:04:02 cheloha Exp $ */
+/* $OpenBSD: sched.h,v 1.67 2023/10/24 13:20:11 claudio Exp $ */
/* $NetBSD: sched.h,v 1.2 1999/02/28 18:14:58 ross Exp $ */
/*-
void sched_init_cpu(struct cpu_info *);
void sched_idle(void *);
void sched_exit(struct proc *);
+void sched_toidle(void);
void mi_switch(void);
void cpu_switchto(struct proc *, struct proc *);
struct proc *sched_chooseproc(void);