From nobody Sat Nov 1 08:16:06 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1526376305790226.58210338398305; Tue, 15 May 2018 02:25:05 -0700 (PDT) Received: from localhost ([::1]:53894 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIWCe-0000Pl-Rt for importer@patchew.org; Tue, 15 May 2018 05:25:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIW6y-0004HW-Hi for qemu-devel@nongnu.org; Tue, 15 May 2018 05:19:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIW6s-0001V9-EX for qemu-devel@nongnu.org; Tue, 15 May 2018 05:19:12 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34910 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fIW6s-0001Uf-6J; Tue, 15 May 2018 05:19:06 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9307341AE7CE; Tue, 15 May 2018 09:19:05 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-49.ams2.redhat.com [10.36.116.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17EB72024CBE; Tue, 15 May 2018 09:19:05 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id EC4613F121; Tue, 15 May 2018 11:19:01 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 15 May 2018 11:19:00 +0200 Message-Id: <20180515091901.27774-10-kraxel@redhat.com> In-Reply-To: <20180515091901.27774-1-kraxel@redhat.com> References: <20180515091901.27774-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 15 May 2018 09:19:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 15 May 2018 09:19:05 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kraxel@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 09/10] console: use linked list for QemuConsoles 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: qemu-trivial@nongnu.org, Paolo Bonzini , Michael Tokarev , Laurent Vivier , Gerd Hoffmann 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" Signed-off-by: Gerd Hoffmann Message-id: 20180507095424.16220-1-kraxel@redhat.com --- ui/console.c | 105 +++++++++++++++++++++++++++++++++----------------------= ---- 1 file changed, 58 insertions(+), 47 deletions(-) diff --git a/ui/console.c b/ui/console.c index b02510cdca..945f05d728 100644 --- a/ui/console.c +++ b/ui/console.c @@ -165,6 +165,8 @@ struct QemuConsole { QEMUFIFO out_fifo; uint8_t out_fifo_buf[16]; QEMUTimer *kbd_timer; + + QTAILQ_ENTRY(QemuConsole) next; }; =20 struct DisplayState { @@ -180,8 +182,8 @@ struct DisplayState { =20 static DisplayState *display_state; static QemuConsole *active_console; -static QemuConsole **consoles; -static int nb_consoles =3D 0; +static QTAILQ_HEAD(consoles_head, QemuConsole) consoles =3D + QTAILQ_HEAD_INITIALIZER(consoles); static bool cursor_visible_phase; static QEMUTimer *cursor_timer; =20 @@ -197,7 +199,7 @@ static void gui_update(void *opaque) uint64_t dcl_interval; DisplayState *ds =3D opaque; DisplayChangeListener *dcl; - int i; + QemuConsole *con; =20 ds->refreshing =3D true; dpy_refresh(ds); @@ -212,9 +214,9 @@ static void gui_update(void *opaque) } if (ds->update_interval !=3D interval) { ds->update_interval =3D interval; - for (i =3D 0; i < nb_consoles; i++) { - if (consoles[i]->hw_ops->update_interval) { - consoles[i]->hw_ops->update_interval(consoles[i]->hw, inte= rval); + QTAILQ_FOREACH(con, &consoles, next) { + if (con->hw_ops->update_interval) { + con->hw_ops->update_interval(con->hw, interval); } } trace_console_refresh(interval); @@ -1292,10 +1294,13 @@ static QemuConsole *new_console(DisplayState *ds, c= onsole_type_t console_type, s->ds =3D ds; s->console_type =3D console_type; =20 - consoles =3D g_realloc(consoles, sizeof(*consoles) * (nb_consoles+1)); - if (console_type !=3D GRAPHIC_CONSOLE || qdev_hotplug) { - s->index =3D nb_consoles; - consoles[nb_consoles++] =3D s; + if (QTAILQ_EMPTY(&consoles)) { + s->index =3D 0; + QTAILQ_INSERT_TAIL(&consoles, s, next); + } else if (console_type !=3D GRAPHIC_CONSOLE || qdev_hotplug) { + QemuConsole *last =3D QTAILQ_LAST(&consoles, consoles_head); + s->index =3D last->index + 1; + QTAILQ_INSERT_TAIL(&consoles, s, next); } else { /* * HACK: Put graphical consoles before text consoles. @@ -1303,15 +1308,24 @@ static QemuConsole *new_console(DisplayState *ds, c= onsole_type_t console_type, * Only do that for coldplugged devices. After initial device * initialization we will not renumber the consoles any more. */ - for (i =3D nb_consoles; i > 0; i--) { - if (consoles[i - 1]->console_type =3D=3D GRAPHIC_CONSOLE) - break; - consoles[i] =3D consoles[i - 1]; - consoles[i]->index =3D i; + QemuConsole *c =3D QTAILQ_FIRST(&consoles); + + while (QTAILQ_NEXT(c, next) !=3D NULL && + c->console_type =3D=3D GRAPHIC_CONSOLE) { + c =3D QTAILQ_NEXT(c, next); + } + if (c->console_type =3D=3D GRAPHIC_CONSOLE) { + /* have no text consoles */ + s->index =3D c->index + 1; + QTAILQ_INSERT_AFTER(&consoles, c, s, next); + } else { + s->index =3D c->index; + QTAILQ_INSERT_BEFORE(c, s, next); + /* renumber text consoles */ + for (i =3D s->index + 1; c !=3D NULL; c =3D QTAILQ_NEXT(c, nex= t), i++) { + c->index =3D i; + } } - s->index =3D i; - consoles[i] =3D s; - nb_consoles++; } return s; } @@ -1861,21 +1875,21 @@ static DisplayState *get_alloc_displaystate(void) DisplayState *init_displaystate(void) { gchar *name; - int i; + QemuConsole *con; =20 get_alloc_displaystate(); - for (i =3D 0; i < nb_consoles; i++) { - if (consoles[i]->console_type !=3D GRAPHIC_CONSOLE && - consoles[i]->ds =3D=3D NULL) { - text_console_do_init(consoles[i]->chr, display_state); + QTAILQ_FOREACH(con, &consoles, next) { + if (con->console_type !=3D GRAPHIC_CONSOLE && + con->ds =3D=3D NULL) { + text_console_do_init(con->chr, display_state); } =20 /* Hook up into the qom tree here (not in new_console()), once * all QemuConsoles are created and the order / numbering * doesn't change any more */ - name =3D g_strdup_printf("console[%d]", i); + name =3D g_strdup_printf("console[%d]", con->index); object_property_add_child(container_get(object_get_root(), "/backe= nd"), - name, OBJECT(consoles[i]), &error_abort); + name, OBJECT(con), &error_abort); g_free(name); } =20 @@ -1957,33 +1971,34 @@ void graphic_console_close(QemuConsole *con) =20 QemuConsole *qemu_console_lookup_by_index(unsigned int index) { - if (index >=3D nb_consoles) { - return NULL; + QemuConsole *con; + + QTAILQ_FOREACH(con, &consoles, next) { + if (con->index =3D=3D index) { + return con; + } } - return consoles[index]; + return NULL; } =20 QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head) { + QemuConsole *con; Object *obj; uint32_t h; - int i; =20 - for (i =3D 0; i < nb_consoles; i++) { - if (!consoles[i]) { - continue; - } - obj =3D object_property_get_link(OBJECT(consoles[i]), + QTAILQ_FOREACH(con, &consoles, next) { + obj =3D object_property_get_link(OBJECT(con), "device", &error_abort); if (DEVICE(obj) !=3D dev) { continue; } - h =3D object_property_get_uint(OBJECT(consoles[i]), + h =3D object_property_get_uint(OBJECT(con), "head", &error_abort); if (h !=3D head) { continue; } - return consoles[i]; + return con; } return NULL; } @@ -2013,22 +2028,19 @@ QemuConsole *qemu_console_lookup_by_device_name(con= st char *device_id, =20 QemuConsole *qemu_console_lookup_unused(void) { + QemuConsole *con; Object *obj; - int i; =20 - for (i =3D 0; i < nb_consoles; i++) { - if (!consoles[i]) { + QTAILQ_FOREACH(con, &consoles, next) { + if (con->hw_ops !=3D &unused_ops) { continue; } - if (consoles[i]->hw_ops !=3D &unused_ops) { - continue; - } - obj =3D object_property_get_link(OBJECT(consoles[i]), + obj =3D object_property_get_link(OBJECT(con), "device", &error_abort); if (obj !=3D NULL) { continue; } - return consoles[i]; + return con; } return NULL; } @@ -2130,12 +2142,11 @@ static void text_console_update_cursor_timer(void) static void text_console_update_cursor(void *opaque) { QemuConsole *s; - int i, count =3D 0; + int count =3D 0; =20 cursor_visible_phase =3D !cursor_visible_phase; =20 - for (i =3D 0; i < nb_consoles; i++) { - s =3D consoles[i]; + QTAILQ_FOREACH(s, &consoles, next) { if (qemu_console_is_graphic(s) || !qemu_console_is_visible(s)) { continue; --=20 2.9.3