From: Fabiano Rosas <farosas@suse.de>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, Peter Xu <peterx@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
"Dr . David Alan Gilbert" <dave@treblig.org>
Subject: Re: [PULL 25/26] migration/postcopy: Add latency distribution report for blocktime
Date: Mon, 14 Jul 2025 16:11:18 -0300 [thread overview]
Message-ID: <875xfumvu1.fsf@suse.de> (raw)
In-Reply-To: <CAFEAcA-_2a5CUspXhy8UErA86EnZ3_s=P2DQ9DPdrMDwNWF4FQ@mail.gmail.com>
Peter Maydell <peter.maydell@linaro.org> writes:
> On Fri, 11 Jul 2025 at 15:20, Fabiano Rosas <farosas@suse.de> wrote:
>>
>> From: Peter Xu <peterx@redhat.com>
>>
>> Add the latency distribution too for blocktime, using order-of-two buckets.
>> It accounts for all the faults, from either vCPU or non-vCPU threads. With
>> prior rework, it's very easy to achieve by adding an array to account for
>> faults in each buckets.
>>
>> Sample output for HMP (while for QMP it's simply an array):
>>
>> Postcopy Latency Distribution:
>
> Hi; Coverity points out that there is a bug here (CID 1612248):
>
>> +static const gchar *format_time_str(uint64_t us)
>> +{
>> + const char *units[] = {"us", "ms", "sec"};
>> + int index = 0;
>> +
>> + while (us > 1000) {
>> + us /= 1000;
>> + if (++index >= (sizeof(units) - 1)) {
>
> sizeof(units) is the size in bytes, which in this case is
> 24, as it is an array of three 8-byte pointers. So it's
> not the right thing to use in bounds checking the array index.
>
> You probably wanted ARRAY_SIZE(units). Also, the ++index
> inside the comparison here seems unnecessarily confusing.
> I would suggest something like
>
> while (us > 1000 && index + 1 < ARRAY_SIZE(units)) {
> us /= 1000;
> index++;
> }
>
> which puts into the while condition the two conditions under
> which we are OK to shift down a unit, and keeps it
> clear that we maintain the invariant of "when we shift
> down a unit we also divide the value by 1000".
>
>> + break;
>> + }
>> + }
>> +
>> + return g_strdup_printf("%"PRIu64" %s", us, units[index]);
>
> Otherwise this units[index] access could be off the end of
> the array.
>
>> +}
Thanks for the report. Peter Xu is not available at the moment, I'll
work on this.
next prev parent reply other threads:[~2025-07-14 20:44 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-11 14:10 [PULL 00/26] Migration patches for 2025-07-11 Fabiano Rosas
2025-07-11 14:10 ` [PULL 01/26] migration/hmp: Reorg "info migrate" once more Fabiano Rosas
2025-07-11 14:10 ` [PULL 02/26] migration/hmp: Fix postcopy-blocktime per-vCPU results Fabiano Rosas
2025-07-11 14:10 ` [PULL 03/26] migration/docs: Move docs for postcopy blocktime feature Fabiano Rosas
2025-07-11 14:10 ` [PULL 04/26] migration/bg-snapshot: Do not check for SKIP in iterator Fabiano Rosas
2025-07-11 14:10 ` [PULL 05/26] migration: Drop save_live_complete_postcopy hook Fabiano Rosas
2025-07-11 14:10 ` [PULL 06/26] migration: Rename save_live_complete_precopy to save_complete Fabiano Rosas
2025-07-11 14:10 ` [PULL 07/26] migration: qemu_savevm_complete*() helpers Fabiano Rosas
2025-07-11 14:10 ` [PULL 08/26] migration/ram: One less indent for ram_find_and_save_block() Fabiano Rosas
2025-07-11 14:10 ` [PULL 09/26] migration/ram: Add tracepoints for ram_save_complete() Fabiano Rosas
2025-07-11 14:10 ` [PULL 10/26] migration: Rewrite the migration complete detect logic Fabiano Rosas
2025-07-11 14:10 ` [PULL 11/26] migration/postcopy: Avoid clearing dirty bitmap for postcopy too Fabiano Rosas
2025-07-11 14:10 ` [PULL 12/26] migration: Add option to set postcopy-blocktime Fabiano Rosas
2025-07-11 14:10 ` [PULL 13/26] migration/postcopy: Push blocktime start/end into page req mutex Fabiano Rosas
2025-07-11 14:10 ` [PULL 14/26] migration/postcopy: Drop all atomic ops in blocktime feature Fabiano Rosas
2025-07-11 14:10 ` [PULL 15/26] migration/postcopy: Make all blocktime vars 64bits Fabiano Rosas
2025-07-11 14:10 ` [PULL 16/26] migration/postcopy: Drop PostcopyBlocktimeContext.start_time Fabiano Rosas
2025-07-11 14:10 ` [PULL 17/26] migration/postcopy: Bring blocktime layer to ns level Fabiano Rosas
2025-07-11 14:10 ` [PULL 18/26] migration/postcopy: Add blocktime fault counts per-vcpu Fabiano Rosas
2025-07-11 14:10 ` [PULL 19/26] migration/postcopy: Report fault latencies in blocktime Fabiano Rosas
2025-07-11 14:10 ` [PULL 20/26] migration/postcopy: Initialize blocktime context only until listen Fabiano Rosas
2025-07-11 14:10 ` [PULL 21/26] migration/postcopy: Cache the tid->vcpu mapping for blocktime Fabiano Rosas
2025-07-11 14:10 ` [PULL 22/26] migration/postcopy: Cleanup the total blocktime accounting Fabiano Rosas
2025-07-11 14:10 ` [PULL 23/26] migration/postcopy: Optimize blocktime fault tracking with hashtable Fabiano Rosas
2025-07-11 14:10 ` [PULL 24/26] migration/postcopy: blocktime allows track / report non-vCPU faults Fabiano Rosas
2025-07-11 14:10 ` [PULL 25/26] migration/postcopy: Add latency distribution report for blocktime Fabiano Rosas
2025-07-14 10:47 ` Peter Maydell
2025-07-14 19:11 ` Fabiano Rosas [this message]
2025-07-14 19:39 ` Philippe Mathieu-Daudé
2025-07-11 14:10 ` [PULL 26/26] migration: Rename save_live_complete_precopy_thread to save_complete_precopy_thread Fabiano Rosas
2025-07-13 7:06 ` [PULL 00/26] Migration patches for 2025-07-11 Stefan Hajnoczi
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=875xfumvu1.fsf@suse.de \
--to=farosas@suse.de \
--cc=armbru@redhat.com \
--cc=dave@treblig.org \
--cc=peter.maydell@linaro.org \
--cc=peterx@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.