From nobody Mon May 23 19:11:51 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 458ED1B3DE2D; Mon, 23 May 2022 19:11:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4L6RlX0Z1Cz3nM2; Mon, 23 May 2022 19:11:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653333112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=KcJB8IYsnjnqSy2X+jBhz8cNK2mQCLj9eNjjBLQfUF8=; b=yIHmo9LmWtXrCgucPgcAThF0CMvilCc8OdNQIqCjxrA8HFz3+mE2WlgpqB6CfQUPIiYnoU TL/EhvvyLDeUR6GVnLzc69sZE1/VUDEo28Hvbb52dweflzTCstEr1o+rpZ3pgiiu/5NaEQ 7LZnZafZDDQbDds/4qr9vsSLBel8DIOVf1h1rowyflvrgneSVDSu/G10s89PaLypYPlLuy xeYuP5ZHSFl1NILiSm9KQ/T8esLHRzxWmpYqsgI0teRtJv7QiOkDRNb2iKP3DX/kpBiQaS kyoAOcVmGnKIjv0zahllmeuxxeaI8j8l9E8uWs3n1ylA5ZzqefiVuMS81Z214g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id BEF1915A9B; Mon, 23 May 2022 19:11:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 24NJBpVw054176; Mon, 23 May 2022 19:11:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24NJBpQ8054175; Mon, 23 May 2022 19:11:51 GMT (envelope-from git) Date: Mon, 23 May 2022 19:11:51 GMT Message-Id: <202205231911.24NJBpQ8054175@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alan Somers Subject: git: dee01da58a27 - stable/13 - Correctly measure system load averages > 1024 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asomers X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: dee01da58a275b1cdc21b6211b26223968431449 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653333112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=KcJB8IYsnjnqSy2X+jBhz8cNK2mQCLj9eNjjBLQfUF8=; b=TdsGRc4QwO21Ww/KjBw5++4cMDErqgEl5vEcoFa0HSg9S9FJJdBdfT6/gDx6Q9tvxoberx nR6UJDj+KytEu8xvhhttKG5K2QSAbHbW+jtuCs0XaZ9FUoYli2iu7TzLslg9mMG+4QPfF7 9gC+IfQDXrkZk5LAoEMuCdzR5+dJlz4L9zdRvO8KMe85sRCvNDaOq+KA14EYQHcUk1579a p0e3SqMrD33rhLPl1i1qOEFqZoOhKkFMJsUhsgxhaY9K1lqFGBPUM9tD8GuzICo6VG7jrS ga+PWteVbWRGboQ71v1gZfmsggSwMRaIM8jDftsDlAz2uBnTMBMYktFfQRwawQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1653333112; a=rsa-sha256; cv=none; b=m6ZxICzp0P5brBG96MP5T1gQRrnFj+8H2hLvH7tsWlj58H6o3Ac1+s0rcqBE8uhescHnJA 9VkKIo+org6qPPhABLdRA3+hMs6LBWeQ/kZnsQycbUnenvqUVLDx8ZoRHkj4Db+TZlK1yg JKSPvZJPEbWmMLFSKZgUzskVU37PeXT7WsHMinDyX2u7rsRUeVwV54Fp2vSRkXf3ZHUQ2e YdomLItE6Gi9jYie113tp3rw1pM5nIhERF656bBuFYCJaohgXTqGnNKUMJo5s0CKQrfMpn SFWbuCFQrAkximaqO4fiYE3gwM4PZ0XV5Q34kuNcsEfHyq39Q1pSnqcmc+Re5w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=dee01da58a275b1cdc21b6211b26223968431449 commit dee01da58a275b1cdc21b6211b26223968431449 Author: Alan Somers AuthorDate: 2022-05-05 21:35:23 +0000 Commit: Alan Somers CommitDate: 2022-05-23 19:11:23 +0000 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 (cherry picked from commit 1d2421ad8b6d508ef155752bdfc5948f7373bac3) --- sys/kern/kern_synch.c | 9 +++++---- sys/kern/tty_info.c | 2 +- sys/sys/param.h | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 88f47ba78601..5abc38d64296 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) */ @@ -610,14 +610,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); diff --git a/sys/sys/param.h b/sys/sys/param.h index a0f1b9f7945b..24011244449e 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -343,12 +343,12 @@ __END_DECLS * Scale factor for scaled integers used to count %cpu time and load avgs. * * The number of CPU `tick's that map to a unique `%age' can be expressed - * by the formula (1 / (2 ^ (FSHIFT - 11))). The maximum load average that - * can be calculated (assuming 32 bits) can be closely approximated using - * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15). + * by the formula (1 / (2 ^ (FSHIFT - 11))). Since the intermediate + * calculation is done with 64-bit precision, the maximum load average that can + * be calculated is approximately 2^32 / FSCALE. * * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age', - * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024. + * FSHIFT must be at least 11. This gives a maximum load avg of 2 million. */ #define FSHIFT 11 /* bits to right of fixed binary point */ #define FSCALE (1<