From patchwork Sun Feb 19 21:28:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alon Levy X-Patchwork-Id: 142075 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A4C9FB6FA7 for ; Mon, 20 Feb 2012 09:05:42 +1100 (EST) Received: from localhost ([::1]:55590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RzEJL-0005Sc-Tb for incoming@patchwork.ozlabs.org; Sun, 19 Feb 2012 16:28:47 -0500 Received: from eggs.gnu.org ([140.186.70.92]:48582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RzEIy-0004Vo-F6 for qemu-devel@nongnu.org; Sun, 19 Feb 2012 16:28:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RzEIw-0004UO-GC for qemu-devel@nongnu.org; Sun, 19 Feb 2012 16:28:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33179) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RzEIw-0004UB-8k for qemu-devel@nongnu.org; Sun, 19 Feb 2012 16:28:22 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q1JLSLUH001224 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 19 Feb 2012 16:28:21 -0500 Received: from garlic.redhat.com (vpn-200-5.tlv.redhat.com [10.35.200.5]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q1JLS6Yt003257; Sun, 19 Feb 2012 16:28:19 -0500 From: Alon Levy To: qemu-devel@nongnu.org, kraxel@redhat.com, elmarco@redhat.com Date: Sun, 19 Feb 2012 23:28:04 +0200 Message-Id: <1329686886-6853-6-git-send-email-alevy@redhat.com> In-Reply-To: <1329686886-6853-1-git-send-email-alevy@redhat.com> References: <1329686886-6853-1-git-send-email-alevy@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC 5/7] qxl-render: call ppm_save on callback X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This changes the behavior of the monitor command. After the previous patch, there is no longer an option of deadlock with virt-manager, but ppm_save is called too early, before the update has completed. With this patch it is called at the correct moment, but that means there is a race between the monitor command completing and the screendump file being saved. The only solution is to use an asynchronous monitor command. For a previous round of this see: http://lists.gnu.org/archive/html/qemu-devel/2011-10/msg02810.html Since that's contentious, I'm suggesting we do something that is almost correct and doesn't hang, instead of correct and hangs. The screendump user can inotify on the directory and the file if need be. For casual monitor usage there is no difference. --- hw/qxl-render.c | 27 +++++++++++++++++++++++---- hw/qxl.c | 15 +++++++++++---- hw/qxl.h | 2 +- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/hw/qxl-render.c b/hw/qxl-render.c index 7f9fbca..7b120ab 100644 --- a/hw/qxl-render.c +++ b/hw/qxl-render.c @@ -75,15 +75,17 @@ typedef struct QXLRenderUpdateData { int redraw; QXLRect dirty[32]; QXLRect area; + char *filename; } QXLRenderUpdateData; -void qxl_render_update(PCIQXLDevice *qxl) +void qxl_render_update(PCIQXLDevice *qxl, const char *filename) { VGACommonState *vga = &qxl->vga; QXLRect dirty[32]; void *ptr; int redraw = 0; QXLRenderUpdateData *data; + QXLCookie *cookie; if (!is_buffer_shared(vga->ds->surface)) { dprint(qxl, 1, "%s: restoring shared displaysurface\n", __func__); @@ -139,11 +141,24 @@ void qxl_render_update(PCIQXLDevice *qxl) data->area.right = qxl->guest_primary.surface.width; data->area.top = 0; data->area.bottom = qxl->guest_primary.surface.height; + if (filename) { + data->filename = g_strdup(filename); + } + cookie = qxl_cookie_new(QXL_COOKIE_TYPE_RENDER_UPDATE_AREA, + 0, + (uint64_t)data); +#if SPICE_INTERFACE_QXL_MINOR >= 1 qxl_spice_update_area(qxl, 0, &data->area, data->dirty, ARRAY_SIZE(dirty), 1, QXL_ASYNC, - qxl_cookie_new(QXL_COOKIE_TYPE_RENDER_UPDATE_AREA, - 0, - (uint64_t)data)); + cookie); +#else + qxl_spice_update_area(qxl, 0, &data->area, + data->dirty, ARRAY_SIZE(dirty), 1, QXL_SYNC, NULL); + qxl_render_update_area_done(qxl, cookie); + if (filename) { + ppm_save(filename, qxl->ssd.ds->surface); + } +#endif } void qxl_render_update_area_done(PCIQXLDevice *qxl, QXLCookie *cookie) @@ -171,6 +186,10 @@ void qxl_render_update_area_done(PCIQXLDevice *qxl, QXLCookie *cookie) dirty[i].right - dirty[i].left, dirty[i].bottom - dirty[i].top); } + if (data->filename) { + ppm_save(data->filename, qxl->ssd.ds->surface); + g_free(data->filename); + } g_free(data); } diff --git a/hw/qxl.c b/hw/qxl.c index 5563293..2409cb3 100644 --- a/hw/qxl.c +++ b/hw/qxl.c @@ -145,12 +145,12 @@ void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id, uint32_t clear_dirty_region, qxl_async_io async, QXLCookie *cookie) { - struct QXLRect *area_copy; if (async == QXL_SYNC) { qxl->ssd.worker->update_area(qxl->ssd.worker, surface_id, area, dirty_rects, num_dirty_rects, clear_dirty_region); } else { #if SPICE_INTERFACE_QXL_MINOR >= 1 + struct QXLRect *area_copy; if (cookie == NULL) { area_copy = g_malloc0(sizeof(*area_copy)); memcpy(area_copy, area, sizeof(*area)); @@ -1476,7 +1476,7 @@ static void qxl_hw_update(void *opaque) break; case QXL_MODE_COMPAT: case QXL_MODE_NATIVE: - qxl_render_update(qxl); + qxl_render_update(qxl, NULL); break; default: break; @@ -1499,8 +1499,15 @@ static void qxl_hw_screen_dump(void *opaque, const char *filename) switch (qxl->mode) { case QXL_MODE_COMPAT: case QXL_MODE_NATIVE: - qxl_render_update(qxl); - ppm_save(filename, qxl->ssd.ds->surface); + /* + * TODO: if we use an async update_area, to avoid deadlock with + * virt-manager, we postpone the saving of the image until the + * rendering is done. This means the image isn't guranteed to be + * written when we return to the monitor. Fixing this needs an async + * monitor command, whatever the implementation of the concept is + * called. + */ + qxl_render_update(qxl, filename); break; case QXL_MODE_VGA: vga->screen_dump(vga, filename); diff --git a/hw/qxl.h b/hw/qxl.h index 71d5c35..198abdc 100644 --- a/hw/qxl.h +++ b/hw/qxl.h @@ -132,7 +132,7 @@ void qxl_log_command(PCIQXLDevice *qxl, const char *ring, QXLCommandExt *ext); /* qxl-render.c */ void qxl_render_resize(PCIQXLDevice *qxl); -void qxl_render_update(PCIQXLDevice *qxl); +void qxl_render_update(PCIQXLDevice *qxl, const char *filename); void qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext); void qxl_render_update_area_done(PCIQXLDevice *qxl, QXLCookie *cookie);