From nobody Tue Oct 28 12:12:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1514446396360449.3557374151734; Wed, 27 Dec 2017 23:33:16 -0800 (PST) Received: from localhost ([::1]:39735 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUSgh-00036j-DX for importer@patchew.org; Thu, 28 Dec 2017 02:33:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38659) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUSde-0001Cu-8c for qemu-devel@nongnu.org; Thu, 28 Dec 2017 02:30:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eUSdd-0005DF-D8 for qemu-devel@nongnu.org; Thu, 28 Dec 2017 02:30:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58632) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eUSdd-0005Cv-7c for qemu-devel@nongnu.org; Thu, 28 Dec 2017 02:30:01 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 64BD2A799 for ; Thu, 28 Dec 2017 07:30:00 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-51.pek2.redhat.com [10.72.12.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D0425C269; Thu, 28 Dec 2017 07:29:57 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 28 Dec 2017 15:29:43 +0800 Message-Id: <20171228072945.9573-2-peterx@redhat.com> In-Reply-To: <20171228072945.9573-1-peterx@redhat.com> References: <20171228072945.9573-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 28 Dec 2017 07:30:00 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/3] chardev: use backend chr context when watch for fe 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: Paolo Bonzini , peterx@redhat.com, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In commit 6bbb6c0644 ("chardev: use per-dev context for io_add_watch_poll", 2017-09-22) all the chardev watches are converted to use per-chardev gcontext to support chardev to be run outside default main thread. However that's still missing one call from the frontend code. Touch that up. Reviewed-by: Stefan Hajnoczi Signed-off-by: Peter Xu Reviewed-by: Marc-Andr=C3=A9 Lureau --- chardev/char-fe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chardev/char-fe.c b/chardev/char-fe.c index ee6d596100..c611b3fa3e 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -356,7 +356,7 @@ guint qemu_chr_fe_add_watch(CharBackend *be, GIOConditi= on cond, } =20 g_source_set_callback(src, (GSourceFunc)func, user_data, NULL); - tag =3D g_source_attach(src, NULL); + tag =3D g_source_attach(src, s->gcontext); g_source_unref(src); =20 return tag; --=20 2.14.3 From nobody Tue Oct 28 12:12:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1514446476294967.2776147600233; Wed, 27 Dec 2017 23:34:36 -0800 (PST) Received: from localhost ([::1]:39779 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUSi3-0003pn-8S for importer@patchew.org; Thu, 28 Dec 2017 02:34:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38822) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUSdq-0001OS-Oz for qemu-devel@nongnu.org; Thu, 28 Dec 2017 02:30:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eUSdn-0005Tp-Kf for qemu-devel@nongnu.org; Thu, 28 Dec 2017 02:30:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46590) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eUSdn-0005S3-Et for qemu-devel@nongnu.org; Thu, 28 Dec 2017 02:30:11 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ACB305D698 for ; Thu, 28 Dec 2017 07:30:10 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-51.pek2.redhat.com [10.72.12.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id C843E5C888; Thu, 28 Dec 2017 07:30:00 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 28 Dec 2017 15:29:44 +0800 Message-Id: <20171228072945.9573-3-peterx@redhat.com> In-Reply-To: <20171228072945.9573-1-peterx@redhat.com> References: <20171228072945.9573-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 28 Dec 2017 07:30:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/3] chardev: let g_idle_add() be with chardev gcontext 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: Paolo Bonzini , peterx@redhat.com, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The idle task will be attached to main gcontext even if the chardev backend is running in another gcontext. Fix the only caller by extending the g_idle_add() logic into the more powerful g_source_attach(). It's basically g_idle_add_full() implementation, but with the chardev's gcontext passed in. Signed-off-by: Peter Xu Reviewed-by: Marc-Andr=C3=A9 Lureau --- chardev/char-pty.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/chardev/char-pty.c b/chardev/char-pty.c index 761ae6dec1..dd17b1b823 100644 --- a/chardev/char-pty.c +++ b/chardev/char-pty.c @@ -210,9 +210,14 @@ static void pty_chr_state(Chardev *chr, int connected) s->timer_tag =3D 0; } if (!s->connected) { + GSource *source =3D g_idle_source_new(); + g_assert(s->open_tag =3D=3D 0); s->connected =3D 1; - s->open_tag =3D g_idle_add(qemu_chr_be_generic_open_func, chr); + g_source_set_callback(source, qemu_chr_be_generic_open_func, + chr, NULL); + s->open_tag =3D g_source_attach(source, chr->gcontext); + g_source_unref(source); } if (!chr->gsource) { chr->gsource =3D io_add_watch_poll(chr, s->ioc, --=20 2.14.3 From nobody Tue Oct 28 12:12:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1514446324451501.12563932436456; Wed, 27 Dec 2017 23:32:04 -0800 (PST) Received: from localhost ([::1]:39684 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUSfV-0002BJ-94 for importer@patchew.org; Thu, 28 Dec 2017 02:31:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38893) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUSe1-0001TO-Qr for qemu-devel@nongnu.org; Thu, 28 Dec 2017 02:30:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eUSdy-0005fB-ET for qemu-devel@nongnu.org; Thu, 28 Dec 2017 02:30:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46716) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eUSdy-0005ee-4W for qemu-devel@nongnu.org; Thu, 28 Dec 2017 02:30:22 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F58EC058ED8 for ; Thu, 28 Dec 2017 07:30:21 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-51.pek2.redhat.com [10.72.12.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C56C5C269; Thu, 28 Dec 2017 07:30:10 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 28 Dec 2017 15:29:45 +0800 Message-Id: <20171228072945.9573-4-peterx@redhat.com> In-Reply-To: <20171228072945.9573-1-peterx@redhat.com> References: <20171228072945.9573-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 28 Dec 2017 07:30:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/3] chardev: introduce qemu_chr_timeout_add() and use 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: Paolo Bonzini , peterx@redhat.com, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It's a replacement of g_timeout_add[_seconds]() for chardevs. Chardevs now can have dedicated gcontext, we should always bind chardev tasks onto those gcontext rather than the default main context. Since there are quite a few of g_timeout_add[_seconds]() callers, a new function qemu_chr_timeout_add() is introduced. One thing to mention is that, terminal3270 is still always running on main gcontext. However let's convert that as well since it's still part of chardev codes and in case one day we'll miss that when we move it out of main gcontext too. Signed-off-by: Peter Xu --- chardev/char-pty.c | 9 ++------- chardev/char-socket.c | 4 ++-- chardev/char.c | 20 ++++++++++++++++++++ hw/char/terminal3270.c | 7 ++++--- include/chardev/char.h | 2 ++ 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/chardev/char-pty.c b/chardev/char-pty.c index dd17b1b823..cbd8ac5eb7 100644 --- a/chardev/char-pty.c +++ b/chardev/char-pty.c @@ -78,13 +78,8 @@ static void pty_chr_rearm_timer(Chardev *chr, int ms) s->timer_tag =3D 0; } =20 - if (ms =3D=3D 1000) { - name =3D g_strdup_printf("pty-timer-secs-%s", chr->label); - s->timer_tag =3D g_timeout_add_seconds(1, pty_chr_timer, chr); - } else { - name =3D g_strdup_printf("pty-timer-ms-%s", chr->label); - s->timer_tag =3D g_timeout_add(ms, pty_chr_timer, chr); - } + name =3D g_strdup_printf("pty-timer-ms-%s", chr->label); + s->timer_tag =3D qemu_chr_timeout_add(chr, ms, pty_chr_timer, chr); g_source_set_name_by_id(s->timer_tag, name); g_free(name); } diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 630a7f2995..644a620599 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -73,8 +73,8 @@ static void qemu_chr_socket_restart_timer(Chardev *chr) char *name; =20 assert(s->connected =3D=3D 0); - s->reconnect_timer =3D g_timeout_add_seconds(s->reconnect_time, - socket_reconnect_timeout, c= hr); + s->reconnect_timer =3D qemu_chr_timeout_add(chr, s->reconnect_time, + socket_reconnect_timeout, ch= r); name =3D g_strdup_printf("chardev-socket-reconnect-%s", chr->label); g_source_set_name_by_id(s->reconnect_timer, name); g_free(name); diff --git a/chardev/char.c b/chardev/char.c index 8c3765ee99..a1de662fec 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -1084,6 +1084,26 @@ void qmp_chardev_send_break(const char *id, Error **= errp) qemu_chr_be_event(chr, CHR_EVENT_BREAK); } =20 +/* + * Add a timeout callback for the chardev (in milliseconds). Please + * use this to add timeout hook for chardev instead of g_timeout_add() + * and g_timeout_add_seconds(), to make sure the gcontext that the + * task bound to is correct. + */ +guint qemu_chr_timeout_add(Chardev *chr, guint ms, GSourceFunc func, + void *private) +{ + GSource *source =3D g_timeout_source_new(ms); + guint id; + + assert(func); + g_source_set_callback(source, func, private, NULL); + id =3D g_source_attach(source, chr->gcontext); + g_source_unref(source); + + return id; +} + void qemu_chr_cleanup(void) { object_unparent(get_chardevs_root()); diff --git a/hw/char/terminal3270.c b/hw/char/terminal3270.c index a109ce5987..479e4554d6 100644 --- a/hw/char/terminal3270.c +++ b/hw/char/terminal3270.c @@ -94,8 +94,8 @@ static void terminal_read(void *opaque, const uint8_t *bu= f, int size) g_source_remove(t->timer_tag); t->timer_tag =3D 0; } - t->timer_tag =3D g_timeout_add_seconds(600, send_timing_mark_cb, t); - + t->timer_tag =3D qemu_chr_timeout_add(t->chr.chr, 600, + send_timing_mark_cb, t); memcpy(&t->inv[t->in_len], buf, size); t->in_len +=3D size; if (t->in_len < 2) { @@ -157,7 +157,8 @@ static void chr_event(void *opaque, int event) * char-socket.c. Once qemu receives the terminal-type of the * client, mark handshake done and trigger everything rolling agai= n. */ - t->timer_tag =3D g_timeout_add_seconds(600, send_timing_mark_cb, t= ); + t->timer_tag =3D qemu_chr_timeout_add(t->chr.chr, 600, + send_timing_mark_cb, t); break; case CHR_EVENT_CLOSED: sch->curr_status.scsw.dstat =3D SCSW_DSTAT_DEVICE_END; diff --git a/include/chardev/char.h b/include/chardev/char.h index 778d610295..4970e46457 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -258,5 +258,7 @@ extern int term_escape_char; =20 /* console.c */ void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend, Error **er= rp); +guint qemu_chr_timeout_add(Chardev *chr, guint ms, GSourceFunc func, + void *private); =20 #endif --=20 2.14.3