From patchwork Fri Feb 24 21:23:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alon Levy X-Patchwork-Id: 142977 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 1A01BB6EEE for ; Sat, 25 Feb 2012 08:24:14 +1100 (EST) Received: from localhost ([::1]:36774 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S12ce-0006uV-09 for incoming@patchwork.ozlabs.org; Fri, 24 Feb 2012 16:24:12 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49213) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S12cX-0006tz-Dm for qemu-devel@nongnu.org; Fri, 24 Feb 2012 16:24:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S12cV-0006FW-AN for qemu-devel@nongnu.org; Fri, 24 Feb 2012 16:24:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:21497) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S12cV-0006FD-2A for qemu-devel@nongnu.org; Fri, 24 Feb 2012 16:24:03 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q1OLO20t011439 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 24 Feb 2012 16:24:02 -0500 Received: from garlic.redhat.com (vpn-200-49.tlv.redhat.com [10.35.200.49]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q1OLO0GI004477; Fri, 24 Feb 2012 16:24:01 -0500 From: Alon Levy To: qemu-devel@nongnu.org, kraxel@redhat.com Date: Fri, 24 Feb 2012 23:23:59 +0200 Message-Id: <1330118639-14774-1-git-send-email-alevy@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] qxl-render: call ppm_save on bh 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 Uses the newly introduced hw_screen_dump_async. Now that the deadlock with virt-manager is fixed we need to call ppm_save in a bh, with the new command we can notify virt-manager using the SCREEN_DUMP_COMPLETE event. Signed-off-by: Alon Levy --- This goes on top of the QEVENT_SCREEN_DUMP_ASYNC and vga_hw_screen_dump_async patches. hw/qxl-render.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++--- hw/qxl.c | 40 ++++++++++++++++++++++++++++----- hw/qxl.h | 2 +- ui/spice-display.h | 3 ++ 4 files changed, 97 insertions(+), 11 deletions(-) diff --git a/hw/qxl-render.c b/hw/qxl-render.c index f323a4d..d1aa9ff 100644 --- a/hw/qxl-render.c +++ b/hw/qxl-render.c @@ -19,6 +19,7 @@ * along with this program; if not, see . */ +#include "console.h" #include "qxl.h" static void qxl_flip(PCIQXLDevice *qxl, QXLRect *rect) @@ -142,19 +143,59 @@ static void qxl_render_update_area_unlocked(PCIQXLDevice *qxl) } /* + * struct used just for ppm save bh. We don't actually support multiple qxl + * screendump yet, but a) we will, and b) exporting qxl0 from qxl.c looks + * uglier imo. + */ +typedef struct QXLPPMSaveBHData { + PCIQXLDevice *qxl; + QXLCookie *cookie; +} QXLPPMSaveBHData; + +static void qxl_render_ppm_save_bh(void *opaque) +{ + QXLPPMSaveBHData *data = opaque; + PCIQXLDevice *qxl = data->qxl; + QXLCookie *cookie = data->cookie; + QEMUBH *bh = cookie->u.render.ppm_save_bh; + + qemu_mutex_lock(&qxl->ssd.lock); + dprint(qxl, 1, "%s: %p (primary %p)\n", __func__, + qxl->ssd.ds->surface->data, qxl->guest_primary.data); + qxl_render_update_area_unlocked(qxl); + ppm_save(cookie->u.render.filename, qxl->ssd.ds->surface); + if (cookie->u.render.async) { + monitor_protocol_screen_dump_complete_event(cookie->u.render.filename); + } + g_free(cookie->u.render.filename); + --qxl->render_update_cookie_num; + g_free(cookie); + g_free(data); + qemu_mutex_unlock(&qxl->ssd.lock); + qemu_bh_delete(bh); +} + +/* * use ssd.lock to protect render_update_cookie_num. * qxl_render_update is called by io thread or vcpu thread, and the completion * callbacks are called by spice_server thread, defering to bh called from the * io thread. */ -void qxl_render_update(PCIQXLDevice *qxl) +void qxl_render_update(PCIQXLDevice *qxl, const char *filename, bool async) { QXLCookie *cookie; + QEMUBH *ppm_save_bh; + QXLPPMSaveBHData *ppm_save_bh_data; qemu_mutex_lock(&qxl->ssd.lock); if (!runstate_is_running() || !qxl->guest_primary.commands) { qxl_render_update_area_unlocked(qxl); + if (filename) { + dprint(qxl, 1, "%s: screendump with no pending commands\n", + __func__); + ppm_save(filename, qxl->ssd.ds->surface); + } qemu_mutex_unlock(&qxl->ssd.lock); return; } @@ -165,6 +206,15 @@ void qxl_render_update(PCIQXLDevice *qxl) cookie = qxl_cookie_new(QXL_COOKIE_TYPE_RENDER_UPDATE_AREA, 0); qxl_set_rect_to_surface(qxl, &cookie->u.render.area); + if (filename) { + ppm_save_bh_data = g_malloc0(sizeof(*ppm_save_bh_data)); + ppm_save_bh_data->qxl = qxl; + ppm_save_bh_data->cookie = cookie; + ppm_save_bh = qemu_bh_new(qxl_render_ppm_save_bh, ppm_save_bh_data); + cookie->u.render.filename = g_strdup(filename); + cookie->u.render.ppm_save_bh = ppm_save_bh; + cookie->u.render.async = async; + } qxl_spice_update_area(qxl, 0, &cookie->u.render.area, NULL, 0, 1 /* clear_dirty_region */, QXL_ASYNC, cookie); } @@ -181,10 +231,15 @@ void qxl_render_update_area_bh(void *opaque) void qxl_render_update_area_done(PCIQXLDevice *qxl, QXLCookie *cookie) { qemu_mutex_lock(&qxl->ssd.lock); - qemu_bh_schedule(qxl->update_area_bh); - qxl->render_update_cookie_num--; + if (cookie->u.render.filename) { + dprint(qxl, 1, "%s: scheduling ppm_save_bh\n", __func__); + qemu_bh_schedule(cookie->u.render.ppm_save_bh); + } else { + qemu_bh_schedule(qxl->update_area_bh); + --qxl->render_update_cookie_num; + g_free(cookie); + } qemu_mutex_unlock(&qxl->ssd.lock); - g_free(cookie); } static QEMUCursor *qxl_cursor(PCIQXLDevice *qxl, QXLCursor *cursor) diff --git a/hw/qxl.c b/hw/qxl.c index 61a7edd..17bf7da 100644 --- a/hw/qxl.c +++ b/hw/qxl.c @@ -1475,7 +1475,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, false); break; default: break; @@ -1490,7 +1490,8 @@ static void qxl_hw_invalidate(void *opaque) vga->invalidate(vga); } -static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch) +static void qxl_hw_screen_dump_helper(void *opaque, const char *filename, + bool cswitch, bool async) { PCIQXLDevice *qxl = opaque; VGACommonState *vga = &qxl->vga; @@ -1498,17 +1499,44 @@ static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch) 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, async); break; case QXL_MODE_VGA: - vga->screen_dump(vga, filename, cswitch); + if (async) { + if (vga->screen_dump_async) { + vga->screen_dump_async(vga, filename, cswitch); + } else { + vga->screen_dump(vga, filename, cswitch); + monitor_protocol_screen_dump_complete_event(filename); + } + } else { + vga->screen_dump(vga, filename, cswitch); + } break; default: break; } } +static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch) +{ + qxl_hw_screen_dump_helper(opaque, filename, cswitch, false); +} + +static void qxl_hw_screen_dump_async(void *opaque, const char *filename, + bool cswitch) +{ + qxl_hw_screen_dump_helper(opaque, filename, cswitch, true); +} + static void qxl_hw_text_update(void *opaque, console_ch_t *chardata) { PCIQXLDevice *qxl = opaque; @@ -1728,7 +1756,7 @@ static int qxl_init_primary(PCIDevice *dev) vga->ds = graphic_console_init(qxl_hw_update, qxl_hw_invalidate, qxl_hw_screen_dump, qxl_hw_text_update, - NULL, qxl); + qxl_hw_screen_dump_async, qxl); qemu_spice_display_init_common(&qxl->ssd, vga->ds); qxl0 = qxl; diff --git a/hw/qxl.h b/hw/qxl.h index 86e415b..e727358 100644 --- a/hw/qxl.h +++ b/hw/qxl.h @@ -140,7 +140,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, bool async); void qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext); void qxl_render_update_area_done(PCIQXLDevice *qxl, QXLCookie *cookie); void qxl_render_update_area_bh(void *opaque); diff --git a/ui/spice-display.h b/ui/spice-display.h index 12e50b6..ea36de2 100644 --- a/ui/spice-display.h +++ b/ui/spice-display.h @@ -62,6 +62,9 @@ typedef struct QXLCookie { struct { QXLRect area; int redraw; + char *filename; + QEMUBH *ppm_save_bh; + bool async; } render; } u; } QXLCookie;