public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
From: Sebastian Huber <sh@sourceware.org>
To: newlib-cvs@sourceware.org
Subject: [newlib-cygwin] Correctly measure system load averages > 1024
Date: Mon, 11 Jul 2022 11:55:35 +0000 (GMT)	[thread overview]
Message-ID: <20220711115535.869CA385415F@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=27dfb5f33fa4954f6278ae8b82584c269fb6e6ef

commit 27dfb5f33fa4954f6278ae8b82584c269fb6e6ef
Author: Alan Somers <asomers@FreeBSD.org>
Date:   Thu May 5 15:35:23 2022 -0600

    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

Diff:
---
 newlib/libc/sys/rtems/include/sys/param.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/newlib/libc/sys/rtems/include/sys/param.h b/newlib/libc/sys/rtems/include/sys/param.h
index c346453bf..9596ecf52 100644
--- a/newlib/libc/sys/rtems/include/sys/param.h
+++ b/newlib/libc/sys/rtems/include/sys/param.h
@@ -248,12 +248,12 @@
  * 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<<FSHIFT)


                 reply	other threads:[~2022-07-11 11:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220711115535.869CA385415F@sourceware.org \
    --to=sh@sourceware.org \
    --cc=newlib-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).