From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42100) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAhR9-0004Vt-6q for qemu-devel@nongnu.org; Thu, 02 Jul 2015 12:34:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZAhR3-0002sX-Vr for qemu-devel@nongnu.org; Thu, 02 Jul 2015 12:34:07 -0400 Received: from e19.ny.us.ibm.com ([129.33.205.209]:41720) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAhR3-0002sQ-SK for qemu-devel@nongnu.org; Thu, 02 Jul 2015 12:34:01 -0400 Received: from /spool/local by e19.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 2 Jul 2015 12:34:01 -0400 Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 7326538C805F for ; Thu, 2 Jul 2015 12:33:56 -0400 (EDT) Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t62GXudc60293206 for ; Thu, 2 Jul 2015 16:33:56 GMT Received: from d01av03.pok.ibm.com (localhost [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t62GXta3010874 for ; Thu, 2 Jul 2015 12:33:56 -0400 Message-ID: <559567F2.4070901@linux.vnet.ibm.com> Date: Thu, 02 Jul 2015 12:33:54 -0400 From: "Jason J. Herne" MIME-Version: 1.0 References: <1435254377-13322-1-git-send-email-jjherne@linux.vnet.ibm.com> <1435254377-13322-2-git-send-email-jjherne@linux.vnet.ibm.com> <20150626180702.GK2186@work-vm> <5593F32F.6090909@redhat.com> In-Reply-To: <5593F32F.6090909@redhat.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3 1/5] cpu: Provide vcpu throttling interface Reply-To: jjherne@linux.vnet.ibm.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , "Dr. David Alan Gilbert" Cc: amit.shah@redhat.com, borntraeger@de.ibm.com, quintela@redhat.com, qemu-devel@nongnu.org, afaerber@suse.de On 07/01/2015 10:03 AM, Paolo Bonzini wrote: > > > On 26/06/2015 20:07, Dr. David Alan Gilbert wrote: >> * Jason J. Herne (jjherne@linux.vnet.ibm.com) wrote: >>> Provide a method to throttle guest cpu execution. CPUState is augmented with >>> timeout controls and throttle start/stop functions. To throttle the guest cpu >>> the caller simply has to call the throttle set function and provide a percentage >>> of throttle time. >> >> I'm worried about atomicity and threads and all those fun things. >> >> I think all the starting/stopping/setting the throttling level is done in the >> migration thread; I think the timers run in the main/io thread? >> So you really need to be careful with at least: >> throttle_timer_stop - which may have a minor effect >> throttle_timer - I worry about the way cpu_timer_active checks the pointer >> yet it's freed when the timer goes off. It's probably >> not too bad because it never dereferences it. > > Agreed. I think the only atomic should be throttle_percentage; if zero, > throttling is inactive. > > In particular, throttle_ratio can be computed in cpu_throttle_thread. > > If you have exactly one variable that is shared between the threads, > everything is much simpler. > > There is no need to allocate and free the timer; it's very cheap and in > fact we probably should convert to statically allocated timers sooner or > later. So you can just create it once, for example in cpu_ticks_init. > I've made all of the changes you have suggested except adding atomics. I'm having a bit of trouble figuring out what is needed here. Perhaps I should be using atomic_read() to read throttle_percentage? If so, I don't undertand why. Rather than trying to explain everything here I'm going to submit my V4 patches. If any atomic operations are still necessary with V4 please let me know. -- -- Jason J. Herne (jjherne@linux.vnet.ibm.com)