From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56270) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YayjG-0000Im-Jc for qemu-devel@nongnu.org; Wed, 25 Mar 2015 23:45:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YayjB-00009Z-L0 for qemu-devel@nongnu.org; Wed, 25 Mar 2015 23:45:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45997) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YayjB-00007B-CE for qemu-devel@nongnu.org; Wed, 25 Mar 2015 23:45:05 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2Q3j4nN006996 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 25 Mar 2015 23:45:04 -0400 Date: Thu, 26 Mar 2015 11:45:02 +0800 From: Fam Zheng Message-ID: <20150326034502.GF14724@ad.nay.redhat.com> References: <20150325083139.GB14724@ad.nay.redhat.com> <20150325133113.GK22940@stefanha-thinkpad.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150325133113.GK22940@stefanha-thinkpad.redhat.com> Subject: Re: [Qemu-devel] AioContext of block jobs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: pbonzini@redhat.com, qemu-devel@nongnu.org On Wed, 03/25 13:31, Stefan Hajnoczi wrote: > On Wed, Mar 25, 2015 at 04:31:39PM +0800, Fam Zheng wrote: > > I was looking at block jobs' AioContext and realized that the block job > > coroutines are actually started in main loop. > > > > I'm confused because 5a7e7a0bad17c96e03f55ed7019e2d7545e21a96 and friends in > > the series [1] seem to move the coroutines to the BDS's iothreads, but it > > didn't do that. > > > > (Although after the first block_job_yield or sleep, the coroutines ARE resumed > > in the right AioContext.) > > > > Why is it safe to start the jobs from the main thread where QMP command is > > handled? I see no guarantee that the jobs won't access BDS before first yield > > but after releasing the AioContext. > > Is there a concrete case you are worried about? No, I just missed that aio_context_release is only called after the first block job coroutine yield. Thanks for explaining. Fam > > For example: > void qmp_block_stream(const char *device, > ... > stream_start(bs, base_bs, base_name, has_speed ? speed : 0, > on_error, block_job_cb, bs, &local_err); > if (local_err) { > error_propagate(errp, local_err); > goto out; > } > > trace_qmp_block_stream(bs, bs->job); > > out: > aio_context_release(aio_context); <---- > } > > Since the BDS AioContext is held during stream_start, there is no race > condition. > > The resources used by the coroutine (i.e. timers or the BDS) bind their event > handler functions to the AioContext. This means the coroutine will only be > entered again under the AioContext in the future. > > Stefan