From: Fabiano Rosas <farosas@suse.de>
To: Prasad Pandit <ppandit@redhat.com>
Cc: qemu-devel@nongnu.org, "Peter Xu" <peterx@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Peter Maydell" <peter.maydell@linaro.org>
Subject: Re: [PATCH 1/2] migration: Fix postcopy latency distribution formatting computation
Date: Wed, 16 Jul 2025 10:36:05 -0300 [thread overview]
Message-ID: <8734awmf5m.fsf@suse.de> (raw)
In-Reply-To: <CAE8KmOzrFF79P4qUOxH4UtzuymGUWTcSLQan-ee=+EaVwv2dBQ@mail.gmail.com>
Prasad Pandit <ppandit@redhat.com> writes:
> On Tue, 15 Jul 2025 at 18:49, Fabiano Rosas <farosas@suse.de> wrote:
>> @@ -57,11 +57,9 @@ static const gchar *format_time_str(uint64_t us)
>> const char *units[] = {"us", "ms", "sec"};
>> int index = 0;
>>
>> - while (us > 1000) {
>> + while (us > 1000 && index + 1 < ARRAY_SIZE(units)) {
>> us /= 1000;
>> - if (++index >= (sizeof(units) - 1)) {
>> - break;
>> - }
>> + index++;
>> }
>>
>> return g_strdup_printf("%"PRIu64" %s", us, units[index]);
>
> * This loop is rather confusing.
>
> * Is the while loop converting microseconds (us) to seconds with: us
> /= 1000 ? ie. index shall mostly be 2 = "sec", except for the range =
> 1000000 - 1000999, when us / 1000 => 1000 would break the while loop
> and it'd return string "1000 ms".
Good catch. The condition should be >=.
> ===
> #define MS (1000)
> #define US (MS * 1000)
> #define NS (US * 1000)
>
> if (n >= NS)
> n /= NS;
> else if (n >= US)
> n /= US;
> else if (n >= MS)
> n /= MS;
>
> return g_strdup_printf("%"PRIu64" sec", n);
> ===
>
> * Does the above simplification look right? It shall always return
> seconds as: "<n> sec"
>
But then that's "0 sec" for 1000000 us.
>
> Thank you.
> ---
> - Prasad
next prev parent reply other threads:[~2025-07-16 13:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-15 12:45 [PATCH 0/2] migration: Fix possible access out of bounds Fabiano Rosas
2025-07-15 12:45 ` [PATCH 1/2] migration: Fix postcopy latency distribution formatting computation Fabiano Rosas
2025-07-15 14:01 ` Philippe Mathieu-Daudé
2025-07-16 10:26 ` Prasad Pandit
2025-07-16 13:36 ` Fabiano Rosas [this message]
2025-07-17 6:28 ` Prasad Pandit
2025-07-17 12:35 ` Fabiano Rosas
2025-07-17 13:31 ` Daniel P. Berrangé
2025-07-15 12:45 ` [PATCH 2/2] cutils: Add time_us_to_str Fabiano Rosas
2025-07-15 14:02 ` Philippe Mathieu-Daudé
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=8734awmf5m.fsf@suse.de \
--to=farosas@suse.de \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=ppandit@redhat.com \
--cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.