From nobody Fri Apr 26 04:44:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578927010; cv=none; d=zohomail.com; s=zohoarc; b=D73iaM5JzkM0zBsClongMYm2MgtMaYO/tx0LaCoLWfLbzUVRf+vbClniGWA6brZ6TviJ0FSLukC6+ZJu1S8HCrW1y4qCqtw8izltkmcuWYSdCaeALd3MAwHkc448d7d5laQqfRArKbfKMynlgo95vHBtfY0DjuRR4NokvasHgnE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578927010; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=z+3odn98lGZbn5vm1Ja+HRL/VbdKuBpWGFhaN0sKXIw=; b=P9S2s1xOEvf7LA73ZE1TED05QSF+F6Tu998/vv9S/3R31z9k98SxDdAeLT7NBgUeVwcPQK8vvMGlYl36PmS3kc4Zq8/80kwE2LAYN9HxFhvNpXR7l48TUFbYZPLsPhilF9Sk9fJM8ZBpJN+cwwfe+XSOq0IfXoKJfyba6fmsnQc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1578927010177672.4593267087135; Mon, 13 Jan 2020 06:50:10 -0800 (PST) Received: from localhost ([::1]:51392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ir12f-0003dr-5N for importer@patchew.org; Mon, 13 Jan 2020 09:50:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44050) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ir11e-00034L-R2 for qemu-devel@nongnu.org; Mon, 13 Jan 2020 09:49:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ir11c-0000Oy-GK for qemu-devel@nongnu.org; Mon, 13 Jan 2020 09:49:05 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:22604 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ir11c-0000Mq-9K for qemu-devel@nongnu.org; Mon, 13 Jan 2020 09:49:04 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-157-86u0fwzhNbaOw9NAA_AC0g-1; Mon, 13 Jan 2020 09:49:01 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1F2FB10BFB67 for ; Mon, 13 Jan 2020 14:49:00 +0000 (UTC) Received: from localhost (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CD535DA70; Mon, 13 Jan 2020 14:48:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578926943; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=z+3odn98lGZbn5vm1Ja+HRL/VbdKuBpWGFhaN0sKXIw=; b=Ep8FlFS/aAxEZa/p3HH3kbB/uX/pIZpcT2sqKyapBqGv3PX0HJ9b0kmSsfZA5Spr+YqL67 LxSD1X5OwZBPxH7ieuEmGHA3JaqZM0GPn579LX/CQ2FqfDKi9XkE/VhJ/Pu4mbW58qiALm AuvusD7xSa6pqvD4dK7vU/2WkcNODMQ= From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Subject: [PATCH] console: make QMP screendump use coroutine Date: Mon, 13 Jan 2020 18:48:48 +0400 Message-Id: <20200113144848.2168018-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: 86u0fwzhNbaOw9NAA_AC0g-1 X-Mimecast-Spam-Score: 0 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: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com, kraxel@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Thanks to the QMP coroutine support, the screendump handler can trigger a graphic_hw_update(), yield and let the main loop run until update is done. Then the handler is resumed, and the ppm_save() will write the screen image to disk in the coroutine context (thus non-blocking). For now, HMP doesn't have coroutine support, so it remains potentially outdated or glitched. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D1230527 Based-on: <20200109183545.27452-2-kwolf@redhat.com> Cc: Kevin Wolf Signed-off-by: Marc-Andr=C3=A9 Lureau --- qapi/ui.json | 3 ++- ui/console.c | 35 +++++++++++++++++++++++++++-------- ui/trace-events | 2 +- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/qapi/ui.json b/qapi/ui.json index e04525d8b4..d941202f34 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -96,7 +96,8 @@ # ## { 'command': 'screendump', - 'data': {'filename': 'str', '*device': 'str', '*head': 'int'} } + 'data': {'filename': 'str', '*device': 'str', '*head': 'int'}, + 'coroutine': true } =20 ## # =3D=3D Spice diff --git a/ui/console.c b/ui/console.c index ac79d679f5..db184b473f 100644 --- a/ui/console.c +++ b/ui/console.c @@ -167,6 +167,7 @@ struct QemuConsole { QEMUFIFO out_fifo; uint8_t out_fifo_buf[16]; QEMUTimer *kbd_timer; + Coroutine *screendump_co; =20 QTAILQ_ENTRY(QemuConsole) next; }; @@ -194,7 +195,6 @@ static void dpy_refresh(DisplayState *s); static DisplayState *get_alloc_displaystate(void); static void text_console_update_cursor_timer(void); static void text_console_update_cursor(void *opaque); -static bool ppm_save(int fd, DisplaySurface *ds, Error **errp); =20 static void gui_update(void *opaque) { @@ -263,6 +263,9 @@ static void gui_setup_refresh(DisplayState *ds) =20 void graphic_hw_update_done(QemuConsole *con) { + if (con && con->screendump_co) { + aio_co_wake(con->screendump_co); + } } =20 void graphic_hw_update(QemuConsole *con) @@ -310,16 +313,16 @@ void graphic_hw_invalidate(QemuConsole *con) } } =20 -static bool ppm_save(int fd, DisplaySurface *ds, Error **errp) +static bool ppm_save(int fd, pixman_image_t *image, Error **errp) { - int width =3D pixman_image_get_width(ds->image); - int height =3D pixman_image_get_height(ds->image); + int width =3D pixman_image_get_width(image); + int height =3D pixman_image_get_height(image); g_autoptr(Object) ioc =3D OBJECT(qio_channel_file_new_fd(fd)); g_autofree char *header =3D NULL; g_autoptr(pixman_image_t) linebuf =3D NULL; int y; =20 - trace_ppm_save(fd, ds); + trace_ppm_save(fd, image); =20 header =3D g_strdup_printf("P6\n%d %d\n%d\n", width, height, 255); if (qio_channel_write_all(QIO_CHANNEL(ioc), @@ -329,7 +332,7 @@ static bool ppm_save(int fd, DisplaySurface *ds, Error = **errp) =20 linebuf =3D qemu_pixman_linebuf_create(PIXMAN_BE_r8g8b8, width); for (y =3D 0; y < height; y++) { - qemu_pixman_linebuf_fill(linebuf, ds->image, width, 0, y); + qemu_pixman_linebuf_fill(linebuf, image, width, 0, y); if (qio_channel_write_all(QIO_CHANNEL(ioc), (char *)pixman_image_get_data(linebuf), pixman_image_get_stride(linebuf), errp) = < 0) { @@ -340,11 +343,18 @@ static bool ppm_save(int fd, DisplaySurface *ds, Erro= r **errp) return true; } =20 +static void graphic_hw_update_bh(void *con) +{ + graphic_hw_update(con); +} + +/* may be called in coroutine context or not */ void qmp_screendump(const char *filename, bool has_device, const char *dev= ice, bool has_head, int64_t head, Error **errp) { QemuConsole *con; DisplaySurface *surface; + g_autoptr(pixman_image_t) image =3D NULL; int fd; =20 if (has_device) { @@ -365,7 +375,15 @@ void qmp_screendump(const char *filename, bool has_dev= ice, const char *device, } } =20 - graphic_hw_update(con); + if (qemu_in_coroutine()) { + assert(!con->screendump_co); + con->screendump_co =3D qemu_coroutine_self(); + aio_bh_schedule_oneshot(qemu_get_aio_context(), + graphic_hw_update_bh, con); + qemu_coroutine_yield(); + con->screendump_co =3D NULL; + } + surface =3D qemu_console_surface(con); if (!surface) { error_setg(errp, "no surface"); @@ -379,7 +397,8 @@ void qmp_screendump(const char *filename, bool has_devi= ce, const char *device, return; } =20 - if (!ppm_save(fd, surface, errp)) { + image =3D pixman_image_ref(surface->image); + if (!ppm_save(fd, image, errp)) { qemu_unlink(filename); } } diff --git a/ui/trace-events b/ui/trace-events index 0dcda393c1..e8726fc969 100644 --- a/ui/trace-events +++ b/ui/trace-events @@ -15,7 +15,7 @@ displaysurface_create_pixman(void *display_surface) "surf= ace=3D%p" displaysurface_free(void *display_surface) "surface=3D%p" displaychangelistener_register(void *dcl, const char *name) "%p [ %s ]" displaychangelistener_unregister(void *dcl, const char *name) "%p [ %s ]" -ppm_save(int fd, void *display_surface) "fd=3D%d surface=3D%p" +ppm_save(int fd, void *image) "fd=3D%d image=3D%p" =20 # gtk.c # gtk-gl-area.c --=20 2.25.0.rc2.1.g09a9a1a997