ui: run screendump in coroutine

-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.22 (GNU/Linux)
 
 iQIcBAABCgAGBQJforJuAAoJEEy22O7T6HE4hwwQAJN7kPQoHvqSsMDTlxz1tyM9
 V/W7lIJ8mDSSxoWrJcQSVJloxw+ZeRAL0Or+Pa7XuPlX4aT4PcaaBzAXc/yb4NHZ
 YwNcsWQUucmFgytfYNKhVAWu8+0uQxoQgltmBhV3JruV9g6oubF9CAt5PZgcdxlQ
 BpJrM/6fZQ1+j+qEOgVKDLlFLUBDsPXcvTgDUr49hpHj8LwzuuKNxk3gBuCRIoHG
 XeAqsh1He1WlAdA7l5Gs1QusV/lFV0Xv7FswnNt58c03JQwcskdJdWfjZizQr0FK
 VdXrURmkzAf1u+kiqybdymN40Pge6IccXKaDa53ufmcjSg8ykoGRhHvx1qy8WVax
 3YgcUx/GSNFE7ydlWN8EKMa4d9neZfMykQywGlJQ18ZiaAP6nhEca6APIXqmbOp6
 vpN15aTXk84CoIDG7/lSanKykGfXcYSLyI+43KGzpN+78npgq9nB8oEcvLxJmoR2
 Mo/YLnfDPLWsS/mA6aayHri3G44rTP50r9jqM0cnnohv5ygaG9IbWDYfzEFQsizD
 ojWchpxZzcAyVg0yg8LGUIFYr8u1hwuwsjcRXOl9Gk9Z/9PyO6hHSWMVi+6OyQeH
 zChCIlKQxZ4Xw1nIi8aWjfcr7UCt4xW4Aw+hhMvEw6UoydAuhDU5ArIevVnRTJHM
 Fvym8l7C79IfCjZyhin9
 =vw0u
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/kraxel/tags/ui-20201104-pull-request' into staging

ui: run screendump in coroutine

# gpg: Signature made Wed 04 Nov 2020 13:53:50 GMT
# gpg:                using RSA key 4CB6D8EED3E87138
# gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>" [full]
# gpg:                 aka "Gerd Hoffmann <gerd@kraxel.org>" [full]
# gpg:                 aka "Gerd Hoffmann (private) <kraxel@gmail.com>" [full]
# Primary key fingerprint: A032 8CFF B93A 17A7 9901  FE7D 4CB6 D8EE D3E8 7138

* remotes/kraxel/tags/ui-20201104-pull-request:
  console: make QMP/HMP screendump run in coroutine
  console: modify ppm_save to take a pixman image ref
  coroutine: let CoQueue wake up outside a coroutine

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2020-11-04 16:52:17 +00:00
commit 3c8c36c908
6 changed files with 45 additions and 17 deletions

View File

@ -254,6 +254,7 @@ ERST
.help = "save screen from head 'head' of display device 'device' "
"into PPM image 'filename'",
.cmd = hmp_screendump,
.coroutine = true,
},
SRST

View File

@ -1762,7 +1762,8 @@ err_out:
goto out;
}
void hmp_screendump(Monitor *mon, const QDict *qdict)
void coroutine_fn
hmp_screendump(Monitor *mon, const QDict *qdict)
{
const char *filename = qdict_get_str(qdict, "filename");
const char *id = qdict_get_try_str(qdict, "device");

View File

@ -98,7 +98,8 @@
#
##
{ 'command': 'screendump',
'data': {'filename': 'str', '*device': 'str', '*head': 'int'} }
'data': {'filename': 'str', '*device': 'str', '*head': 'int'},
'coroutine': true }
##
# == Spice

View File

@ -168,6 +168,7 @@ struct QemuConsole {
QEMUFIFO out_fifo;
uint8_t out_fifo_buf[16];
QEMUTimer *kbd_timer;
CoQueue dump_queue;
QTAILQ_ENTRY(QemuConsole) next;
};
@ -195,7 +196,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);
static void gui_update(void *opaque)
{
@ -264,6 +264,7 @@ static void gui_setup_refresh(DisplayState *ds)
void graphic_hw_update_done(QemuConsole *con)
{
qemu_co_queue_restart_all(&con->dump_queue);
}
void graphic_hw_update(QemuConsole *con)
@ -311,16 +312,16 @@ void graphic_hw_invalidate(QemuConsole *con)
}
}
static bool ppm_save(int fd, DisplaySurface *ds, Error **errp)
static bool ppm_save(int fd, pixman_image_t *image, Error **errp)
{
int width = pixman_image_get_width(ds->image);
int height = pixman_image_get_height(ds->image);
int width = pixman_image_get_width(image);
int height = pixman_image_get_height(image);
g_autoptr(Object) ioc = OBJECT(qio_channel_file_new_fd(fd));
g_autofree char *header = NULL;
g_autoptr(pixman_image_t) linebuf = NULL;
int y;
trace_ppm_save(fd, ds);
trace_ppm_save(fd, image);
header = g_strdup_printf("P6\n%d %d\n%d\n", width, height, 255);
if (qio_channel_write_all(QIO_CHANNEL(ioc),
@ -330,7 +331,7 @@ static bool ppm_save(int fd, DisplaySurface *ds, Error **errp)
linebuf = qemu_pixman_linebuf_create(PIXMAN_BE_r8g8b8, width);
for (y = 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) {
@ -341,9 +342,17 @@ static bool ppm_save(int fd, DisplaySurface *ds, Error **errp)
return true;
}
void qmp_screendump(const char *filename, bool has_device, const char *device,
bool has_head, int64_t head, Error **errp)
static void graphic_hw_update_bh(void *con)
{
graphic_hw_update(con);
}
/* Safety: coroutine-only, concurrent-coroutine safe, main thread only */
void coroutine_fn
qmp_screendump(const char *filename, bool has_device, const char *device,
bool has_head, int64_t head, Error **errp)
{
g_autoptr(pixman_image_t) image = NULL;
QemuConsole *con;
DisplaySurface *surface;
int fd;
@ -366,12 +375,24 @@ void qmp_screendump(const char *filename, bool has_device, const char *device,
}
}
graphic_hw_update(con);
if (qemu_co_queue_empty(&con->dump_queue)) {
/* Defer the update, it will restart the pending coroutines */
aio_bh_schedule_oneshot(qemu_get_aio_context(),
graphic_hw_update_bh, con);
}
qemu_co_queue_wait(&con->dump_queue, NULL);
/*
* All pending coroutines are woken up, while the BQL is held. No
* further graphic update are possible until it is released. Take
* an image ref before that.
*/
surface = qemu_console_surface(con);
if (!surface) {
error_setg(errp, "no surface");
return;
}
image = pixman_image_ref(surface->image);
fd = qemu_open_old(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
if (fd == -1) {
@ -380,7 +401,12 @@ void qmp_screendump(const char *filename, bool has_device, const char *device,
return;
}
if (!ppm_save(fd, surface, errp)) {
/*
* The image content could potentially be updated as the coroutine
* yields and releases the BQL. It could produce corrupted dump, but
* it should be otherwise safe.
*/
if (!ppm_save(fd, image, errp)) {
qemu_unlink(filename);
}
}
@ -1296,6 +1322,7 @@ static QemuConsole *new_console(DisplayState *ds, console_type_t console_type,
obj = object_new(TYPE_QEMU_CONSOLE);
s = QEMU_CONSOLE(obj);
qemu_co_queue_init(&s->dump_queue);
s->head = head;
object_property_add_link(obj, "device", TYPE_DEVICE,
(Object **)&s->device,

View File

@ -15,7 +15,7 @@ displaysurface_create_pixman(void *display_surface) "surface=%p"
displaysurface_free(void *display_surface) "surface=%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=%d surface=%p"
ppm_save(int fd, void *image) "fd=%d image=%p"
# gtk-egl.c
# gtk-gl-area.c

View File

@ -85,15 +85,13 @@ static bool qemu_co_queue_do_restart(CoQueue *queue, bool single)
return true;
}
bool coroutine_fn qemu_co_queue_next(CoQueue *queue)
bool qemu_co_queue_next(CoQueue *queue)
{
assert(qemu_in_coroutine());
return qemu_co_queue_do_restart(queue, true);
}
void coroutine_fn qemu_co_queue_restart_all(CoQueue *queue)
void qemu_co_queue_restart_all(CoQueue *queue)
{
assert(qemu_in_coroutine());
qemu_co_queue_do_restart(queue, false);
}