From 96496668857abede790a486a35d42519d6c91564 Mon Sep 17 00:00:00 2001 From: cheloha Date: Thu, 27 Jul 2023 17:52:53 +0000 Subject: [PATCH] sched_init_cpu: move profclock staggering to clockintr_cpu_init() initclocks() runs after sched_init_cpu() is called for secondary CPUs, so profclock_period is still zero and the clockintr_stagger() call for spc_profclock is useless. For now, just stagger spc_profclock during clockintr_cpu_init() along with everything else. --- sys/kern/kern_clockintr.c | 14 +++++++++++++- sys/kern/kern_sched.c | 4 +--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/sys/kern/kern_clockintr.c b/sys/kern/kern_clockintr.c index 9a9d912f109..0853b10d7f3 100644 --- a/sys/kern/kern_clockintr.c +++ b/sys/kern/kern_clockintr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_clockintr.c,v 1.28 2023/07/25 18:16:19 cheloha Exp $ */ +/* $OpenBSD: kern_clockintr.c,v 1.29 2023/07/27 17:52:53 cheloha Exp $ */ /* * Copyright (c) 2003 Dale Rahn * Copyright (c) 2020 Mark Kettenis @@ -24,7 +24,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -104,6 +106,7 @@ clockintr_cpu_init(const struct intrclock *ic) uint64_t multiplier = 0; struct cpu_info *ci = curcpu(); struct clockintr_queue *cq = &ci->ci_queue; + struct schedstate_percpu *spc = &ci->ci_schedstate; int reset_cq_intrclock = 0; KASSERT(ISSET(clockintr_flags, CL_INIT)); @@ -189,6 +192,15 @@ clockintr_cpu_init(const struct intrclock *ic) clockintr_advance(cq->cq_schedclock, schedclock_period); } + /* + * XXX Need to find a better place to do this. We can't do it in + * sched_init_cpu() because initclocks() runs after it. + */ + if (spc->spc_profclock->cl_expiration == 0) { + clockintr_stagger(spc->spc_profclock, profclock_period, + multiplier, MAXCPUS); + } + if (reset_cq_intrclock) SET(cq->cq_flags, CQ_INTRCLOCK); } diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c index 064195995b6..c94438ecf09 100644 --- a/sys/kern/kern_sched.c +++ b/sys/kern/kern_sched.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sched.c,v 1.80 2023/07/25 18:16:19 cheloha Exp $ */ +/* $OpenBSD: kern_sched.c,v 1.81 2023/07/27 17:52:53 cheloha Exp $ */ /* * Copyright (c) 2007, 2008 Artur Grabowski * @@ -92,8 +92,6 @@ sched_init_cpu(struct cpu_info *ci) profclock); if (spc->spc_profclock == NULL) panic("%s: clockintr_establish profclock", __func__); - clockintr_stagger(spc->spc_profclock, profclock_period, - CPU_INFO_UNIT(ci), MAXCPUS); } kthread_create_deferred(sched_kthreads_create, ci); -- 2.20.1