From: cheloha Date: Wed, 11 Oct 2023 15:42:44 +0000 (+0000) Subject: kernel: expand fixed clock interrupt periods to 64-bit values X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=961828bc194f896bc07775e50bbcc83db3211c21;p=openbsd kernel: expand fixed clock interrupt periods to 64-bit values Technically, all the current fixed clock interrupt periods fit within an unsigned 32-bit value. But 32-bit multiplication is an accident waiting to happen. So, expand the fixed periods for hardclock, statclock, profclock, and roundrobin to 64-bit values. One exception: statclock_mask remains 32-bit because random(9) yields 32-bit values. Update the initclocks() comment to make it clear that this is not an accident. --- diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index 22c62f1f064..d11ac4fe901 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_clock.c,v 1.119 2023/09/14 22:27:09 cheloha Exp $ */ +/* $OpenBSD: kern_clock.c,v 1.120 2023/10/11 15:42:44 cheloha Exp $ */ /* $NetBSD: kern_clock.c,v 1.34 1996/06/09 04:51:03 briggs Exp $ */ /*- @@ -87,9 +87,9 @@ int ticks = INT_MAX - (15 * 60 * HZ); /* Don't force early wrap around, triggers bug in inteldrm */ volatile unsigned long jiffies; -uint32_t hardclock_period; /* [I] hardclock period (ns) */ -uint32_t statclock_avg; /* [I] average statclock period (ns) */ -uint32_t statclock_min; /* [I] minimum statclock period (ns) */ +uint64_t hardclock_period; /* [I] hardclock period (ns) */ +uint64_t statclock_avg; /* [I] average statclock period (ns) */ +uint64_t statclock_min; /* [I] minimum statclock period (ns) */ uint32_t statclock_mask; /* [I] set of allowed offsets */ int statclock_is_randomized; /* [I] fixed or pseudorandom period? */ @@ -99,7 +99,8 @@ int statclock_is_randomized; /* [I] fixed or pseudorandom period? */ void initclocks(void) { - uint32_t half_avg, var; + uint64_t half_avg; + uint32_t var; /* * Let the machine-specific code do its bit. @@ -114,7 +115,7 @@ initclocks(void) /* * Compute the average statclock() period. Then find var, the - * largest power of two such that var <= statclock_avg / 2. + * largest 32-bit power of two such that var <= statclock_avg / 2. */ statclock_avg = 1000000000 / stathz; half_avg = statclock_avg / 2; diff --git a/sys/kern/sched_bsd.c b/sys/kern/sched_bsd.c index 92989846eb2..8f1db1ec3b0 100644 --- a/sys/kern/sched_bsd.c +++ b/sys/kern/sched_bsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sched_bsd.c,v 1.87 2023/09/17 13:02:24 cheloha Exp $ */ +/* $OpenBSD: sched_bsd.c,v 1.88 2023/10/11 15:42:44 cheloha Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /*- @@ -54,7 +54,7 @@ #include #endif -uint32_t roundrobin_period; /* [I] roundrobin period (ns) */ +uint64_t roundrobin_period; /* [I] roundrobin period (ns) */ int lbolt; /* once a second sleep address */ #ifdef MULTIPROCESSOR diff --git a/sys/kern/subr_prof.c b/sys/kern/subr_prof.c index b6308905dd9..52292b30481 100644 --- a/sys/kern/subr_prof.c +++ b/sys/kern/subr_prof.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_prof.c,v 1.38 2023/09/10 03:08:05 cheloha Exp $ */ +/* $OpenBSD: subr_prof.c,v 1.39 2023/10/11 15:42:44 cheloha Exp $ */ /* $NetBSD: subr_prof.c,v 1.12 1996/04/22 01:38:50 christos Exp $ */ /*- @@ -44,7 +44,7 @@ #include #include -uint32_t profclock_period; +uint64_t profclock_period; #if defined(GPROF) || defined(DDBPROF) #include diff --git a/sys/sys/resourcevar.h b/sys/sys/resourcevar.h index fcbd990fcb3..b8dff124920 100644 --- a/sys/sys/resourcevar.h +++ b/sys/sys/resourcevar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: resourcevar.h,v 1.29 2023/09/10 03:08:05 cheloha Exp $ */ +/* $OpenBSD: resourcevar.h,v 1.30 2023/10/11 15:42:44 cheloha Exp $ */ /* $NetBSD: resourcevar.h,v 1.12 1995/11/22 23:01:53 cgd Exp $ */ /* @@ -62,7 +62,7 @@ do { \ struct clockintr; -extern uint32_t profclock_period; +extern uint64_t profclock_period; void addupc_intr(struct proc *, u_long, u_long); void addupc_task(struct proc *, u_long, u_int); diff --git a/sys/sys/sched.h b/sys/sys/sched.h index a54a8f77e1d..6f4cbb66aef 100644 --- a/sys/sys/sched.h +++ b/sys/sys/sched.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sched.h,v 1.64 2023/09/14 22:07:11 cheloha Exp $ */ +/* $OpenBSD: sched.h,v 1.65 2023/10/11 15:42:44 cheloha Exp $ */ /* $NetBSD: sched.h,v 1.2 1999/02/28 18:14:58 ross Exp $ */ /*- @@ -146,7 +146,7 @@ struct cpustats { #define NICE_WEIGHT 2 /* priorities per nice level */ #define ESTCPULIM(e) min((e), NICE_WEIGHT * PRIO_MAX - SCHED_PPQ) -extern uint32_t roundrobin_period; +extern uint64_t roundrobin_period; struct proc; void schedclock(struct proc *); diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 868cd688431..42a1c9ffac6 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -1,4 +1,4 @@ -/* $OpenBSD: systm.h,v 1.167 2023/09/14 20:58:51 cheloha Exp $ */ +/* $OpenBSD: systm.h,v 1.168 2023/10/11 15:42:44 cheloha Exp $ */ /* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */ /*- @@ -233,8 +233,8 @@ int tvtohz(const struct timeval *); int tstohz(const struct timespec *); void realitexpire(void *); -extern uint32_t hardclock_period; -extern uint32_t statclock_avg; +extern uint64_t hardclock_period; +extern uint64_t statclock_avg; extern int statclock_is_randomized; struct clockframe;