From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45209) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAIWH-0001qF-IO for qemu-devel@nongnu.org; Wed, 01 Jul 2015 09:57:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZAIWB-0002MD-RZ for qemu-devel@nongnu.org; Wed, 01 Jul 2015 09:57:45 -0400 Received: from mail-wi0-x22d.google.com ([2a00:1450:400c:c05::22d]:33214) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAIWB-0002LX-JW for qemu-devel@nongnu.org; Wed, 01 Jul 2015 09:57:39 -0400 Received: by wiwl6 with SMTP id l6so166171540wiw.0 for ; Wed, 01 Jul 2015 06:57:35 -0700 (PDT) Sender: Paolo Bonzini References: <1435254377-13322-1-git-send-email-jjherne@linux.vnet.ibm.com> <1435254377-13322-2-git-send-email-jjherne@linux.vnet.ibm.com> From: Paolo Bonzini Message-ID: <5593F1CD.7060101@redhat.com> Date: Wed, 1 Jul 2015 15:57:33 +0200 MIME-Version: 1.0 In-Reply-To: <1435254377-13322-2-git-send-email-jjherne@linux.vnet.ibm.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3 1/5] cpu: Provide vcpu throttling interface List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Jason J. Herne" , afaerber@suse.de, amit.shah@redhat.com, dgilbert@redhat.com, borntraeger@de.ibm.com, quintela@redhat.com, qemu-devel@nongnu.org On 25/06/2015 19:46, Jason J. Herne wrote: > +static void cpu_throttle_thread(void *opaque) > +{ > + long sleeptime_ms = (long)(throttle_ratio * CPU_THROTTLE_TIMESLICE); > + > + qemu_mutex_unlock_iothread(); > + g_usleep(sleeptime_ms * 1000); /* Convert ms to us for usleep call */ > + qemu_mutex_lock_iothread(); > + > + timer_mod(throttle_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + > + CPU_THROTTLE_TIMESLICE); The timer need not run while the VM is stopped. Please use QEMU_CLOCK_VIRTUAL_RT. > +} > + Are you sure you want each CPU to set the timer? I think this should be done in cpu_throttle_timer_pop, or it could use timer_mod_anticipate. > +static void cpu_throttle_timer_pop(void *opaque) > +{ > + CPUState *cpu; > + > + /* Stop the timer if needed */ > + if (throttle_timer_stop) { > + timer_del(throttle_timer); timer_del is not needed in the timer callback. Paolo > + timer_free(throttle_timer); > + throttle_timer = NULL; > + return; > + } > + > + CPU_FOREACH(cpu) { > + async_run_on_cpu(cpu, cpu_throttle_thread, NULL); > + } > +} > +