summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorScott Soule Cheloha <cheloha@cvs.openbsd.org>2023-10-11 15:42:45 +0000
committerScott Soule Cheloha <cheloha@cvs.openbsd.org>2023-10-11 15:42:45 +0000
commita62a6ecf839b4fce020e73b3c346b7b50bb7671e (patch)
tree8e1e6995571f6eb28ee687c54b5f60d76c9f5f75 /sys/kern
parent3b7fa95a130954068aa13697cfa41343bdb0b10c (diff)
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.
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_clock.c13
-rw-r--r--sys/kern/sched_bsd.c4
-rw-r--r--sys/kern/subr_prof.c4
3 files changed, 11 insertions, 10 deletions
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 <sys/ktrace.h>
#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 <sys/syscallargs.h>
#include <sys/user.h>
-uint32_t profclock_period;
+uint64_t profclock_period;
#if defined(GPROF) || defined(DDBPROF)
#include <sys/malloc.h>