From nobody Sun Oct 26 01:44:59 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 151506272575562.44817018056847; Thu, 4 Jan 2018 02:45:25 -0800 (PST) Received: from localhost ([::1]:48215 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX31T-0002xF-S5 for importer@patchew.org; Thu, 04 Jan 2018 05:45:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41363) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX308-00024N-BZ for qemu-devel@nongnu.org; Thu, 04 Jan 2018 05:43:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX307-0001Kw-IZ for qemu-devel@nongnu.org; Thu, 04 Jan 2018 05:43:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57830) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX307-0001KJ-Cf for qemu-devel@nongnu.org; Thu, 04 Jan 2018 05:43:55 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 53DAE4E8BC for ; Thu, 4 Jan 2018 10:43:54 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-34.pek2.redhat.com [10.72.12.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E47060E3F; Thu, 4 Jan 2018 10:43:48 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 18:43:34 +0800 Message-Id: <20180104104336.2794-2-peterx@redhat.com> In-Reply-To: <20180104104336.2794-1-peterx@redhat.com> References: <20180104104336.2794-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 04 Jan 2018 10:43:54 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v3 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-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 Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Peter Xu --- 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 Sun Oct 26 01:44:59 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 1515062814252656.1758879745092; Thu, 4 Jan 2018 02:46:54 -0800 (PST) Received: from localhost ([::1]:48224 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX32v-0003wm-Q8 for importer@patchew.org; Thu, 04 Jan 2018 05:46:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX30A-00026O-Eh for qemu-devel@nongnu.org; Thu, 04 Jan 2018 05:43:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX309-0001MA-Mi for qemu-devel@nongnu.org; Thu, 04 Jan 2018 05:43:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41862) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX309-0001Le-GU for qemu-devel@nongnu.org; Thu, 04 Jan 2018 05:43:57 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A0A1687620 for ; Thu, 4 Jan 2018 10:43:56 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-34.pek2.redhat.com [10.72.12.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7FBF609A0; Thu, 4 Jan 2018 10:43:54 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 18:43:35 +0800 Message-Id: <20180104104336.2794-3-peterx@redhat.com> In-Reply-To: <20180104104336.2794-1-peterx@redhat.com> References: <20180104104336.2794-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 04 Jan 2018 10:43:56 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v3 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-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. Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Hajnoczi Signed-off-by: Peter Xu --- 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 Sun Oct 26 01:44:59 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 1515062897095226.42131439652997; Thu, 4 Jan 2018 02:48:17 -0800 (PST) Received: from localhost ([::1]:48227 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX34I-0004jU-2n for importer@patchew.org; Thu, 04 Jan 2018 05:48:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX30L-0002JA-Qs for qemu-devel@nongnu.org; Thu, 04 Jan 2018 05:44:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX30I-0001RW-M2 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 05:44:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47330) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX30I-0001R8-DA for qemu-devel@nongnu.org; Thu, 04 Jan 2018 05:44:06 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87E27780D9 for ; Thu, 4 Jan 2018 10:44:05 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-34.pek2.redhat.com [10.72.12.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20C0C609A0; Thu, 4 Jan 2018 10:43:56 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 18:43:36 +0800 Message-Id: <20180104104336.2794-4-peterx@redhat.com> In-Reply-To: <20180104104336.2794-1-peterx@redhat.com> References: <20180104104336.2794-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 04 Jan 2018 10:44:05 +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 v3 3/3] chardev: introduce qemu_chr_timeout_add_ms() 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_ms() 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. Also, in pty_chr_rearm_timer() the GSource name is not user visible, and does not really matter much. Unify the two calls into one. Signed-off-by: Peter Xu --- chardev/char-pty.c | 9 ++------- chardev/char-socket.c | 6 ++++-- chardev/char.c | 21 +++++++++++++++++++++ hw/char/terminal3270.c | 7 ++++--- include/chardev/char.h | 3 +++ 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/chardev/char-pty.c b/chardev/char-pty.c index dd17b1b823..2b37ad55ed 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_ms(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..9527314708 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -73,8 +73,10 @@ 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_ms(chr, + s->reconnect_time * 1000, + socket_reconnect_timeout, + chr); 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..d77787d67a 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -1084,6 +1084,27 @@ 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. Returns the ID of the timeout GSource in + * gcontext of the chardev. + */ +guint qemu_chr_timeout_add_ms(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..b0f81d0d16 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_ms(t->chr.chr, 600 * 1000, + 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_ms(t->chr.chr, 600 * 1000, + 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..f1b67af4d2 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -256,6 +256,9 @@ Chardev *qemu_chardev_new(const char *id, const char *t= ypename, =20 extern int term_escape_char; =20 +guint qemu_chr_timeout_add_ms(Chardev *chr, guint ms, GSourceFunc func, + void *private); + /* console.c */ void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend, Error **er= rp); =20 --=20 2.14.3