All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel <qemu-devel@nongnu.org>, abarcelo@ac.upc.edu
Subject: Re: [Qemu-devel] Coroutines and ucontext
Date: Fri, 27 Jan 2012 15:39:22 +0100	[thread overview]
Message-ID: <4F22B71A.3020805@redhat.com> (raw)
In-Reply-To: <CAFKAgTcca=ObcO1yJuxFm2UR-qsF964vhjFMR=AOvNL+7sbkcA@mail.gmail.com>

On 01/27/2012 01:39 PM, Alex Barcelo wrote:
> 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).

You can post it, don't worry.  I'm curious how you are switching stacks 
when creating the coroutine.

> 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).

Booting a guest (even a raw image will do) is a decent smoke test.

> 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"?

It's because you have to create a new stack for the new coroutine. 
makecontext does it for you; you can later use it with setcontext. 
Anything else (getcontext+setcontext, setjmp+longjmp, 
sigsetjmp+siglongjmp) will only work on an existing stack.

> But which system call are we talking about?

sigprocmask, which is invoked by sigsetjmp/siglongjmp and also 
getcontext/setcontext.  That's what we want to avoid.

Paolo

  reply	other threads:[~2012-01-27 14:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-27 12:39 [Qemu-devel] Coroutines and ucontext Alex Barcelo
2012-01-27 14:39 ` Paolo Bonzini [this message]
2012-01-27 14:48   ` Daniel P. Berrange
2012-01-28  9:31   ` Alex Barcelo
2012-02-07 11:18     ` Stefan Hajnoczi
2012-02-07 16:06       ` Alex Barcelo
2012-02-07 16:23         ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F22B71A.3020805@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=abarcelo@ac.upc.edu \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.