qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: jjherne@linux.vnet.ibm.com, afaerber@suse.de,
	amit.shah@redhat.com, dgilbert@redhat.com,
	borntraeger@de.ibm.com, quintela@redhat.com,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v4 1/5] cpu: Provide vcpu throttling interface
Date: Thu, 23 Jul 2015 11:59:02 +0200	[thread overview]
Message-ID: <55B0BAE6.3040504@redhat.com> (raw)
In-Reply-To: <55A7BDF4.4020509@linux.vnet.ibm.com>



On 16/07/2015 16:21, Jason J. Herne wrote:
> 1. Using atomic operations to manage throttle_percentage. I'm not sure
> where atomics are applicable here. If this is still a concern hopefully
> someone can explain.

I would use atomic_read/atomic_set in cpu_throttle_set, 
cpu_throttle_stop, cpu_throttle_active, cpu_throttle_get_percentage.  
In addition, the function naming seems to be a bit inconsistent: please 
rename cpu_throttle_set to cpu_throttle_set_percentage.

Second, here:

>> +static void cpu_throttle_thread(void *opaque)
>> +{
>> + double pct = (double)throttle_percentage/100;

Please use cpu_throttle_get_percentage(), and

>> + double throttle_ratio = pct / (1 - pct);
>> + long sleeptime_ms = (long)(throttle_ratio * CPU_THROTTLE_TIMESLICE);

... move these computations below the if.

I'm also not sure about throttle_ratio, why is it needed?  If pct >= 0.5 you
end up with throttle_ratio >= 1, i.e. no way for the CPU to do any work.  This
would definitely cause a problem with callbacks piling up.

>> + if (!throttle_percentage) {
>> + return;
>> + }
>> +
>> + qemu_mutex_unlock_iothread();
>> + g_usleep(sleeptime_ms * 1000); /* Convert ms to us for usleep call */
>> + qemu_mutex_lock_iothread();
>> +}
>> +

> 2. Callback stacking. And it seems like we are convinced that it is not
> a big issue. Anyone disagree?

I think it's not a big issue to have many timers, but it is a big issue to have many callbacks.  What I suggested is this:

    if (!atomic_xchg(&cpu->throttle_thread_scheduled, 1)) {
        async_run_on_cpu(cpu, cpu_throttle_thread, NULL);
    }

and in the callback:

    atomic_set(&cpu->throttle_thread_scheduled, 0);
    g_usleep(...); 

Paolo

  reply	other threads:[~2015-07-23  9:59 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-02 16:36 [Qemu-devel] [PATCH v4 0/5] migration: Dynamic cpu throttling for auto-converge Jason J. Herne
2015-07-02 16:36 ` [Qemu-devel] [PATCH v4 1/5] cpu: Provide vcpu throttling interface Jason J. Herne
2015-07-02 16:43   ` Paolo Bonzini
2015-07-02 16:58     ` Dr. David Alan Gilbert
2015-07-13 14:43     ` Jason J. Herne
2015-07-13 15:14       ` Paolo Bonzini
2015-07-15 12:40         ` Jason J. Herne
2015-07-15 12:54           ` Paolo Bonzini
2015-07-16 14:21             ` Jason J. Herne
2015-07-23  9:59               ` Paolo Bonzini [this message]
2015-07-31 17:12                 ` Jason J. Herne
2015-07-31 17:16                   ` Paolo Bonzini
2015-07-31 17:42                     ` Jason J. Herne
2015-07-31 18:11                       ` Jason J. Herne
2015-08-01  9:40                         ` Paolo Bonzini
2015-09-01 14:43                           ` Jason J. Herne
2015-07-02 16:47   ` Andreas Färber
2015-07-02 16:36 ` [Qemu-devel] [PATCH v4 2/5] migration: Parameters for auto-converge cpu throttling Jason J. Herne
2015-07-02 16:36 ` [Qemu-devel] [PATCH v4 3/5] migration: Dynamic cpu throttling for auto-converge Jason J. Herne
2015-07-02 16:36 ` [Qemu-devel] [PATCH v4 4/5] qmp/hmp: Add throttle ratio to query-migrate and info migrate Jason J. Herne
2015-07-02 16:36 ` [Qemu-devel] [PATCH v4 5/5] migration: Disambiguate MAX_THROTTLE Jason J. Herne

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=55B0BAE6.3040504@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=afaerber@suse.de \
    --cc=amit.shah@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=dgilbert@redhat.com \
    --cc=jjherne@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /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).