From: Hyman Huang <yong.huang@smartx.com> To: qemu-devel@nongnu.org Cc: Andrei Gudkov <gudkov.andrei@huawei.com>, Hyman Huang <yong.huang@smartx.com> Subject: [PULL 3/3] migration/dirtyrate: Fix precision losses and g_usleep overshoot Date: Tue, 29 Aug 2023 01:19:22 +0800 [thread overview] Message-ID: <e424d9f7e749c84de4a6ce532981271db1c14b23.1693241678.git.yong.huang@smartx.com> (raw) In-Reply-To: <cover.1693241678.git.yong.huang@smartx.com> From: Andrei Gudkov <gudkov.andrei@huawei.com> Signed-off-by: Andrei Gudkov <gudkov.andrei@huawei.com> Reviewed-by: Hyman Huang <yong.huang@smartx.com> Message-Id: <8ddb0d40d143f77aab8f602bd494e01e5fa01614.1691161009.git.gudkov.andrei@huawei.com> Signed-off-by: Hyman Huang <yong.huang@smartx.com> --- migration/dirtyrate.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 84f1b0fb20..bccb3515e3 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -57,6 +57,8 @@ static int64_t dirty_stat_wait(int64_t msec, int64_t initial_time) msec = current_time - initial_time; } else { g_usleep((msec + initial_time - current_time) * 1000); + /* g_usleep may overshoot */ + msec = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) - initial_time; } return msec; @@ -77,9 +79,13 @@ static int64_t do_calculate_dirtyrate(DirtyPageRecord dirty_pages, { uint64_t increased_dirty_pages = dirty_pages.end_pages - dirty_pages.start_pages; - uint64_t memory_size_MiB = qemu_target_pages_to_MiB(increased_dirty_pages); - return memory_size_MiB * 1000 / calc_time_ms; + /* + * multiply by 1000ms/s _before_ converting down to megabytes + * to avoid losing precision + */ + return qemu_target_pages_to_MiB(increased_dirty_pages * 1000) / + calc_time_ms; } void global_dirty_log_change(unsigned int flag, bool start) -- 2.39.1
WARNING: multiple messages have this Message-ID (diff)
From: Hyman Huang <yong.huang@smartx.com> To: qemu-devel@nongnu.org Cc: Andrei Gudkov <gudkov.andrei@huawei.com>, Hyman Huang <yong.huang@smartx.com> Subject: [PULL 3/3] migration/dirtyrate: Fix precision losses and g_usleep overshoot Date: Tue, 29 Aug 2023 01:32:52 +0800 [thread overview] Message-ID: <e424d9f7e749c84de4a6ce532981271db1c14b23.1693241678.git.yong.huang@smartx.com> (raw) Message-ID: <20230828173252.bzcCLhKAjGqW2mSEF6WxXGoGDUbnUbEKKPAvZhr3HeI@z> (raw) In-Reply-To: <cover.1693241678.git.yong.huang@smartx.com> From: Andrei Gudkov <gudkov.andrei@huawei.com> Signed-off-by: Andrei Gudkov <gudkov.andrei@huawei.com> Reviewed-by: Hyman Huang <yong.huang@smartx.com> Message-Id: <8ddb0d40d143f77aab8f602bd494e01e5fa01614.1691161009.git.gudkov.andrei@huawei.com> Signed-off-by: Hyman Huang <yong.huang@smartx.com> --- migration/dirtyrate.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 84f1b0fb20..bccb3515e3 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -57,6 +57,8 @@ static int64_t dirty_stat_wait(int64_t msec, int64_t initial_time) msec = current_time - initial_time; } else { g_usleep((msec + initial_time - current_time) * 1000); + /* g_usleep may overshoot */ + msec = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) - initial_time; } return msec; @@ -77,9 +79,13 @@ static int64_t do_calculate_dirtyrate(DirtyPageRecord dirty_pages, { uint64_t increased_dirty_pages = dirty_pages.end_pages - dirty_pages.start_pages; - uint64_t memory_size_MiB = qemu_target_pages_to_MiB(increased_dirty_pages); - return memory_size_MiB * 1000 / calc_time_ms; + /* + * multiply by 1000ms/s _before_ converting down to megabytes + * to avoid losing precision + */ + return qemu_target_pages_to_MiB(increased_dirty_pages * 1000) / + calc_time_ms; } void global_dirty_log_change(unsigned int flag, bool start) -- 2.39.1
next prev parent reply other threads:[~2023-08-28 17:22 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-08-28 17:19 [PULL 0/3] Dirty page rate and dirty page limit 20230829 patches Hyman Huang 2023-08-28 17:19 ` [PULL 1/3] softmmu: Fix dirtylimit memory leak Hyman Huang 2023-08-28 17:32 ` Hyman Huang 2023-08-28 17:19 ` [PULL 2/3] softmmu/dirtylimit: Convert free to g_free Hyman Huang 2023-08-28 17:32 ` Hyman Huang 2023-08-28 17:19 ` Hyman Huang [this message] 2023-08-28 17:32 ` [PULL 3/3] migration/dirtyrate: Fix precision losses and g_usleep overshoot Hyman Huang 2023-08-28 17:32 ` [PULL 0/3] Dirty page rate and dirty page limit 20230829 patches Hyman Huang -- strict thread matches above, loose matches on Subject: below -- 2023-08-29 15:29 Hyman Huang 2023-08-29 15:29 ` [PULL 3/3] migration/dirtyrate: Fix precision losses and g_usleep overshoot Hyman Huang
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=e424d9f7e749c84de4a6ce532981271db1c14b23.1693241678.git.yong.huang@smartx.com \ --to=yong.huang@smartx.com \ --cc=gudkov.andrei@huawei.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: linkBe 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 NNTP newsgroup(s).