From patchwork Fri Mar 8 16:53:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 10845177 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 54DF01575 for ; Fri, 8 Mar 2019 16:58:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3CCB22DFB9 for ; Fri, 8 Mar 2019 16:58:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30A222DFCB; Fri, 8 Mar 2019 16:58:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D68F62DFB9 for ; Fri, 8 Mar 2019 16:58:40 +0000 (UTC) Received: from localhost ([127.0.0.1]:46863 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2IpU-0007Cx-0u for patchwork-qemu-devel@patchwork.kernel.org; Fri, 08 Mar 2019 11:58:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60383) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2Ild-0003sg-Fh for qemu-devel@nongnu.org; Fri, 08 Mar 2019 11:54:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h2Ilb-0006Ko-Fe for qemu-devel@nongnu.org; Fri, 08 Mar 2019 11:54:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34726) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h2IlV-0006Em-QN; Fri, 08 Mar 2019 11:54:34 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1F827883CA; Fri, 8 Mar 2019 16:54:32 +0000 (UTC) Received: from localhost (ovpn-117-209.ams2.redhat.com [10.36.117.209]) by smtp.corp.redhat.com (Postfix) with ESMTP id A4296600CD; Fri, 8 Mar 2019 16:54:31 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Fri, 8 Mar 2019 16:53:43 +0000 Message-Id: <20190308165344.10685-7-stefanha@redhat.com> In-Reply-To: <20190308165344.10685-1-stefanha@redhat.com> References: <20190308165344.10685-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 08 Mar 2019 16:54:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 6/7] iothread: push gcontext earlier in the thread_fn X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-block@nongnu.org, "Michael S. Tsirkin" , Peter Xu , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Peter Xu 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. Signed-off-by: Peter Xu Message-id: 20190306115532.23025-5-peterx@redhat.com Message-Id: <20190306115532.23025-5-peterx@redhat.com> [Tweaked comment wording as discussed with Peter Xu. --Stefan] Signed-off-by: Stefan Hajnoczi --- iothread.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/iothread.c b/iothread.c index 9abdbace66..ad64c757ac 100644 --- a/iothread.c +++ b/iothread.c @@ -53,7 +53,11 @@ static void *iothread_run(void *opaque) IOThread *iothread = opaque; rcu_register_thread(); - + /* + * g_main_context_push_thread_default() must be called before anything + * in this new thread uses glib. + */ + g_main_context_push_thread_default(iothread->worker_context); my_iothread = iothread; iothread->thread_id = qemu_get_thread_id(); qemu_sem_post(&iothread->init_done_sem); @@ -66,12 +70,11 @@ static void *iothread_run(void *opaque) * changed in previous aio_poll() */ if (iothread->running && atomic_read(&iothread->run_gcontext)) { - g_main_context_push_thread_default(iothread->worker_context); g_main_loop_run(iothread->main_loop); - g_main_context_pop_thread_default(iothread->worker_context); } } + g_main_context_pop_thread_default(iothread->worker_context); rcu_unregister_thread(); return NULL; }