From: Yong Huang <yong.huang@smartx.com>
To: alloc.young@outlook.com
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH] softmmu/dirtylimit: Fix usleep early return on signal
Date: Mon, 4 Sep 2023 21:27:17 +0800 [thread overview]
Message-ID: <CAK9dgmYVeGGf=2jawm77DtiOeqvnN_dEiLvOWK3-r1zzC1DJ8A@mail.gmail.com> (raw)
In-Reply-To: <SA1PR11MB6760A4AD57255448B62EDE38F5E4A@SA1PR11MB6760.namprd11.prod.outlook.com>
[-- Attachment #1: Type: text/plain, Size: 2553 bytes --]
On Fri, Sep 1, 2023 at 10:19 AM <alloc.young@outlook.com> wrote:
> From: alloc <alloc.young@outlook.com>
>
> Timeout functions like usleep can return early on signal, which reduces
> more dirty pages than expected. In dirtylimit case, dirtyrate meter
> thread needs to kick all vcpus out to sync. The callchain:
>
> vcpu_calculate_dirtyrate
> global_dirty_log_sync
> memory_global_dirty_log_sync
> kvm_log_sync_global
> kvm_dirty_ring_flush
> kvm_cpu_synchronize_kick_all <---- send vcpu signal
>
> For long time sleep, use qemu_cond_timedwait_iothread to handle cpu stop
> event.
>
>
The Dirty Limit algorithm seeks to keep the vCPU dirty page rate within
the set limit; since it focuses more emphasis on processing time and
precision, I feel that improvement should strive for the same result.
Could you please provide the final test results showing the impact of
that improvement?
> Signed-off-by: alloc <alloc.young@outlook.com>
> ---
> softmmu/dirtylimit.c | 19 +++++++++++++++++--
> 1 file changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/softmmu/dirtylimit.c b/softmmu/dirtylimit.c
> index fa959d7743..ee938c636d 100644
> --- a/softmmu/dirtylimit.c
> +++ b/softmmu/dirtylimit.c
> @@ -411,13 +411,28 @@ void dirtylimit_set_all(uint64_t quota,
>
> void dirtylimit_vcpu_execute(CPUState *cpu)
> {
> + int64_t sleep_us, endtime_us;
> +
> + dirtylimit_state_lock();
> if (dirtylimit_in_service() &&
> dirtylimit_vcpu_get_state(cpu->cpu_index)->enabled &&
> cpu->throttle_us_per_full) {
> trace_dirtylimit_vcpu_execute(cpu->cpu_index,
> cpu->throttle_us_per_full);
> - usleep(cpu->throttle_us_per_full);
> - }
> + sleep_us = cpu->throttle_us_per_full;
> + dirtylimit_state_unlock();
> + endtime_us = qemu_clock_get_us(QEMU_CLOCK_REALTIME) + sleep_us;
> + while (sleep_us > 0 && !cpu->stop) {
> + if (sleep_us > SCALE_US) {
> + qemu_mutex_lock_iothread();
> + qemu_cond_timedwait_iothread(cpu->halt_cond, sleep_us /
> SCALE_US);
> + qemu_mutex_unlock_iothread();
> + } else
> + g_usleep(sleep_us);
> + sleep_us = endtime_us -
> qemu_clock_get_us(QEMU_CLOCK_REALTIME);
> + }
> + } else
> + dirtylimit_state_unlock();
> }
>
> static void dirtylimit_init(void)
> --
> 2.39.3
>
>
--
Best regards
[-- Attachment #2: Type: text/html, Size: 4366 bytes --]
next prev parent reply other threads:[~2023-09-04 13:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-01 2:18 [PATCH] softmmu/dirtylimit: Fix usleep early return on signal alloc.young
2023-09-04 13:27 ` Yong Huang [this message]
2023-09-05 2:17 ` alloc young
2023-10-16 15:37 ` Hyman Huang
2023-09-08 1:11 ` alloc young
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='CAK9dgmYVeGGf=2jawm77DtiOeqvnN_dEiLvOWK3-r1zzC1DJ8A@mail.gmail.com' \
--to=yong.huang@smartx.com \
--cc=alloc.young@outlook.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 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).