qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Peter Xu <peterx@redhat.com>
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	qemu-devel <qemu-devel@nongnu.org>,
	"Stefan Hajnoczi" <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 4/4] iothread: push gcontext earlier in the thread_fn
Date: Fri, 1 Mar 2019 16:25:17 +0000	[thread overview]
Message-ID: <20190301162517.GC18260@stefanha-x1.localdomain> (raw)
In-Reply-To: <20190228055856.GV13653@xz-x1>

[-- Attachment #1: Type: text/plain, Size: 3429 bytes --]

On Thu, Feb 28, 2019 at 01:58:56PM +0800, Peter Xu wrote:
> On Wed, Feb 27, 2019 at 01:38:38PM +0000, Stefan Hajnoczi wrote:
> > On Fri, Feb 22, 2019 at 02:57:24PM +0800, Peter Xu wrote:
> > > On Fri, Feb 22, 2019 at 07:37:02AM +0100, Marc-André Lureau wrote:
> > > > Hi
> > > > 
> > > > On Fri, Feb 22, 2019 at 4:14 AM Peter Xu <peterx@redhat.com> wrote:
> > > > >
> > > > > We were pushing the context until right before running the gmainloop.
> > > > > Now since we have everything unconditionally, we can move this
> > > > > earlier.
> > > > >
> > > > > One benefit is that now it's done even before init_done_sem, so as
> > > > > long as the iothread user calls iothread_create() and completes, we
> > > > > know that the thread stack is ready.
> > > > >
> > > > 
> > > > This will change the default context in the iothread, for code running
> > > > there. This may not be a good idea. Until now, only sources dispatched
> > > > from iothread_get_g_main_context() would have default context
> > > > associated to it.
> > > > 
> > > > I don't know if the current behaviour is intentional, but it has some
> > > > logic. With this change, you may create hidden races, by changing the
> > > > default context of sources to the iothread.
> > > 
> > > Yes I agree that the behavior will be changed in this patch that even
> > > if the iothread user does not use the gcontext they'll also have the
> > > context set.  I would think it should be ok because IMHO events hooked
> > > onto the aio context should not depend on the gcontext, but indeed I'd
> > > like to get some confirmation from others, especially the block layer.
> > 
> > I don't understand why Patch 4 is desirable.  The comment about
> > init_done_sem isn't clear to me but I also wondered the same thing as
> > Marc-André.
> > 
> > Can you explain why we should apply this patch?
> 
> Hi, Stefan,
> 
> The patch 4 itself does not help much for current QEMU, but it should
> be required to replace the patch that Marc-Andre proposed below:
> 
> https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg05460.html [1]
> 
> And IMHO patch 4 along with this whole series should be a cleaner
> approach comparing to the one proposed in [1].  Here if my
> understanding is correct the problem is that
> g_main_context_push_thread_default() is really designed to be called
> at the very beginning of a thread creation but not dynamically called
> during the execution of a thread (prove is that it even does not have
> any error to return when failed to acquire the context so the caller
> will never know if it failed! see [2] below), in that sense this patch
> 4 can be seen as a tiny cleanup too.
> 
> g_main_context_push_thread_default (GMainContext *context)
> {
>   GQueue *stack;
>   gboolean acquired_context;
> 
>   acquired_context = g_main_context_acquire (context);
>   g_return_if_fail (acquired_context);  <------------- [2]
> 
>   ...
> }

I see.  This explains why you want to call it early.  If you're worried
about that then there should also be a comment warning people that this
must happen first before anything implicitly uses the thread's
GMainContext.

What about Marc-André's concern about the change in behavior?  Now this
thread is associated with the GMainContext that isn't processed at in
aio_poll().  Previously the default main context would be used.

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

  reply	other threads:[~2019-03-01 16:25 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-22  3:14 [Qemu-devel] [PATCH 0/4] iothread: create gcontext unconditionally Peter Xu
2019-02-22  3:14 ` [Qemu-devel] [PATCH 1/4] iothread: replace init_done_cond with a semaphore Peter Xu
2019-02-22  6:25   ` Marc-André Lureau
2019-02-22  6:36     ` Peter Xu
2019-02-22  9:27       ` Paolo Bonzini
2019-02-22  9:44         ` Marc-André Lureau
2019-02-27 13:26   ` Stefan Hajnoczi
2019-02-22  3:14 ` [Qemu-devel] [PATCH 2/4] iothread: create the gcontext onconditionally Peter Xu
2019-02-22  6:29   ` Marc-André Lureau
2019-02-22  6:47     ` Peter Xu
2019-02-22  3:14 ` [Qemu-devel] [PATCH 3/4] iothread: create main loop unconditionally Peter Xu
2019-02-22  6:30   ` Marc-André Lureau
2019-02-22  3:14 ` [Qemu-devel] [PATCH 4/4] iothread: push gcontext earlier in the thread_fn Peter Xu
2019-02-22  6:37   ` Marc-André Lureau
2019-02-22  6:57     ` Peter Xu
2019-02-22  9:24       ` Paolo Bonzini
2019-02-27 13:38       ` Stefan Hajnoczi
2019-02-28  5:58         ` Peter Xu
2019-03-01 16:25           ` Stefan Hajnoczi [this message]
2019-03-04  2:26             ` Peter Xu
2019-03-04  9:12               ` Marc-André Lureau
2019-03-04  9:37                 ` Peter Xu
2019-02-22  9:28 ` [Qemu-devel] [PATCH 0/4] iothread: create gcontext unconditionally Paolo Bonzini
2019-02-22  9:45   ` Peter Xu
2019-03-06 10:19 ` Stefan Hajnoczi
2019-03-06 11:44   ` Peter Xu

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=20190301162517.GC18260@stefanha-x1.localdomain \
    --to=stefanha@gmail.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).