From: Cyril Hrubis <chrubis@suse.cz>
To: Vishal Chourasia <vishalc@linux.ibm.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>,
Shrikanth Hegde <sshegde@linux.vnet.ibm.com>,
raj.khem@gmail.com, chris@mips.com, ltp@lists.linux.it,
tdavies@darkphysics.net, gaowanlong@cn.fujitsu.com
Subject: Re: [LTP] [PATCH v2 2/2] ebizzy: prevent integer overflow in 64-bit systems
Date: Mon, 21 Aug 2023 15:24:05 +0200 [thread overview]
Message-ID: <ZONldbUOjaFGbr_L@yuki> (raw)
In-Reply-To: <20230815093048.1155501-3-vishalc@linux.ibm.com>
Hi!
> Signed-off-by: Vishal Chourasia <vishalc@linux.ibm.com>
> Reviewed-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
> Reviewed-by: Shrikanth Hegde <sshegde@linux.vnet.ibm.com>
> ---
> utils/benchmark/ebizzy-0.3/ebizzy.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/utils/benchmark/ebizzy-0.3/ebizzy.c b/utils/benchmark/ebizzy-0.3/ebizzy.c
> index ae0981fbd..c3eac1133 100644
> --- a/utils/benchmark/ebizzy-0.3/ebizzy.c
> +++ b/utils/benchmark/ebizzy-0.3/ebizzy.c
> @@ -456,7 +456,7 @@ static void start_threads(void)
> unsigned int i;
> struct rusage start_ru, end_ru;
> struct timeval usr_time, sys_time;
> - uintptr_t records_read = 0;
> + uintptr_t records_per_sec = 0;
> int err;
>
> if (verbose)
> @@ -493,14 +493,13 @@ static void start_threads(void)
> fprintf(stderr, "Error joining thread %d\n", i);
> exit(1);
> }
> - records_read += record_thread;
> + records_per_sec += (record_thread / elapsed);
This actually introduces quite a bit rounding errors. Note that even
with 10 second runtime we effectively throw away the last digit for each
thread records and it's even worse for larger runtime. This kind of
naive summing can easily add up to quite large differencies.
E.g. for a machine with 256 CPUs and 10 seconds the value would be on
average smaller by:
512 (number of threads) * 5 (average last digit) / 10 (runtime)
So on average the result printed would be smaller by 256 units.
Either we have to switch the records_per_sec to double and compute the
number in floating point, which should add up fine as long as the work
done by a threads is more or less the same.
Or use uint64_t as a fixed point and use one or two bits for a fraction,
which may be a bit safer than double and should work fine as long as
we round properly.
This should be easy to debug as well, just print the number computed by
the method that sum first and then divide and compare it with the number
that sums the already divided values. These two shouldn't differ much,
ideally the should be the same.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2023-08-21 13:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-15 9:30 [LTP] [PATCH v2 0/2] Fix Integer Overflow and Thread Safety in Record Counting Vishal Chourasia
2023-08-15 9:30 ` [LTP] [PATCH v2 1/2] Enhance " Vishal Chourasia
2023-08-21 12:30 ` Cyril Hrubis
2023-08-15 9:30 ` [LTP] [PATCH v2 2/2] ebizzy: prevent integer overflow in 64-bit systems Vishal Chourasia
2023-08-21 13:24 ` Cyril Hrubis [this message]
2023-08-29 9:37 ` Vishal Chourasia
2023-08-29 10:03 ` Vishal Chourasia
2023-08-29 10:13 ` [LTP] [PATCH v3] " Vishal Chourasia
2023-09-06 8:51 ` Cyril Hrubis
2023-09-07 10:42 ` Richard Palethorpe
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=ZONldbUOjaFGbr_L@yuki \
--to=chrubis@suse.cz \
--cc=chris@mips.com \
--cc=gaowanlong@cn.fujitsu.com \
--cc=ltp@lists.linux.it \
--cc=raj.khem@gmail.com \
--cc=srikar@linux.vnet.ibm.com \
--cc=sshegde@linux.vnet.ibm.com \
--cc=tdavies@darkphysics.net \
--cc=vishalc@linux.ibm.com \
/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