From patchwork Sun Mar 11 19:26:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alon Levy X-Patchwork-Id: 146010 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 56359B6EF3 for ; Mon, 12 Mar 2012 06:49:18 +1100 (EST) Received: from localhost ([::1]:51858 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S6oQh-0003sR-Pw for incoming@patchwork.ozlabs.org; Sun, 11 Mar 2012 15:27:43 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S6oPy-0002BM-GK for qemu-devel@nongnu.org; Sun, 11 Mar 2012 15:27:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S6oPw-0008H2-1h for qemu-devel@nongnu.org; Sun, 11 Mar 2012 15:26:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57998) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S6oPv-0008GX-QC for qemu-devel@nongnu.org; Sun, 11 Mar 2012 15:26:55 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q2BJQsPm018473 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 11 Mar 2012 15:26:54 -0400 Received: from garlic.redhat.com (vpn-200-153.tlv.redhat.com [10.35.200.153]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q2BJQkEx032029; Sun, 11 Mar 2012 15:26:52 -0400 From: Alon Levy To: qemu-devel@nongnu.org, kraxel@redhat.com, lcapitulino@redhat.com, aliguori@us.ibm.com Date: Sun, 11 Mar 2012 21:26:42 +0200 Message-Id: <1331494004-26177-4-git-send-email-alevy@redhat.com> In-Reply-To: <1331494004-26177-1-git-send-email-alevy@redhat.com> References: <1331483977-18910-1-git-send-email-alevy@redhat.com> <1331494004-26177-1-git-send-email-alevy@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 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 v2 3/5] 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 With this change ppm_save is called after rendering, and not before. There are two lose ends: hmp: monitor will be active before ppm_save is complete. qmp: return will be emitted before ppm_save is complete. Signed-off-by: Alon Levy --- hw/qxl-render.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++----- hw/qxl.c | 5 +-- hw/qxl.h | 2 +- trace-events | 2 + ui/spice-display.h | 2 + 5 files changed, 76 insertions(+), 11 deletions(-) diff --git a/hw/qxl-render.c b/hw/qxl-render.c index 74e7ea3..b281766 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_blit(PCIQXLDevice *qxl, QXLRect *rect) @@ -142,12 +143,68 @@ 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); + +static QXLCookie *qxl_cookie_render_new(PCIQXLDevice *qxl, const char *filename) +{ + QXLPPMSaveBHData *ppm_save_bh_data; + QEMUBH *ppm_save_bh; + QXLCookie *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; + } + return cookie; +} + +static void qxl_cookie_render_free(PCIQXLDevice *qxl, QXLCookie *cookie) +{ + g_free(cookie->u.render.filename); + g_free(cookie); + --qxl->render_update_cookie_num; +} + +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); + trace_qxl_render_ppm_save_bh( + 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); + qxl_cookie_render_free(qxl, cookie); + qemu_mutex_unlock(&qxl->ssd.lock); + g_free(data); + 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) { QXLCookie *cookie; @@ -155,6 +212,10 @@ void qxl_render_update(PCIQXLDevice *qxl) if (!runstate_is_running() || !qxl->guest_primary.commands) { qxl_render_update_area_unlocked(qxl); + if (filename) { + trace_qxl_render_update_screendump_no_update(); + ppm_save(filename, qxl->ssd.ds->surface); + } qemu_mutex_unlock(&qxl->ssd.lock); return; } @@ -162,9 +223,7 @@ void qxl_render_update(PCIQXLDevice *qxl) qxl->guest_primary.commands = 0; qxl->render_update_cookie_num++; qemu_mutex_unlock(&qxl->ssd.lock); - cookie = qxl_cookie_new(QXL_COOKIE_TYPE_RENDER_UPDATE_AREA, - 0); - qxl_set_rect_to_surface(qxl, &cookie->u.render.area); + cookie = qxl_cookie_render_new(qxl, filename); qxl_spice_update_area(qxl, 0, &cookie->u.render.area, NULL, 0, 1 /* clear_dirty_region */, QXL_ASYNC, cookie); } @@ -182,10 +241,13 @@ void qxl_render_update_area_done(PCIQXLDevice *qxl, QXLCookie *cookie) { qemu_mutex_lock(&qxl->ssd.lock); trace_qxl_render_update_area_done(cookie); - qemu_bh_schedule(qxl->update_area_bh); - qxl->render_update_cookie_num--; + if (cookie->u.render.filename) { + qemu_bh_schedule(cookie->u.render.ppm_save_bh); + } else { + qemu_bh_schedule(qxl->update_area_bh); + qxl_cookie_render_free(qxl, 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 7857731..bcfd661 100644 --- a/hw/qxl.c +++ b/hw/qxl.c @@ -1471,7 +1471,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; @@ -1494,8 +1494,7 @@ 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); + qxl_render_update(qxl, filename); break; case QXL_MODE_VGA: vga->screen_dump(vga, filename, cswitch); diff --git a/hw/qxl.h b/hw/qxl.h index 11a0db3..417ab28 100644 --- a/hw/qxl.h +++ b/hw/qxl.h @@ -147,7 +147,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); void qxl_render_update_area_bh(void *opaque); diff --git a/trace-events b/trace-events index a66aee8..2f045c4 100644 --- a/trace-events +++ b/trace-events @@ -718,3 +718,5 @@ qxl_blit_guest_primary_initialized(void) "" qxl_blit(int32_t stride, int32_t left, int32_t right, int32_t top, int32_t bottom) "stride=%d [%d, %d, %d, %d]" qxl_guest_primary_resized(int32_t width, int32_t height, int32_t stride, int32_t bytes_pp, int32_t bits_pp) "%dx%d, stride %d, bpp %d, depth %d" qxl_render_update_area_done(void *cookie) "%p" +qxl_render_update_screendump_no_update(void) "" +qxl_render_ppm_save_bh(void *data, void *primary) "%p (primary %p)" diff --git a/ui/spice-display.h b/ui/spice-display.h index 12e50b6..ec1fc24 100644 --- a/ui/spice-display.h +++ b/ui/spice-display.h @@ -62,6 +62,8 @@ typedef struct QXLCookie { struct { QXLRect area; int redraw; + char *filename; + QEMUBH *ppm_save_bh; } render; } u; } QXLCookie;