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/amd64 | |
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/amd64')
-rw-r--r-- | sys/arch/amd64/amd64/lapic.c | 5 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/machdep.c | 9 | ||||
-rw-r--r-- | sys/arch/amd64/include/cpu.h | 6 | ||||
-rw-r--r-- | sys/arch/amd64/isa/clock.c | 6 |
4 files changed, 19 insertions, 7 deletions
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); /* |