From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35865) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YL8gw-0000P1-EH for qemu-devel@nongnu.org; Tue, 10 Feb 2015 06:09:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YL8gs-0003Ht-5b for qemu-devel@nongnu.org; Tue, 10 Feb 2015 06:09:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43268) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YL8gr-0003Hh-UR for qemu-devel@nongnu.org; Tue, 10 Feb 2015 06:09:14 -0500 Date: Tue, 10 Feb 2015 12:09:07 +0100 From: Kevin Wolf Message-ID: <20150210110907.GD5202@noname.str.redhat.com> References: <1423564888-14933-1-git-send-email-kwolf@redhat.com> <1423564888-14933-3-git-send-email-kwolf@redhat.com> <54D9E3BF.1090109@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <54D9E3BF.1090109@redhat.com> Subject: Re: [Qemu-devel] [PATCH 2/3] coroutine: Clean up qemu_coroutine_enter() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: wu.wubin@huawei.com, famz@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com Am 10.02.2015 um 11:55 hat Paolo Bonzini geschrieben: > > > On 10/02/2015 11:41, Kevin Wolf wrote: > > + ret = qemu_coroutine_switch(self, co, COROUTINE_ENTER); > > + > > + qemu_co_queue_run_restart(co); > > + > > + switch (ret) { > > + case COROUTINE_YIELD: > > + return; > > + case COROUTINE_TERMINATE: > > + trace_qemu_coroutine_terminate(co); > > + coroutine_delete(co); > > + return; > > + default: > > Say you have: > > co1 co2 > ------------------------------------------------------------------------ > 1 qemu_co_mutex_lock(&m); > 2 qemu_coroutine_yield(); > 3 qemu_co_mutex_lock(&m); > 4 qemu_co_mutex_unlock(&m); > 5 qemu_coroutine_yield(); > > Then you have: > > 1 mutex->locked = true; > > 2 coroutine_swap(co1, leader, COROUTINE_YIELD); > > 3 while (mutex->locked) { > qemu_co_queue_wait(&mutex->queue); > '--> QTAILQ_INSERT_TAIL(&queue->entries, self, co_queue_next); > qemu_coroutine_yield(); > '--> coroutine_swap(co2, leader, COROUTINE_YIELD); > } > > 4 mutex->locked = false; > qemu_co_queue_next(&mutex->queue); > '--> qemu_co_queue_do_restart(queue, true); > '--> QTAILQ_REMOVE(&queue->entries, next, co_queue_next); > QTAILQ_INSERT_TAIL(&self->co_queue_wakeup, next, co_queue_next); > > 5 coroutine_swap(co1, leader, COROUTINE_YIELD); > > And co2 is never reentered until co1 terminates. Right? No, co2 will be reentered during the yield in line 5. However, it's not the yielding coroutine that reenters it but the parent, which is resumed at exactly the line of code that you quoted above. This is actually how it always worked, even with the bug. The bug caused it to access the queue of a random other coroutine, but that queue must have always been empty because it was already processed when that other coroutine yielded/terminated. Kevin