From nobody Sat May 07 00:06:10 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 828091AC36DF; Sat, 7 May 2022 00:06:17 +0000 (UTC) (envelope-from koobs.freebsd@gmail.com) Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Kw7544x2dz4RFJ; Sat, 7 May 2022 00:06:16 +0000 (UTC) (envelope-from koobs.freebsd@gmail.com) Received: by mail-pl1-x62f.google.com with SMTP id s14so8903736plk.8; Fri, 06 May 2022 17:06:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:message-id:date:mime-version:user-agent:reply-to:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=wt+vWSu0qD2JLzXkoqPKfFZzqN21l87Y68qch3nkgnM=; b=hGjV91If5hX1zDP/qbHwxAgvbLWXqheONNMqZrHxEUEHy+E37xTFG8Pgc7iUK31ea9 VzcrcykDmR6fgsyVcL3MBD0f48VomK/U2y+X9nIgrMgr88y+eapdqMA15tHJb2A2vGgC TqC+lq322gD4YIT8Jl+LX7t5LrY1kShwP06hW62cQS5dErUay/Ar0s57ufOeIBXrBMPp z9KImvb5Qkl5hVzKWD1Aas4rRM0HmfU2/Y3nkxIOTJxbKBlXv9ihQgTCd1xz78H078r/ GBzD8Hvtln57Ce2xjs5pxogdcCbfGt+R3fXuxfrrjG6O/AWM4XwXBazmTimQmi3MiSZ6 U6wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:message-id:date:mime-version:user-agent :reply-to:subject:content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=wt+vWSu0qD2JLzXkoqPKfFZzqN21l87Y68qch3nkgnM=; b=knCvpcjrFfxyc9J1b+JUXO5G5UBpqR7RiCcLy9oeTZEoSjCRBUNW7Q8w/KbEMiPHJD atHf+YTNNhf1nwZJkCRoUYQAW6+4zUZ++L0miISSBe8yHFnN5Fh1sKSxJ/7SfDL8koRs fKCpDvxMHDD0yH/vS8+cJCxK4Uq0nFse5SWAbfDYYPLpHEgw1sD9/CYeaPbFj6auQBO1 WRIZC52ZswkVkbRGld5swuQD+SG5Liel69d5GD6gL+LLStiW/YWQSDPVoq9/beFRQL/n VRgmuglwxlBt0eSuw4z1FpYiBynIZf8aChONEKDhDBrXzGEqodOPyLGj64oHBAOdcJ35 2kWg== X-Gm-Message-State: AOAM530qnxj9US0HPTDKF6+p+Pcs+g2KolqgfHPPG1rqDCddaja1sZ3K ncFxWe50fti6BeRPrGi4MvB4x2Otun0= X-Google-Smtp-Source: ABdhPJwSriro/zJWtoFPm80ejhtzdziWQiFaehYuZx5jit4Mf+j5sjaaS5bJKaHfU/yaJWgP3Ta0nw== X-Received: by 2002:a17:902:bb8d:b0:156:51a1:3f5a with SMTP id m13-20020a170902bb8d00b0015651a13f5amr6159208pls.65.1651881975572; Fri, 06 May 2022 17:06:15 -0700 (PDT) Received: from ?IPV6:2403:5807:1b:1:ddb4:3f80:31b5:9d3? (2403-5807-1b-1-ddb4-3f80-31b5-9d3.ip6.aussiebb.net. [2403:5807:1b:1:ddb4:3f80:31b5:9d3]) by smtp.gmail.com with ESMTPSA id 4-20020a620604000000b0050dc76281d5sm4015519pfg.175.2022.05.06.17.06.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 May 2022 17:06:15 -0700 (PDT) Message-ID: <771111e0-5c1b-8eb3-751d-c5f2b8bc36eb@FreeBSD.org> Date: Sat, 7 May 2022 10:06:10 +1000 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 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.0a1 Reply-To: koobs@FreeBSD.org Subject: Re: git: 1d2421ad8b6d - main - Correctly measure system load averages > 1024 Content-Language: en-US To: Alan Somers , src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org References: <202205070004.24704iIx031164@gitrepo.freebsd.org> From: Kubilay Kocak In-Reply-To: <202205070004.24704iIx031164@gitrepo.freebsd.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4Kw7544x2dz4RFJ X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20210112 header.b=hGjV91If; dmarc=none; spf=pass (mx1.freebsd.org: domain of koobsfreebsd@gmail.com designates 2607:f8b0:4864:20::62f as permitted sender) smtp.mailfrom=koobsfreebsd@gmail.com X-Spamd-Result: default: False [-1.20 / 15.00]; HAS_REPLYTO(0.00)[koobs@FreeBSD.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; REPLYTO_ADDR_EQ_FROM(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[gmail.com:+]; NEURAL_HAM_SHORT(-1.00)[-1.000]; FORGED_SENDER(0.30)[koobs@FreeBSD.org,koobsfreebsd@gmail.com]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; MID_RHS_MATCH_FROM(0.00)[]; TAGGED_FROM(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20210112]; FROM_NEQ_ENVFROM(0.00)[koobs@FreeBSD.org,koobsfreebsd@gmail.com]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[FreeBSD.org]; NEURAL_SPAM_MEDIUM(1.00)[1.000]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::62f:from]; MLMMJ_DEST(0.00)[dev-commits-src-all,dev-commits-src-main]; RCVD_TLS_ALL(0.00)[] X-ThisMailContainsUnwantedMimeParts: N On 7/05/2022 10:04 am, Alan Somers wrote: > 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 Can MFC? > --- > 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<