diff options
author | Alan Somers <asomers@FreeBSD.org> | 2022-05-05 21:35:23 +0000 |
---|---|---|
committer | Alan Somers <asomers@FreeBSD.org> | 2022-05-06 23:25:43 +0000 |
commit | 1d2421ad8b6d508ef155752bdfc5948f7373bac3 (patch) | |
tree | 5f3230e5c053fa48b4ec682f1fa4df233b8b7fa7 /sys/kern | |
parent | 90161e72eecd463919898b4e9c1e29dbeabe139d (diff) | |
download | src-1d2421ad8b6d508ef155752bdfc5948f7373bac3.tar.gz src-1d2421ad8b6d508ef155752bdfc5948f7373bac3.zip |
Correctly measure system load averages > 1024
The old fixed-point arithmetic used for calculating load averages had an
overflow at 1024. So on systems with extremely high load, the observed
load average would actually fall back to 0 and shoot up again, creating
a kind of sawtooth graph.
Fix this by using 64-bit math internally, while still reporting the load
average to userspace as a 32-bit number.
Sponsored by: Axcient
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D35134
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_synch.c | 9 | ||||
-rw-r--r-- | sys/kern/tty_info.c | 2 |
2 files changed, 6 insertions, 5 deletions
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index e78878987b57..381d6315044c 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -87,7 +87,7 @@ struct loadavg averunnable = * Constants for averages over 1, 5, and 15 minutes * when sampling at 5 second intervals. */ -static fixpt_t cexp[3] = { +static uint64_t cexp[3] = { 0.9200444146293232 * FSCALE, /* exp(-1/12) */ 0.9834714538216174 * FSCALE, /* exp(-1/60) */ 0.9944598480048967 * FSCALE, /* exp(-1/180) */ @@ -611,14 +611,15 @@ setrunnable(struct thread *td, int srqflags) static void loadav(void *arg) { - int i, nrun; + int i; + uint64_t nrun; struct loadavg *avg; - nrun = sched_load(); + nrun = (uint64_t)sched_load(); avg = &averunnable; for (i = 0; i < 3; i++) - avg->ldavg[i] = (cexp[i] * avg->ldavg[i] + + avg->ldavg[i] = (cexp[i] * (uint64_t)avg->ldavg[i] + nrun * FSCALE * (FSCALE - cexp[i])) >> FSHIFT; /* diff --git a/sys/kern/tty_info.c b/sys/kern/tty_info.c index 60675557e4ed..237aa47a18da 100644 --- a/sys/kern/tty_info.c +++ b/sys/kern/tty_info.c @@ -302,7 +302,7 @@ tty_info(struct tty *tp) sbuf_set_drain(&sb, sbuf_tty_drain, tp); /* Print load average. */ - load = (averunnable.ldavg[0] * 100 + FSCALE / 2) >> FSHIFT; + load = ((int64_t)averunnable.ldavg[0] * 100 + FSCALE / 2) >> FSHIFT; sbuf_printf(&sb, "%sload: %d.%02d ", tp->t_column == 0 ? "" : "\n", load / 100, load % 100); |