From: Peter Xu <peterx@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, Juan Quintela <quintela@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Richard Henderson <rth@twiddle.net>,
jjherne@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [PATCH 5/5] cpu: throttle: fix throttle time slice
Date: Sat, 1 Apr 2017 15:52:15 +0800 [thread overview]
Message-ID: <20170401075215.GO3981@pxdev.xzpeter.org> (raw)
In-Reply-To: <aa26e76e-e5fd-c205-8919-6cc927a6d3ce@redhat.com>
On Fri, Mar 31, 2017 at 06:38:50PM +0200, Paolo Bonzini wrote:
>
>
> On 27/03/2017 09:21, Peter Xu wrote:
> > @@ -641,8 +640,7 @@ static void cpu_throttle_thread(CPUState *cpu, run_on_cpu_data opaque)
> > }
> >
> > pct = (double)cpu_throttle_get_percentage()/100;
> > - throttle_ratio = pct / (1 - pct);
> > - sleeptime_ns = (long)(throttle_ratio * CPU_THROTTLE_TIMESLICE_NS);
>
> Say pct = 0.25, then throttle_ratio = 0.25/0.75 = 1/3.
>
> > + sleeptime_ns = (long)((1 - pct) * CPU_THROTTLE_TIMESLICE_NS);
> >
> > qemu_mutex_unlock_iothread();
> > atomic_set(&cpu->throttle_thread_scheduled, 0);
> > @@ -668,7 +666,7 @@ static void cpu_throttle_timer_tick(void *opaque)
> >
> > pct = (double)cpu_throttle_get_percentage()/100;
> > timer_mod(throttle_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT) +
> > - CPU_THROTTLE_TIMESLICE_NS / (1-pct));
>
> And the timer is running every 1/0.75 = 4/3 * CPU_THROTTLE_TIMESLICE_NS.
>
> Of these, 1/3 is spent sleeping (3.33 ms), while 1 (10 ms) is spent not
> sleeping.
>
> When pct = 0.75, throttle_ratio = 3 and the timer is running every 4 *
> CPU_THROTTLE_TIMESLICE_NS (40 ms). Of these, 3 slices (30 ms) are spent
> sleeping, while 10 ms are spent not sleeping.
>
> The rationale _could_ be (I don't remember) that a CPU with a very high
> throttling frequency leaves little time for the migration thread to do
> any work. So QEMU keeps the "on" phase always the same and lengthens
> the "off" phase, which as you found out can be unsatisfactory.
Yes. Sorry I must have done an incorrect math that day. Current
algorithm is correct, it just assumes that the running time is
constant, which is CPU_THROTTLE_TIMESLICE_NS (10ms). I just didn't
realize it at the first glance.
>
> However, I think your patch has the opposite problem: the frequency is
> constant, but with high throttling all time reserved for the CPU will be
> lost in overhead. For example, at 99% throttling you only have 100
> microseconds to wake up, do work and go back to sleep.
>
> So I'm inclined _not_ to take your patch. One possibility could be to
> do the following:
>
> - for throttling between 0% and 80%, use the current algorithm. At 66%,
> the CPU will work for 10 ms and sleep for 40 ms.
>
> - for throttling above 80% adapt your algorithm to have a variable
> timeslice, going from 50 ms at 66% to 100 ms at 100%. This way, the CPU
> time will shrink below 10 ms and the sleep time will grow.
>
> It looks like this: http://i.imgur.com/lyFie04.png
>
> So at 99% the timeslice will be 97.5 ms; the CPU will work for 975 us
> and sleep for the rest (10x more than with just your patch). But I'm
> not sure it's really worth it.
Yeah. It may not that worth it. Thanks for the analysis. :-)
Will drop this patch in next post.
Thanks,
-- peterx
prev parent reply other threads:[~2017-04-01 7:52 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-27 7:21 [Qemu-devel] [PATCH 0/5] several migrations related patches Peter Xu
2017-03-27 7:21 ` [Qemu-devel] [PATCH 1/5] migration: set current_active_state once Peter Xu
2017-03-31 18:50 ` Dr. David Alan Gilbert
2017-03-27 7:21 ` [Qemu-devel] [PATCH 2/5] migration: rename max_size to threshold_size Peter Xu
2017-03-31 18:59 ` Dr. David Alan Gilbert
2017-04-01 7:16 ` Peter Xu
2017-03-27 7:21 ` [Qemu-devel] [PATCH 3/5] hmp: info migrate_capability format tunes Peter Xu
2017-03-31 19:01 ` Dr. David Alan Gilbert
2017-03-27 7:21 ` [Qemu-devel] [PATCH 4/5] hmp: info migrate_parameters " Peter Xu
2017-03-31 19:02 ` Dr. David Alan Gilbert
2017-03-27 7:21 ` [Qemu-devel] [PATCH 5/5] cpu: throttle: fix throttle time slice Peter Xu
2017-03-27 7:40 ` Peter Xu
2017-03-31 16:38 ` Paolo Bonzini
2017-03-31 19:13 ` Dr. David Alan Gilbert
2017-03-31 19:46 ` Paolo Bonzini
2017-04-04 15:44 ` Dr. David Alan Gilbert
2017-04-01 7:52 ` Peter Xu [this message]
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=20170401075215.GO3981@pxdev.xzpeter.org \
--to=peterx@redhat.com \
--cc=dgilbert@redhat.com \
--cc=jjherne@linux.vnet.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=rth@twiddle.net \
/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.