From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43533) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZd7l-0003q5-0J for qemu-devel@nongnu.org; Wed, 09 Sep 2015 07:01:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZd7h-0003SO-Ln for qemu-devel@nongnu.org; Wed, 09 Sep 2015 07:01:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49208) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZd7h-0003SG-H6 for qemu-devel@nongnu.org; Wed, 09 Sep 2015 07:01:05 -0400 From: Juan Quintela In-Reply-To: <55F00F83.2080708@redhat.com> (Paolo Bonzini's message of "Wed, 9 Sep 2015 12:52:51 +0200") References: <1441732357-11861-1-git-send-email-jjherne@linux.vnet.ibm.com> <1441732357-11861-2-git-send-email-jjherne@linux.vnet.ibm.com> <87egi77u3f.fsf@neno.neno> <55F00F83.2080708@redhat.com> Date: Wed, 09 Sep 2015 13:01:03 +0200 Message-ID: <87a8sv6emo.fsf@neno.neno> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v7 1/5] cpu: Provide vcpu throttling interface Reply-To: quintela@redhat.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org, dgilbert@redhat.com, borntraeger@de.ibm.com, "Jason J. Herne" , amit.shah@redhat.com, afaerber@suse.de Paolo Bonzini wrote: > On 09/09/2015 12:41, Juan Quintela wrote: >>> > + qemu_mutex_unlock_iothread(); >>> > + atomic_set(&cpu->throttle_thread_scheduled, 0); >>> > + g_usleep(sleeptime_ns / 1000); /* Convert ns to us for usleep call */ >>> > + qemu_mutex_lock_iothread(); >> >> Why is this thread safe? >> >> qemu_mutex_lock_iothread() is protecting (at least) cpu_work_first on >> each cpu. How can we be sure that _nothing_ will change that while we >> are waiting? > > You only have to be sure that the queued work list remains consistent; > not that nothing changes. But nothing else is protected by the iothread? That is the part that I can't see. > (BTW, there is a queued patch that moves the queued work list to its own > mutex, and indeed it releases that mutex while calling the work function). >> A fast look through the tree don't show anything that >> runs here that drops the lock. > > Actually, the existing implementation of throttling does. :) See, that happens when you search in a modified tree O:-) Thanks for the fast answer. Later, Juan.