From nobody Sat May 07 00:04:44 2022 X-Original-To: dev-commits-src-main@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 7385C1AC341D; Sat, 7 May 2022 00:04:45 +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 4Kw73K2Xgvz3wWm; Sat, 7 May 2022 00:04:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651881885; 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=5TZiwglZdUb5mT/cPvMOfmQHrCRDAOLfD9EQuRg3y6g=; b=rj3yypCm9bS6AbqrzCuyoXLGFcbJ09rKxI4whAQLZk/OfQw66OFpcbNnEveH2Yt5WY0KGY AXkWzH1486sQqTdWmggFr5tivU6cWQXMWNtBKcIQmua0dDO+bAHbigXCeZSoaO4A86xJIK akwKPkd/0dolPhKdtK8b4J4jgTpcinF4tK1Ob+BZIwwyZtTLIr109NkGoid7AWbg3gErFJ GCzWLOgGFtAuDi0IV2WTprhM57S9CIOhad+sFvyTmXO3vt2GvWjRh54+yBk1TSYS+yCbYz y+aa6avFi30ysf48aKdwtW02cuYQNDpPou5oXyk0aoGL1p7rpMmNQMGt4pD7xg== 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 21BB425D01; Sat, 7 May 2022 00:04:45 +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 24704iTb031165; Sat, 7 May 2022 00:04:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24704iIx031164; Sat, 7 May 2022 00:04:44 GMT (envelope-from git) Date: Sat, 7 May 2022 00:04:44 GMT Message-Id: <202205070004.24704iIx031164@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alan Somers Subject: git: 1d2421ad8b6d - main - Correctly measure system load averages > 1024 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 1d2421ad8b6d508ef155752bdfc5948f7373bac3 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651881885; 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=5TZiwglZdUb5mT/cPvMOfmQHrCRDAOLfD9EQuRg3y6g=; b=vm7LIdgLcVaOEy3xlsSb3+z/xvOPUfcrFJ7gjWVj6S796FWGDVZ2cDu1yK6cM5U9BnYjGG g2etHD4ajr9qRCBr0jky0kRVsZ/bVygqXSCvMSZZRylwXyaODDjvQkBW/Z7g3tJ7tIBRjZ ussFqeox97NqPk0b3fsbAJQsAqDc6koKYj2qyCpM4CcZ0vJysodJ3Ya6HypuAHFiJoG2iK +F/0FH9CtaYcRvPc2s/gr6+n1WXamkwOEL8Xsw+zxQqFBvuEciCvDm2kCMq91LaeneLcEA shEJe0iwJo/uWdxse4LjUVHPkaTu9qE86skxzP4J2Imv7W7A12gk5RcmhyFCmg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651881885; a=rsa-sha256; cv=none; b=wLN9E3FnQi1Qi5SWxXyIBUIgilT73zeEutFkIRaCiUOgEqbJW0T8mHr1Q7WyefPJV5gd+o YO2OcgFlRGjpNzXMDBY91RxkUUEnzn5EmZBq/ICbVzWBUBiIEw4O/MjiHJ0wCP/UzUQmfs CFTHlH1MhOCho75treXKgo7FQ+XouSdP1FZgydbJgBRKEBDL/3M5HUSKWbR2ehACoXK/9h 82zTp7USKydOMhVS8m6DD9fnDjTCGZQB7g+bxHQWFVx+ra5qbDUm5e3L0vdmf5EcCNRyRG CKxVFVo3sezIQG2Fzll9KmsNZz0q9Yibytr/46wPfiY0hLB/TukXfPkqGsfQaA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=1d2421ad8b6d508ef155752bdfc5948f7373bac3 commit 1d2421ad8b6d508ef155752bdfc5948f7373bac3 Author: Alan Somers AuthorDate: 2022-05-05 21:35:23 +0000 Commit: Alan Somers CommitDate: 2022-05-06 23:25:43 +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 --- 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 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); diff --git a/sys/sys/param.h b/sys/sys/param.h index 2d463b9ac7a2..b0b53f1a7776 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -361,12 +361,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<