Received: from eggs.gnu.org ([140.186.70.92]:45573) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QaTSX-0003ex-OV for qemu-devel@nongnu.org; Sat, 25 Jun 2011 10:03:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QaTSV-0005Hi-Rw for qemu-devel@nongnu.org; Sat, 25 Jun 2011 10:03:41 -0400 Received: from fmmailgate01.web.de ([217.72.192.221]:38589) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QaTSV-0005HY-4w for qemu-devel@nongnu.org; Sat, 25 Jun 2011 10:03:39 -0400 Message-Id: <488AF283-4817-43AC-B61F-E146487D3460@web.de> From: =?ISO-8859-1?Q?Andreas_F=E4rber?= In-Reply-To: <1307911585-22106-3-git-send-email-stefanha@linux.vnet.ibm.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v936) Date: Sat, 25 Jun 2011 16:03:36 +0200 References: <1307911585-22106-1-git-send-email-stefanha@linux.vnet.ibm.com> <1307911585-22106-3-git-send-email-stefanha@linux.vnet.ibm.com> Sender: andreas.faerber@web.de Subject: Re: [Qemu-devel] [PATCH v5 2/5] coroutine: introduce coroutines List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Kevin Wolf , Anthony Liguori , qemu-devel@nongnu.org, Blue Swirl , "Aneesh Kumar K.V" , Paolo Bonzini , Venkateswararao Jujjuri Am 12.06.2011 um 22:46 schrieb Stefan Hajnoczi: > From: Kevin Wolf > > Asynchronous code is becoming very complex. At the same time > synchronous code is growing because it is convenient to write. > Sometimes duplicate code paths are even added, one synchronous and the > other asynchronous. This patch introduces coroutines which allow code > that looks synchronous but is asynchronous under the covers. > > A coroutine has its own stack and is therefore able to preserve state > across blocking operations, which traditionally require callback > functions and manual marshalling of parameters. > > Creating and starting a coroutine is easy: > > coroutine = qemu_coroutine_create(my_coroutine); > qemu_coroutine_enter(coroutine, my_data); > > The coroutine then executes until it returns or yields: > > void coroutine_fn my_coroutine(void *opaque) { > MyData *my_data = opaque; > > /* do some work */ > > qemu_coroutine_yield(); > > /* do some more work */ > } > > Yielding switches control back to the caller of > qemu_coroutine_enter(). > This is typically used to switch back to the main thread's event loop > after issuing an asynchronous I/O request. The request callback will > then invoke qemu_coroutine_enter() once more to switch back to the > coroutine. > > Note that if coroutines are used only from threads which hold the > global > mutex they will never execute concurrently. This makes programming > with > coroutines easier than with threads. Race conditions cannot occur > since > only one coroutine may be active at any time. Other coroutines can > only > run across yield. > > This coroutines implementation is based on the gtk-vnc implementation > written by Anthony Liguori but it has been > significantly rewritten by Kevin Wolf to use > setjmp()/longjmp() instead of the more expensive swapcontext() and by > Paolo Bonzini for Windows Fibers support. > > Signed-off-by: Kevin Wolf > Signed-off-by: Stefan Hajnoczi > --- > Makefile.objs | 7 ++ > coroutine-ucontext.c | 229 +++++++++++++++++++++++++++++++++++++++++ > +++++++++ > coroutine-win32.c | 92 ++++++++++++++++++++ > qemu-coroutine-int.h | 48 +++++++++++ > qemu-coroutine.c | 75 ++++++++++++++++ > qemu-coroutine.h | 95 +++++++++++++++++++++ > trace-events | 5 + > 7 files changed, 551 insertions(+), 0 deletions(-) > create mode 100644 coroutine-ucontext.c > create mode 100644 coroutine-win32.c > create mode 100644 qemu-coroutine-int.h > create mode 100644 qemu-coroutine.c > create mode 100644 qemu-coroutine.h > diff --git a/trace-events b/trace-events > index e0e9574..e0a4d83 100644 > --- a/trace-events > +++ b/trace-events > @@ -386,3 +386,8 @@ disable xen_unmap_block(void* addr, unsigned > long size) "%p, size %#lx" > > # exec.c > disable qemu_put_ram_ptr(void* addr) "%p" > + > +# qemu-coroutine.c > +disable qemu_coroutine_enter(void *from, void *to, void *opaque) > "from %p to %p opaque %p" > +disable qemu_coroutine_yield(void *from, void *to) "from %p to %p" > +disable qemu_coroutine_terminate(void *co) "self %p" This hunk no longer applies. Andreas