Received: from eggs.gnu.org ([2001:4830:134:3::10]:39297) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YalOz-0007ND-Dq for qemu-devel@nongnu.org; Wed, 25 Mar 2015 09:31:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YalOu-0007zx-IW for qemu-devel@nongnu.org; Wed, 25 Mar 2015 09:31:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51673) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YalOu-0007zj-Cr for qemu-devel@nongnu.org; Wed, 25 Mar 2015 09:31:16 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id E1A87B5BF6 for ; Wed, 25 Mar 2015 13:31:15 +0000 (UTC) Date: Wed, 25 Mar 2015 13:31:13 +0000 From: Stefan Hajnoczi Message-ID: <20150325133113.GK22940@stefanha-thinkpad.redhat.com> References: <20150325083139.GB14724@ad.nay.redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="0FM4RQAc0jwHekq5" Content-Disposition: inline In-Reply-To: <20150325083139.GB14724@ad.nay.redhat.com> Subject: Re: [Qemu-devel] AioContext of block jobs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: pbonzini@redhat.com, qemu-devel@nongnu.org --0FM4RQAc0jwHekq5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. >=20 > 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. >=20 > (Although after the first block_job_yield or sleep, the coroutines ARE re= sumed > in the right AioContext.) >=20 > 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 y= ield > but after releasing the AioContext. Is there a concrete case you are worried about? For example: void qmp_block_stream(const char *device, =2E.. 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 eve= nt handler functions to the AioContext. This means the coroutine will only be entered again under the AioContext in the future. Stefan --0FM4RQAc0jwHekq5 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJVErihAAoJEJykq7OBq3PIaakIAJGv6wZ7zBJdcxvAxRiDblkS 4MdqdZNfWgygLb9uvHkIJ1wlNG7sIbFwuUhadRMuEB7m5A0dt5vWUC/QKrOQAACp bfVUkdUXc4PIafxW3wJkykl5tt0RMDvADKWL/qg7Oe85bWoT9rSMTmfW4lKCfaZQ nuDyaH2EI3GBX2jWnOzgE2No5DPYdQe+cAoKIL6qnojKHn3X3OPpWPV2q+SEh18i gPzzI8cB0xX2DfTq+lG0o1cTQ/rnqAKywbip9ARU+1iOuVAvX8k4bvf3N1N5g86L CmXKO0JrMNQ/fHkvJJwQWVc8ZFQyQCqlQfwFgJC4URLgDiUVmghm2iW0ccD0ceE= =CH2/ -----END PGP SIGNATURE----- --0FM4RQAc0jwHekq5--