diff options
author | Scott Soule Cheloha <cheloha@cvs.openbsd.org> | 2023-08-23 01:55:48 +0000 |
---|---|---|
committer | Scott Soule Cheloha <cheloha@cvs.openbsd.org> | 2023-08-23 01:55:48 +0000 |
commit | 03acd21a4e00752d82ce1f3198960b52c475396e (patch) | |
tree | 12084f3273f661178be60a73087dc3b53041b423 /sys/arch | |
parent | 83fa6d388c3eec5da9f344ef9571ca741627fe5c (diff) |
all platforms: separate cpu_initclocks() from cpu_startclock()
To give the primary CPU an opportunity to perform clock interrupt
preparation in a machine-independent manner we need to separate the
"initialization" parts of cpu_initclocks() from the "start the clock
interrupt" parts. Currently, cpu_initclocks() does everything all at
once, so there is no space for this MI setup.
Many platforms have more-or-less already done this separation by
implementing a separate routine named "cpu_startclock()". This patch
promotes cpu_startclock() from de facto standard to mandatory API.
- Prototype cpu_startclock() in sys/systm.h alongside cpu_initclocks().
The separation of responsibility between the two routines is a bit
fuzzy but the basic guidelines are as follows:
+ cpu_initclocks() must initialize hz, stathz, and profhz, and call
clockintr_init().
+ cpu_startclock() must call clockintr_cpu_init() and start the clock
interrupt cycle on the calling CPU.
These guidelines will shift in the future, but that's the way things
stand as of *this* commit.
- In initclocks(): first call cpu_initclocks(), then do MI setup, and
last call cpu_startclock().
- On platforms where cpu_startclock() already exists: don't call
cpu_startclock() from cpu_initclocks() anymore.
- On platforms where cpu_startclock() doesn't yet exist: implement it.
Usually this is as simple as dividing cpu_initclocks() in two.
Tested on amd64 (i8254, lapic), arm64, i386 (i8254, lapic), macppc,
mips64/octeon, and sparc64. Tested on arm/armv7 (agtimer(4)) by
phessler@ and jmatthew@. Tested on m88k/luna88k by aoyama@. Tested
on powerpc64 by gkoehler@ and mlarkin@. Tested on riscv64 by
jmatthew@.
Thread: https://marc.info/?l=openbsd-tech&m=169195251322149&w=2
Diffstat (limited to 'sys/arch')
30 files changed, 121 insertions, 97 deletions
diff --git a/sys/arch/alpha/alpha/clock.c b/sys/arch/alpha/alpha/clock.c index c03cd35993d..dd3ad3f75b2 100644 --- a/sys/arch/alpha/alpha/clock.c +++ b/sys/arch/alpha/alpha/clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clock.c,v 1.29 2023/08/21 15:19:09 cheloha Exp $ */ +/* $OpenBSD: clock.c,v 1.30 2023/08/23 01:55:45 cheloha Exp $ */ /* $NetBSD: clock.c,v 1.29 2000/06/05 21:47:10 thorpej Exp $ */ /* @@ -192,7 +192,11 @@ cpu_initclocks(void) stathz = hz; profhz = stathz; clockintr_init(0); +} +void +cpu_startclock(void) +{ clockintr_cpu_init(NULL); /* diff --git a/sys/arch/amd64/amd64/lapic.c b/sys/arch/amd64/amd64/lapic.c index da17b0875f7..4e7182ecb5e 100644 --- a/sys/arch/amd64/amd64/lapic.c +++ b/sys/arch/amd64/amd64/lapic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lapic.c,v 1.68 2023/04/26 10:52:55 mlarkin Exp $ */ +/* $OpenBSD: lapic.c,v 1.69 2023/08/23 01:55:46 cheloha Exp $ */ /* $NetBSD: lapic.c,v 1.2 2003/05/08 01:04:35 fvdl Exp $ */ /*- @@ -499,8 +499,6 @@ lapic_initclocks(void) stathz = hz; profhz = stathz * 10; clockintr_init(CL_RNDSTAT); - - lapic_startclock(); } @@ -599,6 +597,7 @@ skip_calibration: lapic_per_second * (1ULL << 32) / 1000000000; lapic_timer_nsec_max = UINT64_MAX / lapic_timer_nsec_cycle_ratio; initclock_func = lapic_initclocks; + startclock_func = lapic_startclock; } /* diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c index 453de13fbfb..8c5f398b88c 100644 --- a/sys/arch/amd64/amd64/machdep.c +++ b/sys/arch/amd64/amd64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.286 2023/07/27 00:28:25 guenther Exp $ */ +/* $OpenBSD: machdep.c,v 1.287 2023/08/23 01:55:45 cheloha Exp $ */ /* $NetBSD: machdep.c,v 1.3 2003/05/07 22:58:18 fvdl Exp $ */ /*- @@ -227,6 +227,7 @@ paddr_t avail_end; void (*delay_func)(int) = i8254_delay; void (*initclock_func)(void) = i8254_initclocks; +void (*startclock_func)(void) = i8254_start_both_clocks; /* * Format of boot information passed to us by 32-bit /boot @@ -1881,6 +1882,12 @@ cpu_initclocks(void) } void +cpu_startclock(void) +{ + (*startclock_func)(); +} + +void need_resched(struct cpu_info *ci) { ci->ci_want_resched = 1; diff --git a/sys/arch/amd64/include/cpu.h b/sys/arch/amd64/include/cpu.h index cf322886269..9069c3df8a8 100644 --- a/sys/arch/amd64/include/cpu.h +++ b/sys/arch/amd64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.158 2023/07/27 00:28:24 guenther Exp $ */ +/* $OpenBSD: cpu.h,v 1.159 2023/08/23 01:55:46 cheloha Exp $ */ /* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $ */ /*- @@ -408,6 +408,8 @@ int amd64_pa_used(paddr_t); extern void (*cpu_idle_cycle_fcn)(void); #define cpu_idle_cycle() (*cpu_idle_cycle_fcn)() #define cpu_idle_leave() do { /* nothing */ } while (0) +extern void (*initclock_func)(void); +extern void (*startclock_func)(void); struct region_descriptor; void lgdt(struct region_descriptor *); @@ -418,7 +420,6 @@ void switch_exit(struct proc *, void (*)(struct proc *)); void proc_trampoline(void); /* clock.c */ -extern void (*initclock_func)(void); void startclocks(void); void rtcinit(void); void rtcstart(void); @@ -426,6 +427,7 @@ void rtcstop(void); void i8254_delay(int); void i8254_initclocks(void); void i8254_startclock(void); +void i8254_start_both_clocks(void); void i8254_inittimecounter(void); void i8254_inittimecounter_simple(void); diff --git a/sys/arch/amd64/isa/clock.c b/sys/arch/amd64/isa/clock.c index 019259ffdff..3dd79b1769d 100644 --- a/sys/arch/amd64/isa/clock.c +++ b/sys/arch/amd64/isa/clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clock.c,v 1.40 2023/07/25 18:16:19 cheloha Exp $ */ +/* $OpenBSD: clock.c,v 1.41 2023/08/23 01:55:46 cheloha Exp $ */ /* $NetBSD: clock.c,v 1.1 2003/04/26 18:39:50 fvdl Exp $ */ /*- @@ -284,7 +284,11 @@ i8254_initclocks(void) stathz = 128; profhz = 1024; /* XXX does not divide into 1 billion */ clockintr_init(0); +} +void +i8254_start_both_clocks(void) +{ clockintr_cpu_init(NULL); /* diff --git a/sys/arch/arm/cortex/agtimer.c b/sys/arch/arm/cortex/agtimer.c index 13b0af6f8e1..88e201abe8a 100644 --- a/sys/arch/arm/cortex/agtimer.c +++ b/sys/arch/arm/cortex/agtimer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: agtimer.c,v 1.18 2023/07/25 18:16:19 cheloha Exp $ */ +/* $OpenBSD: agtimer.c,v 1.19 2023/08/23 01:55:46 cheloha Exp $ */ /* * Copyright (c) 2011 Dale Rahn <drahn@openbsd.org> * Copyright (c) 2013 Patrick Wildt <patrick@blueri.se> @@ -227,7 +227,6 @@ void agtimer_cpu_initclocks(void) { struct agtimer_softc *sc = agtimer_cd.cd_devs[0]; - uint32_t reg; stathz = hz; profhz = stathz * 10; @@ -237,21 +236,11 @@ agtimer_cpu_initclocks(void) agtimer_set_clockrate(agtimer_frequency); } - clockintr_cpu_init(&agtimer_intrclock); - /* Setup secure and non-secure timer IRQs. */ arm_intr_establish_fdt_idx(sc->sc_node, 0, IPL_CLOCK, agtimer_intr, NULL, "tick"); arm_intr_establish_fdt_idx(sc->sc_node, 1, IPL_CLOCK, agtimer_intr, NULL, "tick"); - - reg = agtimer_get_ctrl(); - reg &= ~GTIMER_CNTP_CTL_IMASK; - reg |= GTIMER_CNTP_CTL_ENABLE; - agtimer_set_tval(INT32_MAX); - agtimer_set_ctrl(reg); - - clockintr_trigger(); } void diff --git a/sys/arch/arm/cortex/amptimer.c b/sys/arch/arm/cortex/amptimer.c index 6fcf495791c..299f9fe8c61 100644 --- a/sys/arch/arm/cortex/amptimer.c +++ b/sys/arch/arm/cortex/amptimer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: amptimer.c,v 1.17 2023/07/25 18:16:19 cheloha Exp $ */ +/* $OpenBSD: amptimer.c,v 1.18 2023/08/23 01:55:46 cheloha Exp $ */ /* * Copyright (c) 2011 Dale Rahn <drahn@openbsd.org> * @@ -301,10 +301,6 @@ amptimer_cpu_initclocks(void) /* Enable private timer counter and interrupt. */ bus_space_write_4(sc->sc_iot, sc->sc_pioh, PTIMER_CTRL, (PTIMER_CTRL_ENABLE | PTIMER_CTRL_IRQEN)); - - /* Start the clock interrupt cycle. */ - clockintr_cpu_init(&timer_intrclock); - clockintr_trigger(); } void diff --git a/sys/arch/arm/include/cpu.h b/sys/arch/arm/include/cpu.h index 986e1798cb9..1ced238694e 100644 --- a/sys/arch/arm/include/cpu.h +++ b/sys/arch/arm/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.63 2023/07/25 18:16:19 cheloha Exp $ */ +/* $OpenBSD: cpu.h,v 1.64 2023/08/23 01:55:46 cheloha Exp $ */ /* $NetBSD: cpu.h,v 1.34 2003/06/23 11:01:08 martin Exp $ */ /* @@ -329,8 +329,6 @@ intr_restore(u_long cpsr) __asm volatile ("msr cpsr_c, %0" :: "r"(cpsr)); } -void cpu_startclock(void); - #endif /* _KERNEL */ #ifdef MULTIPROCESSOR diff --git a/sys/arch/arm64/dev/agtimer.c b/sys/arch/arm64/dev/agtimer.c index 32f0688148e..14fb14f0088 100644 --- a/sys/arch/arm64/dev/agtimer.c +++ b/sys/arch/arm64/dev/agtimer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: agtimer.c,v 1.25 2023/08/11 01:28:19 cheloha Exp $ */ +/* $OpenBSD: agtimer.c,v 1.26 2023/08/23 01:55:46 cheloha Exp $ */ /* * Copyright (c) 2011 Dale Rahn <drahn@openbsd.org> * Copyright (c) 2013 Patrick Wildt <patrick@blueri.se> @@ -290,8 +290,6 @@ void agtimer_cpu_initclocks(void) { struct agtimer_softc *sc = agtimer_cd.cd_devs[0]; - uint32_t reg; - uint64_t kctl; stathz = hz; profhz = stathz * 10; @@ -304,20 +302,6 @@ agtimer_cpu_initclocks(void) /* configure virtual timer interrupt */ sc->sc_ih = arm_intr_establish_fdt_idx(sc->sc_node, 2, IPL_CLOCK|IPL_MPSAFE, agtimer_intr, NULL, "tick"); - - clockintr_cpu_init(&agtimer_intrclock); - - reg = agtimer_get_ctrl(); - reg &= ~GTIMER_CNTV_CTL_IMASK; - reg |= GTIMER_CNTV_CTL_ENABLE; - agtimer_set_tval(INT32_MAX); - agtimer_set_ctrl(reg); - - clockintr_trigger(); - - /* enable userland access to virtual counter */ - kctl = READ_SPECIALREG(CNTKCTL_EL1); - WRITE_SPECIALREG(CNTKCTL_EL1, kctl | CNTKCTL_EL0VCTEN); } void @@ -343,7 +327,8 @@ agtimer_startclock(void) uint64_t kctl; uint32_t reg; - arm_intr_route(sc->sc_ih, 1, curcpu()); + if (!CPU_IS_PRIMARY(curcpu())) + arm_intr_route(sc->sc_ih, 1, curcpu()); clockintr_cpu_init(&agtimer_intrclock); diff --git a/sys/arch/arm64/include/cpu.h b/sys/arch/arm64/include/cpu.h index ab9fdcb3758..ec514d8e4d4 100644 --- a/sys/arch/arm64/include/cpu.h +++ b/sys/arch/arm64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.38 2023/07/25 18:16:20 cheloha Exp $ */ +/* $OpenBSD: cpu.h,v 1.39 2023/08/23 01:55:46 cheloha Exp $ */ /* * Copyright (c) 2016 Dale Rahn <drahn@dalerahn.com> * @@ -344,7 +344,6 @@ intr_restore(u_long daif) } void cpu_halt(void); -void cpu_startclock(void); int cpu_suspend_primary(void); void cpu_resume_secondary(struct cpu_info *); diff --git a/sys/arch/armv7/omap/dmtimer.c b/sys/arch/armv7/omap/dmtimer.c index 2d0995112c3..985428bd6d3 100644 --- a/sys/arch/armv7/omap/dmtimer.c +++ b/sys/arch/armv7/omap/dmtimer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dmtimer.c,v 1.19 2023/07/25 18:16:19 cheloha Exp $ */ +/* $OpenBSD: dmtimer.c,v 1.20 2023/08/23 01:55:46 cheloha Exp $ */ /* * Copyright (c) 2007,2009 Dale Rahn <drahn@openbsd.org> * Copyright (c) 2013 Raphael Graf <r@undefined.ch> @@ -102,6 +102,7 @@ int dmtimer_intr(void *frame); void dmtimer_reset_tisr(void); void dmtimer_wait(int reg); void dmtimer_cpu_initclocks(void); +void dmtimer_cpu_startclock(void); void dmtimer_delay(u_int); void dmtimer_setstatclockrate(int newhz); @@ -195,7 +196,7 @@ dmtimer_attach(struct device *parent, struct device *self, void *args) dmtimer_timecounter.tc_priv = sc; tc_init(&dmtimer_timecounter); arm_clock_register(dmtimer_cpu_initclocks, dmtimer_delay, - dmtimer_setstatclockrate, NULL); + dmtimer_setstatclockrate, dmtimer_cpu_startclock); } else panic("attaching too many dmtimers at 0x%lx", @@ -247,7 +248,11 @@ dmtimer_cpu_initclocks(void) bus_space_write_4(sc->sc_iot, sc->sc_ioh[0], DM_TLDR, 0); bus_space_write_4(sc->sc_iot, sc->sc_ioh[0], DM_TIER, DM_TIER_OVF_EN); bus_space_write_4(sc->sc_iot, sc->sc_ioh[0], DM_TWER, DM_TWER_OVF_EN); +} +void +dmtimer_cpu_startclock(void) +{ /* start the clock interrupt cycle */ clockintr_cpu_init(&dmtimer_intrclock); clockintr_trigger(); diff --git a/sys/arch/armv7/omap/gptimer.c b/sys/arch/armv7/omap/gptimer.c index 6cac9de9461..72cf3e0566a 100644 --- a/sys/arch/armv7/omap/gptimer.c +++ b/sys/arch/armv7/omap/gptimer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gptimer.c,v 1.20 2023/07/25 18:16:19 cheloha Exp $ */ +/* $OpenBSD: gptimer.c,v 1.21 2023/08/23 01:55:46 cheloha Exp $ */ /* * Copyright (c) 2007,2009 Dale Rahn <drahn@openbsd.org> * @@ -99,6 +99,7 @@ void gptimer_attach(struct device *parent, struct device *self, void *args); int gptimer_intr(void *frame); void gptimer_wait(int reg); void gptimer_cpu_initclocks(void); +void gptimer_cpu_startclock(void); void gptimer_delay(u_int); void gptimer_reset_tisr(void); void gptimer_setstatclockrate(int newhz); @@ -176,7 +177,7 @@ gptimer_attach(struct device *parent, struct device *self, void *args) aa->aa_dev->mem[0].addr); arm_clock_register(gptimer_cpu_initclocks, gptimer_delay, - gptimer_setstatclockrate, NULL); + gptimer_setstatclockrate, gptimer_cpu_startclock); } int @@ -216,7 +217,11 @@ gptimer_cpu_initclocks(void) gptimer_wait(GP_TWPS_ALL); bus_space_write_4(gptimer_iot, gptimer_ioh0, GP_TWER, GP_TWER_OVF_EN); gptimer_wait(GP_TWPS_ALL); +} +void +gptimer_cpu_startclock(void) +{ /* start the clock interrupt cycle */ clockintr_cpu_init(&gptimer_intrclock); clockintr_trigger(); diff --git a/sys/arch/armv7/sunxi/sxitimer.c b/sys/arch/armv7/sunxi/sxitimer.c index 9383282e440..81b36f9c23b 100644 --- a/sys/arch/armv7/sunxi/sxitimer.c +++ b/sys/arch/armv7/sunxi/sxitimer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sxitimer.c,v 1.21 2023/07/25 18:16:19 cheloha Exp $ */ +/* $OpenBSD: sxitimer.c,v 1.22 2023/08/23 01:55:46 cheloha Exp $ */ /* * Copyright (c) 2007,2009 Dale Rahn <drahn@openbsd.org> * Copyright (c) 2013 Raphael Graf <r@undefined.ch> @@ -77,6 +77,7 @@ void sxitimer_attach(struct device *, struct device *, void *); int sxitimer_tickintr(void *); int sxitimer_statintr(void *); void sxitimer_cpu_initclocks(void); +void sxitimer_cpu_startclock(void); void sxitimer_setstatclockrate(int); uint64_t sxitimer_readcnt64(void); uint32_t sxitimer_readcnt32(void); @@ -191,7 +192,7 @@ sxitimer_attach(struct device *parent, struct device *self, void *aux) tc_init(&sxitimer_timecounter); arm_clock_register(sxitimer_cpu_initclocks, sxitimer_delay, - sxitimer_setstatclockrate, NULL); + sxitimer_setstatclockrate, sxitimer_cpu_startclock); printf(": %d kHz", sxitimer_freq[CNTRTIMER] / 1000); @@ -229,7 +230,11 @@ sxitimer_cpu_initclocks(void) bus_space_write_4(sxitimer_iot, sxitimer_ioh, TIMER_CTRL(CNTRTIMER), ctrl | TIMER_ENABLE | TIMER_RELOAD | TIMER_CONTINOUS); +} +void +sxitimer_cpu_startclock(void) +{ /* start clock interrupt cycle */ clockintr_cpu_init(&sxitimer_intrclock); clockintr_trigger(); diff --git a/sys/arch/hppa/dev/clock.c b/sys/arch/hppa/dev/clock.c index 8e5a10eb147..2bae218e3c8 100644 --- a/sys/arch/hppa/dev/clock.c +++ b/sys/arch/hppa/dev/clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clock.c,v 1.36 2023/07/25 18:16:20 cheloha Exp $ */ +/* $OpenBSD: clock.c,v 1.37 2023/08/23 01:55:46 cheloha Exp $ */ /* * Copyright (c) 1998-2003 Michael Shalayeff @@ -120,8 +120,6 @@ cpu_initclocks(void) itmr_nsec_cycle_ratio = itmr_freq * (1ULL << 32) / 1000000000; itmr_nsec_max = UINT64_MAX / itmr_nsec_cycle_ratio; - - cpu_startclock(); } void diff --git a/sys/arch/hppa/include/cpu.h b/sys/arch/hppa/include/cpu.h index 91b7de98af8..6b21bcb0742 100644 --- a/sys/arch/hppa/include/cpu.h +++ b/sys/arch/hppa/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.100 2023/07/25 18:16:20 cheloha Exp $ */ +/* $OpenBSD: cpu.h,v 1.101 2023/08/23 01:55:46 cheloha Exp $ */ /* * Copyright (c) 2000-2004 Michael Shalayeff @@ -241,7 +241,6 @@ int copy_on_fault(void); void proc_trampoline(void); int cpu_dumpsize(void); int cpu_dump(void); -void cpu_startclock(void); static inline unsigned int cpu_rnd_messybits(void) diff --git a/sys/arch/i386/i386/lapic.c b/sys/arch/i386/i386/lapic.c index fae8f71cbfc..49d9dfcfe89 100644 --- a/sys/arch/i386/i386/lapic.c +++ b/sys/arch/i386/i386/lapic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lapic.c,v 1.55 2023/02/09 01:41:15 cheloha Exp $ */ +/* $OpenBSD: lapic.c,v 1.56 2023/08/23 01:55:46 cheloha Exp $ */ /* $NetBSD: lapic.c,v 1.1.2.8 2000/02/23 06:10:50 sommerfeld Exp $ */ /*- @@ -327,8 +327,6 @@ lapic_initclocks(void) stathz = hz; profhz = stathz * 10; clockintr_init(CL_RNDSTAT); - - lapic_startclock(); } extern int gettick(void); /* XXX put in header file */ @@ -422,6 +420,7 @@ lapic_calibrate_timer(struct cpu_info *ci) lapic_per_second * (1ULL << 32) / 1000000000; lapic_timer_nsec_max = UINT64_MAX / lapic_timer_nsec_cycle_ratio; initclock_func = lapic_initclocks; + startclock_func = lapic_startclock; } /* diff --git a/sys/arch/i386/i386/machdep.c b/sys/arch/i386/i386/machdep.c index 9ce08823da5..2599def386c 100644 --- a/sys/arch/i386/i386/machdep.c +++ b/sys/arch/i386/i386/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.668 2023/08/16 09:51:39 jsg Exp $ */ +/* $OpenBSD: machdep.c,v 1.669 2023/08/23 01:55:46 cheloha Exp $ */ /* $NetBSD: machdep.c,v 1.214 1996/11/10 03:16:17 thorpej Exp $ */ /*- @@ -233,6 +233,7 @@ void (*cpusensors_setup)(struct cpu_info *); void (*delay_func)(int) = i8254_delay; void (*initclock_func)(void) = i8254_initclocks; +void (*startclock_func)(void) = i8254_start_both_clocks; /* * Extent maps to manage I/O and ISA memory hole space. Allocate @@ -3439,6 +3440,12 @@ cpu_initclocks(void) } void +cpu_startclock(void) +{ + (*startclock_func)(); +} + +void need_resched(struct cpu_info *ci) { ci->ci_want_resched = 1; diff --git a/sys/arch/i386/include/cpu.h b/sys/arch/i386/include/cpu.h index 2496ba30140..297344bace9 100644 --- a/sys/arch/i386/include/cpu.h +++ b/sys/arch/i386/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.182 2023/07/25 18:16:20 cheloha Exp $ */ +/* $OpenBSD: cpu.h,v 1.183 2023/08/23 01:55:46 cheloha Exp $ */ /* $NetBSD: cpu.h,v 1.35 1996/05/05 19:29:26 christos Exp $ */ /*- @@ -399,6 +399,9 @@ extern int i386_has_sse2; extern void (*update_cpuspeed)(void); +extern void (*initclock_func)(void); +extern void (*startclock_func)(void); + /* machdep.c */ void dumpconf(void); void cpu_reset(void); @@ -416,7 +419,6 @@ void switch_exit(struct proc *); void proc_trampoline(void); /* clock.c */ -extern void (*initclock_func)(void); void startclocks(void); void rtcinit(void); void rtcstart(void); @@ -424,6 +426,7 @@ void rtcstop(void); void i8254_delay(int); void i8254_initclocks(void); void i8254_startclock(void); +void i8254_start_both_clocks(void); void i8254_inittimecounter(void); void i8254_inittimecounter_simple(void); diff --git a/sys/arch/i386/isa/clock.c b/sys/arch/i386/isa/clock.c index 563feaabf99..630be7642a2 100644 --- a/sys/arch/i386/isa/clock.c +++ b/sys/arch/i386/isa/clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clock.c,v 1.66 2023/08/22 17:13:22 cheloha Exp $ */ +/* $OpenBSD: clock.c,v 1.67 2023/08/23 01:55:46 cheloha Exp $ */ /* $NetBSD: clock.c,v 1.39 1996/05/12 23:11:54 mycroft Exp $ */ /*- @@ -427,7 +427,11 @@ i8254_initclocks(void) stathz = 128; profhz = 1024; /* XXX does not divide into 1 billion */ clockintr_init(0); +} +void +i8254_start_both_clocks(void) +{ clockintr_cpu_init(NULL); /* diff --git a/sys/arch/luna88k/luna88k/clock.c b/sys/arch/luna88k/luna88k/clock.c index 479bf89770d..2dd6d91cae5 100644 --- a/sys/arch/luna88k/luna88k/clock.c +++ b/sys/arch/luna88k/luna88k/clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clock.c,v 1.17 2023/07/25 18:16:20 cheloha Exp $ */ +/* $OpenBSD: clock.c,v 1.18 2023/08/23 01:55:47 cheloha Exp $ */ /* $NetBSD: clock.c,v 1.2 2000/01/11 10:29:35 nisimura Exp $ */ /* @@ -139,7 +139,11 @@ cpu_initclocks() stathz = hz; profhz = stathz; clockintr_init(0); +} +void +cpu_startclock(void) +{ clockintr_cpu_init(NULL); clockinitted = 1; diff --git a/sys/arch/macppc/macppc/clock.c b/sys/arch/macppc/macppc/clock.c index 5edfb978eb2..93084b0573a 100644 --- a/sys/arch/macppc/macppc/clock.c +++ b/sys/arch/macppc/macppc/clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clock.c,v 1.55 2023/07/25 18:16:20 cheloha Exp $ */ +/* $OpenBSD: clock.c,v 1.56 2023/08/23 01:55:47 cheloha Exp $ */ /* $NetBSD: clock.c,v 1.1 1996/09/30 16:34:40 ws Exp $ */ /* @@ -147,8 +147,6 @@ decr_intr(struct clockframe *frame) (void) ppc_intr_disable(); } -void cpu_startclock(void); - void cpu_initclocks(void) { @@ -204,15 +202,13 @@ cpu_initclocks(void) evcount_attach(&clk_count, "clock", &clk_irq); - clock_initialized = 1; - cpu_startclock(); - ppc_intr_enable(intrstate); } void cpu_startclock(void) { + clock_initialized = 1; clockintr_cpu_init(&dec_intrclock); clockintr_trigger(); } diff --git a/sys/arch/mips64/include/cpu.h b/sys/arch/mips64/include/cpu.h index 4b9f1940a94..d647dbb1964 100644 --- a/sys/arch/mips64/include/cpu.h +++ b/sys/arch/mips64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.143 2023/08/05 05:46:36 guenther Exp $ */ +/* $OpenBSD: cpu.h,v 1.144 2023/08/23 01:55:47 cheloha Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -260,6 +260,7 @@ void smp_rendezvous_cpus(unsigned long, void (*)(void *), void *arg); #define CPU_BUSY_CYCLE() do {} while (0) +extern void (*md_initclock)(void); extern void (*md_startclock)(struct cpu_info *); extern void (*md_triggerclock)(void); void cp0_calibrate(struct cpu_info *); diff --git a/sys/arch/mips64/mips64/clock.c b/sys/arch/mips64/mips64/clock.c index 6badea94862..afcf68c509b 100644 --- a/sys/arch/mips64/mips64/clock.c +++ b/sys/arch/mips64/mips64/clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clock.c,v 1.50 2023/01/18 19:12:43 cheloha Exp $ */ +/* $OpenBSD: clock.c,v 1.51 2023/08/23 01:55:47 cheloha Exp $ */ /* * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -70,6 +70,7 @@ const struct intrclock cp0_intrclock = { .ic_trigger = cp0_trigger_int5_wrapper }; +void cp0_initclock(void); uint32_t cp0_int5(uint32_t, struct trapframe *); void cp0_startclock(struct cpu_info *); void cp0_trigger_int5(void); @@ -104,6 +105,7 @@ clockattach(struct device *parent, struct device *self, void *aux) /* try to avoid getting clock interrupts early */ cp0_set_compare(cp0_get_count() - 1); + md_initclock = cp0_initclock; md_startclock = cp0_startclock; md_triggerclock = cp0_trigger_int5; } @@ -232,6 +234,16 @@ cp0_trigger_int5_wrapper(void *unused) cp0_trigger_int5(); } +void +cp0_initclock(void) +{ + KASSERT(CPU_IS_PRIMARY(curcpu())); + + stathz = hz; + profhz = stathz * 10; + clockintr_init(CL_RNDSTAT); +} + /* * Start the clock interrupt dispatch cycle. */ @@ -240,11 +252,7 @@ cp0_startclock(struct cpu_info *ci) { int s; - if (CPU_IS_PRIMARY(ci)) { - stathz = hz; - profhz = stathz * 10; - clockintr_init(CL_RNDSTAT); - } else { + if (!CPU_IS_PRIMARY(ci)) { s = splhigh(); nanouptime(&ci->ci_schedstate.spc_runtime); splx(s); diff --git a/sys/arch/mips64/mips64/mips64_machdep.c b/sys/arch/mips64/mips64/mips64_machdep.c index aaa7a04a234..a8381d40291 100644 --- a/sys/arch/mips64/mips64/mips64_machdep.c +++ b/sys/arch/mips64/mips64/mips64_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mips64_machdep.c,v 1.42 2023/07/25 18:16:20 cheloha Exp $ */ +/* $OpenBSD: mips64_machdep.c,v 1.43 2023/08/23 01:55:47 cheloha Exp $ */ /* * Copyright (c) 2009, 2010, 2012 Miodrag Vallat. @@ -219,6 +219,7 @@ tlb_asid_wrap(struct cpu_info *ci) * Mips machine independent clock routines. */ +void (*md_initclock)(void); void (*md_startclock)(struct cpu_info *); void (*md_triggerclock)(void); @@ -323,11 +324,18 @@ cpu_initclocks(void) tc_init(&cp0_timecounter); } + if (md_initclock != NULL) + (*md_initclock)(); +} + +void +cpu_startclock(void) +{ #ifdef DIAGNOSTIC if (md_startclock == NULL) panic("no clock"); #endif - (*md_startclock)(ci); + (*md_startclock)(curcpu()); } void diff --git a/sys/arch/powerpc64/include/cpu.h b/sys/arch/powerpc64/include/cpu.h index b02553986a9..00f742b15af 100644 --- a/sys/arch/powerpc64/include/cpu.h +++ b/sys/arch/powerpc64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.34 2023/08/21 01:35:43 guenther Exp $ */ +/* $OpenBSD: cpu.h,v 1.35 2023/08/23 01:55:47 cheloha Exp $ */ /* * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org> @@ -153,7 +153,6 @@ curcpu(void) void cpu_kick(struct cpu_info *); void cpu_unidle(struct cpu_info *); void cpu_boot_secondary_processors(void); -void cpu_startclock(void); extern void (*ul_setperf)(int); void mp_setperf(int); diff --git a/sys/arch/powerpc64/powerpc64/clock.c b/sys/arch/powerpc64/powerpc64/clock.c index e17cdacaf1e..39cab54e93c 100644 --- a/sys/arch/powerpc64/powerpc64/clock.c +++ b/sys/arch/powerpc64/powerpc64/clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clock.c,v 1.11 2023/07/25 18:16:21 cheloha Exp $ */ +/* $OpenBSD: clock.c,v 1.12 2023/08/23 01:55:47 cheloha Exp $ */ /* * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org> @@ -53,8 +53,6 @@ static struct timecounter tb_timecounter = { .tc_user = TC_TB, }; -void cpu_startclock(void); - void dec_rearm(void *unused, uint64_t nsecs) { @@ -99,8 +97,6 @@ cpu_initclocks(void) clockintr_init(CL_RNDSTAT); evcount_attach(&clock_count, "clock", NULL); - - cpu_startclock(); } void diff --git a/sys/arch/riscv64/include/cpu.h b/sys/arch/riscv64/include/cpu.h index 7bd6c2cf998..aa1ae178f7d 100644 --- a/sys/arch/riscv64/include/cpu.h +++ b/sys/arch/riscv64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.17 2023/08/05 05:45:52 guenther Exp $ */ +/* $OpenBSD: cpu.h,v 1.18 2023/08/23 01:55:47 cheloha Exp $ */ /* * Copyright (c) 2019 Mike Larkin <mlarkin@openbsd.org> @@ -171,7 +171,6 @@ extern struct cpu_info *cpu_info_list; extern struct cpu_info *cpu_info[MAXCPUS]; void cpu_boot_secondary_processors(void); -void cpu_startclock(void); #endif /* !MULTIPROCESSOR */ diff --git a/sys/arch/riscv64/riscv64/clock.c b/sys/arch/riscv64/riscv64/clock.c index 0648a744179..cd8c8ec6da6 100644 --- a/sys/arch/riscv64/riscv64/clock.c +++ b/sys/arch/riscv64/riscv64/clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clock.c,v 1.10 2023/07/25 18:16:21 cheloha Exp $ */ +/* $OpenBSD: clock.c,v 1.11 2023/08/23 01:55:47 cheloha Exp $ */ /* * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org> @@ -56,7 +56,6 @@ static struct timecounter tb_timecounter = { .tc_user = TC_TB, }; -void cpu_startclock(void); int clock_intr(void *); void @@ -100,8 +99,6 @@ cpu_initclocks(void) evcount_attach(&clock_count, "clock", NULL); evcount_percpu(&clock_count); - - cpu_startclock(); } void diff --git a/sys/arch/sh/sh/clock.c b/sys/arch/sh/sh/clock.c index 2e3a8b62ee3..daeedf34e66 100644 --- a/sys/arch/sh/sh/clock.c +++ b/sys/arch/sh/sh/clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clock.c,v 1.15 2023/07/25 18:16:21 cheloha Exp $ */ +/* $OpenBSD: clock.c,v 1.16 2023/08/23 01:55:47 cheloha Exp $ */ /* $NetBSD: clock.c,v 1.32 2006/09/05 11:09:36 uwe Exp $ */ /*- @@ -260,7 +260,11 @@ cpu_initclocks(void) stathz = hz; profhz = stathz; clockintr_init(0); +} +void +cpu_startclock(void) +{ clockintr_cpu_init(NULL); /* diff --git a/sys/arch/sparc64/sparc64/clock.c b/sys/arch/sparc64/sparc64/clock.c index 0a27a726fc1..9255d571a2e 100644 --- a/sys/arch/sparc64/sparc64/clock.c +++ b/sys/arch/sparc64/sparc64/clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clock.c,v 1.79 2023/08/07 17:11:13 miod Exp $ */ +/* $OpenBSD: clock.c,v 1.80 2023/08/23 01:55:47 cheloha Exp $ */ /* $NetBSD: clock.c,v 1.41 2001/07/24 19:29:25 eeh Exp $ */ /* @@ -562,7 +562,11 @@ cpu_initclocks(void) for (ci = cpus; ci != NULL; ci = ci->ci_next) memcpy(&ci->ci_tickintr, &level0, sizeof(level0)); +} +void +cpu_startclock(void) +{ cpu_start_clock(); } |