From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:36044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QldpN-00031d-SS for qemu-devel@nongnu.org; Tue, 26 Jul 2011 05:21:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QldpK-0000Cb-2I for qemu-devel@nongnu.org; Tue, 26 Jul 2011 05:21:25 -0400 Received: from mtagate2.uk.ibm.com ([194.196.100.162]:45097) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QldpJ-0000C3-R9 for qemu-devel@nongnu.org; Tue, 26 Jul 2011 05:21:22 -0400 Received: from d06nrmr1307.portsmouth.uk.ibm.com (d06nrmr1307.portsmouth.uk.ibm.com [9.149.38.129]) by mtagate2.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p6Q9LJQx022363 for ; Tue, 26 Jul 2011 09:21:19 GMT Received: from d06av06.portsmouth.uk.ibm.com (d06av06.portsmouth.uk.ibm.com [9.149.37.217]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p6Q9LJQV2297884 for ; Tue, 26 Jul 2011 10:21:19 +0100 Received: from d06av06.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p6Q9LJPL016485 for ; Tue, 26 Jul 2011 03:21:19 -0600 From: Stefan Hajnoczi Date: Tue, 26 Jul 2011 10:21:12 +0100 Message-Id: <1311672077-4592-1-git-send-email-stefanha@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v8 0/5] Coroutines for better asynchronous programming List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Blue Swirl , Anthony Liguori , Venkateswararao Jujjuri , Stefan Hajnoczi QEMU is event-driven and suffers when blocking operations are performed b= ecause VM execution may be stopped until the operation completes. Therefore man= y operations that could block are performed asynchronously and a callback i= s invoked when the operation has completed. This allows QEMU to continue executing while the operation is pending. The downside to callbacks is that they split up code into many smaller functions, each of which is a single step in a state machine that quickly becomes complex and hard to understand. Callback functions also result i= n lots of noise as variables are packed and unpacked into temporary structs that= pass state to the callback function. This patch series introduces coroutines as a solution for writing asynchr= onous code while still having a nice sequential control flow. The semantics ar= e explained in the second patch. The fourth patch adds automated tests. A nice feature of coroutines is that it is relatively easy to take synchr= onous code and lift it into a coroutine to make it asynchronous. Work has been= done to move qcow2 request processing into coroutines and thereby make it asynchronous (today qcow2 will perform synchronous metadata accesses). T= his qcow2 work is still ongoing and not quite ready for mainline yet. v8: * Bisectability: introduce gthread implementation before ucontext/fibers v7: * Reduce ucontext and win32 fiber stack size to 1 MB * Add qemu-timer-common.o to test-coroutine dependencies for OpenBSD bui= ld v6: * Use GThread on Mac OS X, fix from Andreas F=C3=A4rber * abort(3) if coroutine-ucontext.c fails to create a coroutine v5: * GThread-based implementation for platforms without makecontext(3) (Ane= esh Kumar K.V ) * Switch to gtester test framework v4: * Windows Fibers support (Paolo Bonzini ) * Return-after-setjmp() fix (Aneesh Kumar K.V ) * Re-entrancy for multi-threaded coroutines support * qemu-coroutine.h cleanup and documentation v3: * Updated LGPL v2 license header to use web link * Removed atexit(3) pool freeing * Removed thread-local current/leader * Documented thread-safety limitation * Disabled trace events v2: * Added ./check-coroutine --lifecycle-benchmark for performance measurem= ent * Split pooling into a separate patch with performance justification * Set maximum pool size to prevent holding onto too many free coroutines * Added atexit(3) handler to free pool * Coding style cleanups Kevin Wolf (1): coroutine: add ucontext and win32 implementations Stefan Hajnoczi (4): coroutine: add gthread dependency coroutine: introduce coroutines API coroutine: add test-coroutine automated tests coroutine: add test-coroutine --benchmark-lifecycle .gitignore | 1 + Makefile | 3 +- Makefile.objs | 11 +++ configure | 24 +++++- coroutine-gthread.c | 131 ++++++++++++++++++++++++++++ coroutine-ucontext.c | 230 ++++++++++++++++++++++++++++++++++++++++++++= ++++++ coroutine-win32.c | 91 ++++++++++++++++++++ qemu-coroutine-int.h | 48 +++++++++++ qemu-coroutine.c | 75 ++++++++++++++++ qemu-coroutine.h | 95 +++++++++++++++++++++ test-coroutine.c | 192 +++++++++++++++++++++++++++++++++++++++++ trace-events | 5 + 12 files changed, 902 insertions(+), 4 deletions(-) create mode 100644 coroutine-gthread.c 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 create mode 100644 test-coroutine.c --=20 1.7.5.4