qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] Coroutines and ucontext


From: Alex Barcelo
Subject: [Qemu-devel] Coroutines and ucontext
Date: Fri, 27 Jan 2012 13:39:53 +0100

I have read that one of the reasons for using makecontext is that it
saves the signal state. But there also exist functions like
"sigsetjmp" and "siglongjmp" which can be used to jump around the
coroutines while preserving signal masks.

I have a patch that uses sigsetjmp and siglongjmp instead of
makecontext and getcontext (and all the ucontext stuff), and it
*seems* to work... but I'm not sure if it works "by accident" (not
sure what I'm doing to the stack, not sure what I should be doing to
the stack). I will test more, but first I wanted to ask a little bit
for advice and comments. (Well, I have to admit it: the only benchmark
I have done is "qemu-img create -f qcow2 imgfile.qcow2 5G"... an
extremely poor test, but enough to see if something works at all).

On a related side note, this is not very well-written:
    /* The ucontext functions preserve signal masks which incurs a system call
     * overhead.  setjmp()/longjmp() does not preserve signal masks but only
     * works on the current stack.  Since we need a way to create and switch to
     * a new stack, use the ucontext functions for that but setjmp()/longjmp()
     * for everything else.
     */
[coroutine-ucontext.c, static Coroutine *coroutine_new(void)]
Because it is not clear (IMHO) why are the exact reasons for not using
setjmp and longjmp. Is it because the signal masks? Or is it (also?)
because the "only works on the current stack"? But which system call
are we talking about? Related to stack or related to signals? The
"but" is very ill-placed. And my knowledge is far below the needed for
correcting (or maybe simply understanding) this... sorry.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]