monitor+qxl: async monitor support
cover monitor+qxl: async monitor support
This patchset converts the screen_dump command to async across qemu, and then implements it asynchronously for the qxl device in Native mode. This fixes a hang that is caused when the spice client is also a qemu monitor client and the client is single threaded:
io thread worker thread client
<---------------------------------------------------- screendump
do_screen_dump-> read------->
flush, read
client socket------------->Monitor maintainers: The first patch changes the monitor command to be async. The rest are qxl changes only.
Alon Levy (5):
monitor: screen_dump async
qxl: s/__FUNCTION__/__func__/, change logging levels
qxl: support concurrent async commands
qxl: split qxl_render_display_resized
qxl: support async monitor screen dump
console.c | 5 +- console.h | 7 +- hmp-commands.hx | 3 +- hw/g364fb.c | 12 ++- hw/qxl-render.c | 136 ++++++++++++++++++++---------- hw/qxl.c | 236 +++++++++++++++++++++++++++++++++++++-------------- hw/qxl.h | 63 +++++++++++++- hw/vga.c | 7 +- hw/vmware_vga.c | 5 +- monitor.c | 5 +- qmp-commands.hx | 3 +- ui/spice-display.c | 19 ++-- ui/spice-display.h | 7 +- 13 files changed, 363 insertions(+), 145 deletions(-)
Signature · 1 line
1.7.7
PATCH 1/5 monitor: screen_dump async
Make screen_dump monitor command an async command to allow next for qxl to implement it as a initiating call to red_worker and completion on callback, to fix a deadlock when issueing a screendump command via libvirt while connected with a libvirt controlled spice-gtk client.
This patch introduces no functional changes.
--- console.c | 5 +++-- console.h | 7 +++++-- hmp-commands.hx | 3 ++- hw/g364fb.c | 12 ++++++++---- hw/qxl.c | 6 ++++-- hw/vga.c | 7 +++++-- hw/vmware_vga.c | 5 +++-- monitor.c | 5 +++-- qmp-commands.hx | 3 ++- 9 files changed, 35 insertions(+), 18 deletions(-)
console.c +3 -2
@@ -173,7 +173,8 @@ void vga_hw_invalidate(void) active_console->hw_invalidate (active_console->hw); } -void vga_hw_screen_dump (const char *filename) +void vga_hw_screen_dump (const char *filename,MonitorCompletion cb, +void *opaque) {TextConsole *previous_active_console;
@@ -183,7 +184,7 @@ void vga_hw_screen_dump(const char *filename)so always dump the first one. */ console_select (0 );if (consoles[0 ] && consoles[0 ]->hw_screen_dump) { - consoles[0 ]->hw_screen_dump (consoles[0 ]->hw, filename); + consoles[0 ]->hw_screen_dump (consoles[0 ]->hw, filename, cb, opaque); }console_select (previous_active_console->index);
console.h +5 -2
@@ -343,7 +343,9 @@ static inline void console_write_ch(console_ch_t *dest, uint32_t ch)typedef void (*vga_hw_update_ptr )(void *);typedef void (*vga_hw_invalidate_ptr )(void *); -typedef void (*vga_hw_screen_dump_ptr )(void *,const char *); +typedef void (*vga_hw_screen_dump_ptr )(void *,const char *, +MonitorCompletion *, +void *);typedef void (*vga_hw_text_update_ptr )(void *,console_ch_t *); DisplayState *graphic_console_init(vga_hw_update_ptr update,
@@ -354,7 +356,8 @@ DisplayState *graphic_console_init(vga_hw_update_ptr update,void vga_hw_update (void );void vga_hw_invalidate (void ); -void vga_hw_screen_dump (const char *filename); +void vga_hw_screen_dump (const char *filename,MonitorCompletion cb, +void *opaque);void vga_hw_text_update (console_ch_t *chardata);int is_graphic_console (void );
hmp-commands.hx +2 -1
@@ -157,7 +157,8 @@ ETEXI .params = "filename", .help = "save screen into PPM image 'filename'", .user_print = monitor_user_noop, - .mhandler.cmd_new = do_screen_dump, + .mhandler.cmd_async = do_screen_dump, + .flags = MONITOR_CMD_ASYNC, }, STEXI
hw/g364fb.c +8 -4
@@ -291,7 +291,8 @@ static void g364fb_reset(G364State *s)g364fb_invalidate_display (s); } -static void g364fb_screen_dump (void *opaque,const char *filename) +static void g364fb_screen_dump (void *opaque,const char *filename, +MonitorCompletion *cb,void *cb_opaque) {G364State *s = opaque;int y, x;
@@ -303,12 +304,13 @@ static void g364fb_screen_dump(void *opaque, const char *filename)if (s->depth !=8 ) {error_report ("g364: unknown guest depth %d" , s->depth); -return ; + goto end; } f =fopen (filename,"wb" ); -if (!f) -return ; +if (!f) { + goto end; + }if (s->ctla &CTLA_FORCE_BLANK ) {/* blank screen */
@@ -331,6 +333,8 @@ static void g364fb_screen_dump(void *opaque, const char *filename) }fclose (f); +end: +cb (cb_opaque,NULL ); }/* called for accesses to io ports */
hw/qxl.c +4 -2
@@ -1423,7 +1423,8 @@ static void qxl_hw_invalidate(void *opaque) vga->invalidate (vga); } -static void qxl_hw_screen_dump (void *opaque,const char *filename) +static void qxl_hw_screen_dump (void *opaque,const char *filename, +MonitorCompletion *cb,void *cb_opaque) {PCIQXLDevice *qxl = opaque;VGACommonState *vga = &qxl->vga;
@@ -1433,9 +1434,10 @@ static void qxl_hw_screen_dump(void *opaque, const char *filename)case QXL_MODE_NATIVE :qxl_render_update (qxl);ppm_save (filename, qxl->ssd.ds->surface); +cb (cb_opaque,NULL );break ;case QXL_MODE_VGA : - vga->screen_dump (vga, filename); + vga->screen_dump (vga, filename, cb, cb_opaque);break ;default :break ;
hw/vga.c +5 -2
@@ -148,7 +148,8 @@ static uint32_t expand4[256];static uint16_t expand2[256 ];static uint8_t expand4to8[16 ]; -static void vga_screen_dump (void *opaque,const char *filename); +static void vga_screen_dump (void *opaque,const char *filename, +MonitorCompletion *cb,void *cb_opaque);static const char *screen_dump_filename;static DisplayChangeListener *screen_dump_dcl;
@@ -2404,7 +2405,8 @@ static DisplayChangeListener* vga_screen_dump_init(DisplayState *ds)/* save the vga display in a PPM image even if no display is available */ -static void vga_screen_dump (void *opaque,const char *filename) +static void vga_screen_dump (void *opaque,const char *filename, +MonitorCompletion *cb,void *cb_opaque) {VGACommonState *s = opaque;
@@ -2415,4 +2417,5 @@ static void vga_screen_dump(void *opaque, const char *filename)vga_invalidate_display (s);vga_hw_update (); screen_dump_filename =NULL ; +cb (cb_opaque,NULL ); }
hw/vmware_vga.c +3 -2
@@ -1003,11 +1003,12 @@ static void vmsvga_invalidate_display(void *opaque)/* save the vga display in a PPM image even if no display is available */ -static void vmsvga_screen_dump (void *opaque,const char *filename) +static void vmsvga_screen_dump (void *opaque,const char *filename, +MonitorCompletion *cb,void *cb_opaque) {struct vmsvga_state_s *s = opaque;if (!s->enable) { - s->vga.screen_dump (&s->vga, filename); + s->vga.screen_dump (&s->vga, filename, cb, cb_opaque);return ; }
monitor.c +3 -2
@@ -1180,9 +1180,10 @@ static int client_migrate_info(Monitor *mon, const QDict *qdict, QObject **ret_dreturn -1 ; } -static int do_screen_dump (Monitor *mon,const QDict *qdict,QObject **ret_data) +static int do_screen_dump (Monitor *mon,const QDict *params, +MonitorCompletion cb,void *opaque) { -vga_hw_screen_dump (qdict_get_str (qdict,"filename" )); +vga_hw_screen_dump (qdict_get_str (params,"filename" ), cb, opaque);return 0 ; }
qmp-commands.hx +2 -1
@@ -155,7 +155,8 @@ EQMP .params = "filename", .help = "save screen into PPM image 'filename'", .user_print = monitor_user_noop, - .mhandler.cmd_new = do_screen_dump, + .mhandler.cmd_async = do_screen_dump, + .flags = MONITOR_CMD_ASYNC, }, SQMP
Signature · 1 line
1.7.7
Re: [Qemu-devel] [PATCH 1/5] monitor: screen_dump async
Quoted 4 lines · Alon Levy
Make
screen_dumpmonitor command an async command to allow next for qxl to implement it as a initiating call tored_workerand completion on callback, to fix a deadlock when issueing a screendump command via libvirt while connected with a libvirt controlled spice-gtk client.
Approach looks reasonable to me. Patch breaks the build though, you've missed a bunch of screen_dump functions in non-x86 targets.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 1/5] monitor: screen_dump async
Quoted 8 lines · On Mon, 24 Oct 2011 17:13:14 +0200 Gerd Hoffmann <[email protected]> wrote:
Quoted 4 lines · Alon Levy
Make
screen_dumpmonitor command an async command to allow next for qxl to implement it as a initiating call tored_workerand completion on callback, to fix a deadlock when issueing a screendump command via libvirt while connected with a libvirt controlled spice-gtk client.Approach looks reasonable to me. Patch breaks the build though, you've missed a bunch of
screen_dumpfunctions in non-x86 targets.
There are two problems actually.
The first one is that changing an existing command from synchronous to asynchronous is an incompatible change because asynchronous commands semantics is different. For an example of possible problems please
check: https://bugzilla.redhat.com/show_bug.cgi?id=623903.
The second problem is that the existing asynchronous interface in the monitor is incomplete and has never been used for real. Our plan is to use QAPI's async support, but that has not landed in master yet and iirc there wasn't consensus about it. I also think it's a bit late for its inclusion in 1.0 (and certainly not a candidate for stable).
If all you need here is to delay sending the response, then maybe the current interface could work (although I honestly don't trust it and regret not having dropped it). Otherwise our only choice would be to work on getting the QAPI async support merged.
Re: [Qemu-devel] [PATCH 1/5] monitor: screen_dump async
Quoted 25 lines · Luiz Capitulino
Quoted 8 lines · On Mon, 24 Oct 2011 17:13:14 +0200 Gerd Hoffmann <[email protected]> wrote:
Quoted 4 lines · Alon Levy
Make
screen_dumpmonitor command an async command to allow next for qxl to implement it as a initiating call tored_workerand completion on callback, to fix a deadlock when issueing a screendump command via libvirt while connected with a libvirt controlled spice-gtk client.Approach looks reasonable to me. Patch breaks the build though, you've missed a bunch of
screen_dumpfunctions in non-x86 targets.There are two problems actually.
The first one is that changing an existing command from synchronous to asynchronous is an incompatible change because asynchronous commands semantics is different. For an example of possible problems please
check: https://bugzilla.redhat.com/show_bug.cgi?id=623903.The second problem is that the existing asynchronous interface in the monitor is incomplete and has never been used for real. Our plan is to use QAPI's async support, but that has not landed in master yet and iirc there wasn't consensus about it. I also think it's a bit late for its inclusion in 1.0 (and certainly not a candidate for stable).
Quoted 4 lines
If all you need here is to delay sending the response, then maybe the current interface could work (although I honestly don't trust it and regret not having dropped it). Otherwise our only choice would be to work on getting the QAPI async support merged.
My problem is that the io thread keeps the global mutex during the wait, that's why the async monitor is perfect for what I want - this is exactly what it does. I haven't looked at QAPI async support, but I understand it's a bit in the future.
Re: [Qemu-devel] [PATCH 1/5] monitor: screen_dump async
Quoted 26 lines · On Mon, 24 Oct 2011 19:29:37 +0200 Alon Levy <[email protected]> wrote:
Quoted 25 lines · Luiz Capitulino
Quoted 8 lines · On Mon, 24 Oct 2011 17:13:14 +0200 Gerd Hoffmann <[email protected]> wrote:
Quoted 4 lines · Alon Levy
Make
screen_dumpmonitor command an async command to allow next for qxl to implement it as a initiating call tored_workerand completion on callback, to fix a deadlock when issueing a screendump command via libvirt while connected with a libvirt controlled spice-gtk client.Approach looks reasonable to me. Patch breaks the build though, you've missed a bunch of
screen_dumpfunctions in non-x86 targets.There are two problems actually.
The first one is that changing an existing command from synchronous to asynchronous is an incompatible change because asynchronous commands semantics is different. For an example of possible problems please
check: https://bugzilla.redhat.com/show_bug.cgi?id=623903.The second problem is that the existing asynchronous interface in the monitor is incomplete and has never been used for real. Our plan is to use QAPI's async support, but that has not landed in master yet and iirc there wasn't consensus about it. I also think it's a bit late for its inclusion in 1.0 (and certainly not a candidate for stable).
Quoted 8 lines
Quoted 4 lines
If all you need here is to delay sending the response, then maybe the current interface could work (although I honestly don't trust it and regret not having dropped it). Otherwise our only choice would be to work on getting the QAPI async support merged.
My problem is that the io thread keeps the global mutex during the wait, that's why the async monitor is perfect for what I want - this is exactly what it does.
Let's not mix internal implementation details with what we want as an external interface.
Can't you just make a vga_hw_screen_dump() specific callback?
Quoted 2 lines
I haven't looked at QAPI async support, but I
understand it's a bit in the future.
Yes, it's not for the immediate term.
Re: [Qemu-devel] [PATCH 1/5] monitor: screen_dump async
Quoted 34 lines · Luiz Capitulino
Quoted 31 lines · On Mon, 24 Oct 2011 19:29:37 +0200 Alon Levy <[email protected]> wrote:
Quoted 29 lines · Luiz Capitulino
Quoted 8 lines · On Mon, 24 Oct 2011 17:13:14 +0200 Gerd Hoffmann <[email protected]> wrote:
Quoted 4 lines · Alon Levy
Make
screen_dumpmonitor command an async command to allow next for qxl to implement it as a initiating call tored_workerand completion on callback, to fix a deadlock when issueing a screendump command via libvirt while connected with a libvirt controlled spice-gtk client.Approach looks reasonable to me. Patch breaks the build though, you've missed a bunch of
screen_dumpfunctions in non-x86 targets.There are two problems actually.
The first one is that changing an existing command from synchronous to asynchronous is an incompatible change because asynchronous commands semantics is different. For an example of possible problems please
check: https://bugzilla.redhat.com/show_bug.cgi?id=623903.The second problem is that the existing asynchronous interface in the monitor is incomplete and has never been used for real. Our plan is to use QAPI's async support, but that has not landed in master yet and iirc there wasn't consensus about it. I also think it's a bit late for its inclusion in 1.0 (and certainly not a candidate for stable).
If all you need here is to delay sending the response, then maybe the current interface could work (although I honestly don't trust it and regret not having dropped it). Otherwise our only choice would be to work on getting the QAPI async support merged.
Quoted 9 lines
Quoted 3 lines
My problem is that the io thread keeps the global mutex during the wait, that's why the async monitor is perfect for what I want - this is exactly what it does.
Let's not mix internal implementation details with what we want as an external interface.
Can't you just make a
vga_hw_screen_dump()specific callback?
I don't understand how that would help - if the monitor command doesn't return (normal sync operation) then the mutex is never dropped, and any callback won't change that.
On the other hand, thinking a bit about the reference to 623903 baloon bug, I don't see a problem: the change doesn't affect the semantics for any other device except qxl, which I've tested. For any other device, the only difference is that instead of:
do_screen_dump call
device specific implementation
return
It becomes
do_screen_dump call
device specific implementation (not qxl)
callback called (always - not conditional, no one stores it except
qxl)
return
Quoted 4 lines
Quoted 2 lines
I haven't looked at QAPI async support, but I
understand it's a bit in the future.Yes, it's not for the immediate term.
Re: [Qemu-devel] [PATCH 1/5] monitor: screen_dump async
Quoted 42 lines · On Tue, 25 Oct 2011 12:13:09 +0200 Alon Levy <[email protected]> wrote:
Quoted 41 lines · Luiz Capitulino
Quoted 26 lines · On Mon, 24 Oct 2011 19:29:37 +0200 Alon Levy <[email protected]> wrote:
Quoted 25 lines · Luiz Capitulino
Quoted 8 lines · On Mon, 24 Oct 2011 17:13:14 +0200 Gerd Hoffmann <[email protected]> wrote:
Quoted 4 lines · Alon Levy
Make
screen_dumpmonitor command an async command to allow next for qxl to implement it as a initiating call tored_workerand completion on callback, to fix a deadlock when issueing a screendump command via libvirt while connected with a libvirt controlled spice-gtk client.Approach looks reasonable to me. Patch breaks the build though, you've missed a bunch of
screen_dumpfunctions in non-x86 targets.There are two problems actually.
The first one is that changing an existing command from synchronous to asynchronous is an incompatible change because asynchronous commands semantics is different. For an example of possible problems please
check: https://bugzilla.redhat.com/show_bug.cgi?id=623903.The second problem is that the existing asynchronous interface in the monitor is incomplete and has never been used for real. Our plan is to use QAPI's async support, but that has not landed in master yet and iirc there wasn't consensus about it. I also think it's a bit late for its inclusion in 1.0 (and certainly not a candidate for stable).
Quoted 8 lines
Quoted 4 lines
If all you need here is to delay sending the response, then maybe the current interface could work (although I honestly don't trust it and regret not having dropped it). Otherwise our only choice would be to work on getting the QAPI async support merged.
My problem is that the io thread keeps the global mutex during the wait, that's why the async monitor is perfect for what I want - this is exactly what it does.
Let's not mix internal implementation details with what we want as an external interface.
Quoted 6 lines
Quoted 2 lines
Can't you just make a
vga_hw_screen_dump()specific callback?I don't understand how that would help - if the monitor command doesn't return (normal sync operation) then the mutex is never dropped, and any callback won't change that.
I'm trying to figure out a different solution.
Our primary motivation for making a QMP command asynchronous must be to give clients the ability to keep issuing commands while "slow" commands are running. If that's not what you want nor your primary motivation, then you're probably taking the wrong approach.
If that is what you want, then you'll have to add a new command, because changing from asynchronous to synchronous is an incompatible change _and_ you shouldn't use the current interface, because it's botched (actually, I think I'm going to drop it right now as my last series fixed its only user).
Using a botched interface that doesn't do what's supposed to do but happens to solve a bug as a side effect will very likely end in tears at some point in the future.
Now, I did some research and found this description of the problem:
"""
In testing my patches for 'add_client' support with SPICE, I noticed deadlock in the QEMU/SPICE code. It only happens if I close a SPICE client and then immediately reconnect within about 1 second. If I wait a couple of seconds before reconnecting the SPICE client I don't see the deadlock.
"""
(http://lists.nongnu.org/archive/html/qemu-devel/2011-10/msg02599.html)
Is this accurate? Why does it _work_ after 1 second?
Quoted 24 lines
On the other hand, thinking a bit about the reference to 623903 baloon bug, I don't see a problem: the change doesn't affect the semantics for any other device except qxl, which I've tested. For any other device, the only difference is that instead of:
do_screen_dumpcall
device specific implementation
returnIt becomes
do_screen_dumpcall
device specific implementation (not qxl)
callback called (always - not conditional, no one stores it except
qxl)
returnQuoted 4 lines
Quoted 2 lines
I haven't looked at QAPI async support, but I
understand it's a bit in the future.Yes, it's not for the immediate term.
Re: [Qemu-devel] [PATCH 1/5] monitor: screen_dump async
Quoted 52 lines · Luiz Capitulino
Quoted 42 lines · On Tue, 25 Oct 2011 12:13:09 +0200 Alon Levy <[email protected]> wrote:
Quoted 41 lines · Luiz Capitulino
Quoted 26 lines · On Mon, 24 Oct 2011 19:29:37 +0200 Alon Levy <[email protected]> wrote:
Quoted 25 lines · Luiz Capitulino
Quoted 8 lines · On Mon, 24 Oct 2011 17:13:14 +0200 Gerd Hoffmann <[email protected]> wrote:
Quoted 4 lines · Alon Levy
Make
screen_dumpmonitor command an async command to allow next for qxl to implement it as a initiating call tored_workerand completion on callback, to fix a deadlock when issueing a screendump command via libvirt while connected with a libvirt controlled spice-gtk client.Approach looks reasonable to me. Patch breaks the build though, you've missed a bunch of
screen_dumpfunctions in non-x86 targets.There are two problems actually.
The first one is that changing an existing command from synchronous to asynchronous is an incompatible change because asynchronous commands semantics is different. For an example of possible problems please
check: https://bugzilla.redhat.com/show_bug.cgi?id=623903.The second problem is that the existing asynchronous interface in the monitor is incomplete and has never been used for real. Our plan is to use QAPI's async support, but that has not landed in master yet and iirc there wasn't consensus about it. I also think it's a bit late for its inclusion in 1.0 (and certainly not a candidate for stable).
Quoted 8 lines
Quoted 4 lines
If all you need here is to delay sending the response, then maybe the current interface could work (although I honestly don't trust it and regret not having dropped it). Otherwise our only choice would be to work on getting the QAPI async support merged.
My problem is that the io thread keeps the global mutex during the wait, that's why the async monitor is perfect for what I want - this is exactly what it does.
Let's not mix internal implementation details with what we want as an external interface.
Quoted 6 lines
Quoted 2 lines
Can't you just make a
vga_hw_screen_dump()specific callback?I don't understand how that would help - if the monitor command doesn't return (normal sync operation) then the mutex is never dropped, and any callback won't change that.
Quoted 6 lines
I'm trying to figure out a different solution.
Our primary motivation for making a QMP command asynchronous must be to give clients the ability to keep issuing commands while "slow" commands are running. If that's not what you want nor your primary motivation, then you're probably taking the wrong approach.
That sounds right, and it was what I assumed the async monitor implementation would do, boy was I surprised to discover it doesn't do any such thing, but what it does do is return early, allow *other* io related events (select returns) to be handled, and keeps the serialized only-one-command-ongoing monitor usage.
Quoted 6 lines
If that is what you want, then you'll have to add a new command, because changing from asynchronous to synchronous is an incompatible change _and_ you shouldn't use the current interface, because it's botched (actually, I think I'm going to drop it right now as my last series fixed its only user).
This is not what I want. I understand of course that it is what one would design an async monitor / api to allow (it was after all what I thought async monitor support meant).
Quoted 4 lines
Using a botched interface that doesn't do what's supposed to do but happens to solve a bug as a side effect will very likely end in tears at some point in the future.
Right, but it's the opposite of the current case.
Quoted 11 lines
Now, I did some research and found this description of the problem:
"""
In testing my patches for 'add_client' support with SPICE, I noticed deadlock in the QEMU/SPICE code. It only happens if I close a SPICE client and then immediately reconnect within about 1 second. If I wait a couple of seconds before reconnecting the SPICE client I don't see the deadlock.
"""
(http://lists.nongnu.org/archive/html/qemu-devel/2011-10/msg02599.html)
Quoted 2 lines
Is this accurate? Why does it _work_ after 1 second?
This is an unrelated bug, I know I said different on the thread but now rereading the callstack it is the channel_event locking workaround - and it is fixed by a spice-server only patch (which stops calling channel_event from the worker thread).
Quoted 25 lines
Quoted 24 lines
On the other hand, thinking a bit about the reference to 623903 baloon bug, I don't see a problem: the change doesn't affect the semantics for any other device except qxl, which I've tested. For any other device, the only difference is that instead of:
do_screen_dumpcall
device specific implementation
returnIt becomes
do_screen_dumpcall
device specific implementation (not qxl)
callback called (always - not conditional, no one stores it except
qxl)
returnQuoted 4 lines
Quoted 2 lines
I haven't looked at QAPI async support, but I
understand it's a bit in the future.Yes, it's not for the immediate term.
Re: [Qemu-devel] [PATCH 1/5] monitor: screen_dump async
Quoted 60 lines · On Tue, 25 Oct 2011 15:21:11 +0200 Alon Levy <[email protected]> wrote:
Quoted 52 lines · Luiz Capitulino
Quoted 42 lines · On Tue, 25 Oct 2011 12:13:09 +0200 Alon Levy <[email protected]> wrote:
Quoted 41 lines · Luiz Capitulino
Quoted 26 lines · On Mon, 24 Oct 2011 19:29:37 +0200 Alon Levy <[email protected]> wrote:
Quoted 25 lines · Luiz Capitulino
Quoted 8 lines · On Mon, 24 Oct 2011 17:13:14 +0200 Gerd Hoffmann <[email protected]> wrote:
Quoted 4 lines · Alon Levy
Make
screen_dumpmonitor command an async command to allow next for qxl to implement it as a initiating call tored_workerand completion on callback, to fix a deadlock when issueing a screendump command via libvirt while connected with a libvirt controlled spice-gtk client.Approach looks reasonable to me. Patch breaks the build though, you've missed a bunch of
screen_dumpfunctions in non-x86 targets.There are two problems actually.
The first one is that changing an existing command from synchronous to asynchronous is an incompatible change because asynchronous commands semantics is different. For an example of possible problems please
check: https://bugzilla.redhat.com/show_bug.cgi?id=623903.The second problem is that the existing asynchronous interface in the monitor is incomplete and has never been used for real. Our plan is to use QAPI's async support, but that has not landed in master yet and iirc there wasn't consensus about it. I also think it's a bit late for its inclusion in 1.0 (and certainly not a candidate for stable).
Quoted 8 lines
Quoted 4 lines
If all you need here is to delay sending the response, then maybe the current interface could work (although I honestly don't trust it and regret not having dropped it). Otherwise our only choice would be to work on getting the QAPI async support merged.
My problem is that the io thread keeps the global mutex during the wait, that's why the async monitor is perfect for what I want - this is exactly what it does.
Let's not mix internal implementation details with what we want as an external interface.
Quoted 6 lines
Quoted 2 lines
Can't you just make a
vga_hw_screen_dump()specific callback?I don't understand how that would help - if the monitor command doesn't return (normal sync operation) then the mutex is never dropped, and any callback won't change that.
Quoted 6 lines
I'm trying to figure out a different solution.
Our primary motivation for making a QMP command asynchronous must be to give clients the ability to keep issuing commands while "slow" commands are running. If that's not what you want nor your primary motivation, then you're probably taking the wrong approach.
Quoted 5 lines
That sounds right, and it was what I assumed the async monitor implementation would do, boy was I surprised to discover it doesn't do any such thing, but what it does do is return early, allow *other* io related events (select returns) to be handled, and keeps the serialized only-one-command-ongoing monitor usage.
Yes, if that turns out to be needed internally then we'll have to add such functionality (but probably not as part of QMP's async support iiuc).
Quoted 28 lines
Quoted 5 lines
If that is what you want, then you'll have to add a new command, because changing from asynchronous to synchronous is an incompatible change _and_ you shouldn't use the current interface, because it's botched (actually, I think I'm going to drop it right now as my last series fixed its only user).
This is not what I want. I understand of course that it is what one would design an async monitor / api to allow (it was after all what I thought async monitor support meant).
Quoted 4 lines
Using a botched interface that doesn't do what's supposed to do but happens to solve a bug as a side effect will very likely end in tears at some point in the future.
Right, but it's the opposite of the current case.
Quoted 11 lines
Now, I did some research and found this description of the problem:
"""
In testing my patches for 'add_client' support with SPICE, I noticed deadlock in the QEMU/SPICE code. It only happens if I close a SPICE client and then immediately reconnect within about 1 second. If I wait a couple of seconds before reconnecting the SPICE client I don't see the deadlock.
"""
(http://lists.nongnu.org/archive/html/qemu-devel/2011-10/msg02599.html)
Quoted 7 lines
Quoted 2 lines
Is this accurate? Why does it _work_ after 1 second?
This is an unrelated bug, I know I said different on the thread but now rereading the callstack it is the
channel_eventlocking workaround - and it is fixed by a spice-server only patch (which stops callingchannel_eventfrom the worker thread).
So, can you try to describe the problem you're having to someone who is not familiar with qlx and its locking?
Quoted 27 lines
Quoted 26 lines
Quoted 25 lines
On the other hand, thinking a bit about the reference to 623903 baloon bug, I don't see a problem: the change doesn't affect the semantics for any other device except qxl, which I've tested. For any other device, the only difference is that instead of:
do_screen_dumpcall
device specific implementation
returnIt becomes
do_screen_dumpcall
device specific implementation (not qxl)
callback called (always - not conditional, no one stores it except
qxl)
returnQuoted 4 lines
Quoted 2 lines
I haven't looked at QAPI async support, but I
understand it's a bit in the future.Yes, it's not for the immediate term.
Re: [Qemu-devel] [PATCH 1/5] monitor: screen_dump async
Quoted 103 lines · Luiz Capitulino
Quoted 60 lines · On Tue, 25 Oct 2011 15:21:11 +0200 Alon Levy <[email protected]> wrote:
Quoted 52 lines · Luiz Capitulino
Quoted 42 lines · On Tue, 25 Oct 2011 12:13:09 +0200 Alon Levy <[email protected]> wrote:
Quoted 41 lines · Luiz Capitulino
Quoted 26 lines · On Mon, 24 Oct 2011 19:29:37 +0200 Alon Levy <[email protected]> wrote:
Quoted 25 lines · Luiz Capitulino
Quoted 8 lines · On Mon, 24 Oct 2011 17:13:14 +0200 Gerd Hoffmann <[email protected]> wrote:
Quoted 4 lines · Alon Levy
Make
screen_dumpmonitor command an async command to allow next for qxl to implement it as a initiating call tored_workerand completion on callback, to fix a deadlock when issueing a screendump command via libvirt while connected with a libvirt controlled spice-gtk client.Approach looks reasonable to me. Patch breaks the build though, you've missed a bunch of
screen_dumpfunctions in non-x86 targets.There are two problems actually.
The first one is that changing an existing command from synchronous to asynchronous is an incompatible change because asynchronous commands semantics is different. For an example of possible problems please
check: https://bugzilla.redhat.com/show_bug.cgi?id=623903.The second problem is that the existing asynchronous interface in the monitor is incomplete and has never been used for real. Our plan is to use QAPI's async support, but that has not landed in master yet and iirc there wasn't consensus about it. I also think it's a bit late for its inclusion in 1.0 (and certainly not a candidate for stable).
Quoted 8 lines
Quoted 4 lines
If all you need here is to delay sending the response, then maybe the current interface could work (although I honestly don't trust it and regret not having dropped it). Otherwise our only choice would be to work on getting the QAPI async support merged.
My problem is that the io thread keeps the global mutex during the wait, that's why the async monitor is perfect for what I want - this is exactly what it does.
Let's not mix internal implementation details with what we want as an external interface.
Quoted 6 lines
Quoted 2 lines
Can't you just make a
vga_hw_screen_dump()specific callback?I don't understand how that would help - if the monitor command doesn't return (normal sync operation) then the mutex is never dropped, and any callback won't change that.
Quoted 6 lines
I'm trying to figure out a different solution.
Our primary motivation for making a QMP command asynchronous must be to give clients the ability to keep issuing commands while "slow" commands are running. If that's not what you want nor your primary motivation, then you're probably taking the wrong approach.
Quoted 5 lines
That sounds right, and it was what I assumed the async monitor implementation would do, boy was I surprised to discover it doesn't do any such thing, but what it does do is return early, allow *other* io related events (select returns) to be handled, and keeps the serialized only-one-command-ongoing monitor usage.
Yes, if that turns out to be needed internally then we'll have to add such functionality (but probably not as part of QMP's async support iiuc).
Quoted 31 lines
Quoted 5 lines
If that is what you want, then you'll have to add a new command, because changing from asynchronous to synchronous is an incompatible change _and_ you shouldn't use the current interface, because it's botched (actually, I think I'm going to drop it right now as my last series fixed its only user).
This is not what I want. I understand of course that it is what one would design an async monitor / api to allow (it was after all what I thought async monitor support meant).
Quoted 4 lines
Using a botched interface that doesn't do what's supposed to do but happens to solve a bug as a side effect will very likely end in tears at some point in the future.
Right, but it's the opposite of the current case.
Quoted 13 lines
Now, I did some research and found this description of the problem:
"""
In testing my patches for 'add_client' support with SPICE, I noticed deadlock in the QEMU/SPICE code. It only happens if I close a SPICE client and then immediately reconnect within about 1 second. If I wait a couple of seconds before reconnecting the SPICE client I don't see the deadlock.
"""
(http://lists.nongnu.org/archive/html/qemu-devel/2011-10/msg02599.html)Is this accurate? Why does it _work_ after 1 second?
Quoted 8 lines
Quoted 4 lines
This is an unrelated bug, I know I said different on the thread but now rereading the callstack it is the
channel_eventlocking workaround - and it is fixed by a spice-server only patch (which stops callingchannel_eventfrom the worker thread).So, can you try to describe the problem you're having to someone who is not familiar with qlx and its locking?
I'm suddenly not sure this patchset even fixes the problem that I said it does, so I'll update once I made sure what it actually fixes.
Quoted 28 lines
Quoted 27 lines
Quoted 26 lines
Quoted 25 lines
On the other hand, thinking a bit about the reference to 623903 baloon bug, I don't see a problem: the change doesn't affect the semantics for any other device except qxl, which I've tested. For any other device, the only difference is that instead of:
do_screen_dumpcall
device specific implementation
returnIt becomes
do_screen_dumpcall
device specific implementation (not qxl)
callback called (always - not conditional, no one stores it except
qxl)
returnQuoted 4 lines
Quoted 2 lines
I haven't looked at QAPI async support, but I
understand it's a bit in the future.Yes, it's not for the immediate term.
Re: [Qemu-devel] [PATCH 1/5] monitor: screen_dump async
In reply to Luiz CapitulinoHi,
Quoted 4 lines
If all you need here is to delay sending the response, then maybe the current interface could work (although I honestly don't trust it and regret not having dropped it). Otherwise our only choice would be to work on getting the QAPI async support merged.
A delayed monitor response is all we need.
The command may take a bit to finish, where "a bit" is in the order of a few seconds max, usually less than a second. Blocking the monitor for that amount of time is fine, but blocking the io thread introduces insane long I/O latencies for the guest (and device emulation).
cheers,
Gerd
PATCH 2/5 qxl: s/__FUNCTION__/__func__/, change logging levels
In reply to Alon Levy--- hw/qxl.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
hw/qxl.c +4 -4
@@ -515,7 +515,7 @@ static int interface_get_command(QXLInstance *sin, struct QXLCommandExt *ext)switch (qxl->mode) {case QXL_MODE_VGA : -dprint (qxl,2 ,"%s: vga\n" , __FUNCTION__); +dprint (qxl,4 ,"%s: vga\n" , __func__); ret = false;qemu_mutex_lock (&qxl->ssd.lock);if (qxl->ssd.update !=NULL ) {
@@ -526,19 +526,19 @@ static int interface_get_command(QXLInstance *sin, struct QXLCommandExt *ext) }qemu_mutex_unlock (&qxl->ssd.lock);if (ret) { -dprint (qxl,2 ,"%s %s\n" , __FUNCTION__,qxl_mode_to_string (qxl->mode)); +dprint (qxl,4 ,"%s %s\n" , __func__,qxl_mode_to_string (qxl->mode));qxl_log_command (qxl,"vga" , ext); }return ret;case QXL_MODE_COMPAT :case QXL_MODE_NATIVE :case QXL_MODE_UNDEFINED : -dprint (qxl,4 ,"%s: %s\n" , __FUNCTION__,qxl_mode_to_string (qxl->mode)); +dprint (qxl,5 ,"%s: %s\n" , __func__,qxl_mode_to_string (qxl->mode)); ring = &qxl->ram->cmd_ring;if (SPICE_RING_IS_EMPTY (ring)) {return false; } -dprint (qxl,2 ,"%s: %s\n" , __FUNCTION__,qxl_mode_to_string (qxl->mode)); +dprint (qxl,4 ,"%s: %s\n" , __func__,qxl_mode_to_string (qxl->mode));SPICE_RING_CONS_ITEM (ring, cmd); ext->cmd = *cmd; ext->group_id =MEMSLOT_GROUP_GUEST ;
Signature · 1 line
1.7.7
PATCH 3/5 qxl: support concurrent async commands
In reply to Alon Levychange the single pending current_async to a linked list of pending SpiceAsyncCommand.
--- hw/qxl-render.c | 2 +- hw/qxl.c | 145 +++++++++++++++++++++++++++++++++++----------------- hw/qxl.h | 29 +++++++++-- ui/spice-display.c | 19 ++++--- ui/spice-display.h | 7 ++- 5 files changed, 137 insertions(+), 65 deletions(-)
hw/qxl-render.c +1 -1
@@ -125,7 +125,7 @@ void qxl_render_update(PCIQXLDevice *qxl)memset (dirty,0 ,sizeof (dirty));qxl_spice_update_area (qxl,0 , &update, - dirty,ARRAY_SIZE (dirty),1 ,QXL_SYNC ); + dirty,ARRAY_SIZE (dirty),1 ,QXL_SYNC ,0 );for (i =0 ; i <ARRAY_SIZE (dirty); i++) {if (qemu_spice_rect_is_empty (dirty+i)) {
hw/qxl.c +97 -48
357 lines not on this page · raw message
hw/qxl.h +25 -4
@@ -17,7 +17,22 @@ enum qxl_mode {#define QXL_UNDEFINED_IO UINT32_MAX -typedef struct PCIQXLDevice { +typedef struct PCIQXLDevice PCIQXLDevice ; +typedef struct SpiceAsyncCommand SpiceAsyncCommand ; +typedef void (*SpiceAsyncCommandCompletion )(PCIQXLDevice *, +SpiceAsyncCommand *); + +/* Outstanding async request sent to spice server. +* cookie must be unique across the list. */ +struct SpiceAsyncCommand { +uint64_t cookie; +void *opaque; +uint32_t async_io; +SpiceAsyncCommandCompletion completion; +QLIST_ENTRY (SpiceAsyncCommand) next; +}; + +struct PCIQXLDevice {PCIDevice pci;SimpleSpiceDisplay ssd;int id;
@@ -32,7 +47,8 @@ typedef struct PCIQXLDevice {int32_t num_memslots;int32_t num_surfaces; -uint32_t current_async; + QLIST_HEAD(, SpiceAsyncCommand) async_commands; +uint64_t async_next_cookie;QemuMutex async_lock;struct guest_slots {
@@ -87,7 +103,7 @@ typedef struct PCIQXLDevice {/* io bar */ MemoryRegion io_bar; -} PCIQXLDevice; +};#define PANIC_ON (x) if ((x)) { \ printf("%s: PANIC %s failed\n", __FUNCTION__, #x); \
@@ -116,13 +132,18 @@ void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id, struct QXLRect *area, struct QXLRect *dirty_rects, uint32_t num_dirty_rects, uint32_t clear_dirty_region, - qxl_async_io async); + qxl_async_io async, uint64_t cookie);void qxl_spice_loadvm_commands (PCIQXLDevice *qxl,struct QXLCommandExt *ext,uint32_t count);void qxl_spice_oom (PCIQXLDevice *qxl);void qxl_spice_reset_memslots (PCIQXLDevice *qxl);void qxl_spice_reset_image_cache (PCIQXLDevice *qxl);void qxl_spice_reset_cursor (PCIQXLDevice *qxl); +SpiceAsyncCommand *push_spice_async_command (PCIQXLDevice *qxl, +uint32_t async_io,int size); +/* complete_spice_async_command: call to cleanup a command */ +void complete_spice_async_command (PCIQXLDevice *qxl, +SpiceAsyncCommand *spice_async_command);/* qxl-logger.c */ void qxl_log_cmd_cursor (PCIQXLDevice *qxl,QXLCursorCmd *cmd,int group_id);
ui/spice-display.c +10 -9
@@ -61,11 +61,11 @@ void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r) }void qemu_spice_add_memslot (SimpleSpiceDisplay *ssd,QXLDevMemSlot *memslot, -qxl_async_io async) +qxl_async_io async,uint64_t cookie) {if (async !=QXL_SYNC ) {#if SPICE_INTERFACE_QXL_MINOR >=1 -spice_qxl_add_memslot_async (&ssd->qxl, memslot,0 ); +spice_qxl_add_memslot_async (&ssd->qxl, memslot, cookie);#else abort ();#endif
@@ -81,11 +81,11 @@ void qemu_spice_del_memslot(SimpleSpiceDisplay *ssd, uint32_t gid, uint32_t sid)void qemu_spice_create_primary_surface (SimpleSpiceDisplay *ssd,uint32_t id,QXLDevSurfaceCreate *surface, -qxl_async_io async) +qxl_async_io async,uint64_t cookie) {if (async !=QXL_SYNC ) {#if SPICE_INTERFACE_QXL_MINOR >=1 -spice_qxl_create_primary_surface_async (&ssd->qxl, id, surface,0 ); +spice_qxl_create_primary_surface_async (&ssd->qxl, id, surface, cookie);#else abort ();#endif
@@ -96,11 +96,12 @@ void qemu_spice_create_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id,void qemu_spice_destroy_primary_surface (SimpleSpiceDisplay *ssd, -uint32_t id,qxl_async_io async) +uint32_t id,qxl_async_io async, +uint64_t cookie) {if (async !=QXL_SYNC ) {#if SPICE_INTERFACE_QXL_MINOR >=1 -spice_qxl_destroy_primary_surface_async (&ssd->qxl, id,0 ); +spice_qxl_destroy_primary_surface_async (&ssd->qxl, id, cookie);#else abort ();#endif
@@ -223,7 +224,7 @@ void qemu_spice_create_host_memslot(SimpleSpiceDisplay *ssd)memset (&memslot,0 ,sizeof (memslot)); memslot.slot_group_id =MEMSLOT_GROUP_HOST ; memslot.virt_end = ~0 ; -qemu_spice_add_memslot (ssd, &memslot,QXL_SYNC ); +qemu_spice_add_memslot (ssd, &memslot,QXL_SYNC ,0 ); }void qemu_spice_create_host_primary (SimpleSpiceDisplay *ssd)
@@ -243,14 +244,14 @@ void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd) surface.mem = (intptr_t )ssd->buf; surface.group_id =MEMSLOT_GROUP_HOST ; -qemu_spice_create_primary_surface (ssd,0 , &surface,QXL_SYNC ); +qemu_spice_create_primary_surface (ssd,0 , &surface,QXL_SYNC ,0 ); }void qemu_spice_destroy_host_primary (SimpleSpiceDisplay *ssd) {dprint (1 ,"%s:\n" , __FUNCTION__); -qemu_spice_destroy_primary_surface (ssd,0 ,QXL_SYNC ); +qemu_spice_destroy_primary_surface (ssd,0 ,QXL_SYNC ,0 ); } void qemu_spice_vm_change_state_handler(void *opaque, int running,
ui/spice-display.h +4 -3
@@ -99,14 +99,15 @@ void qemu_spice_display_resize(SimpleSpiceDisplay *ssd);void qemu_spice_display_refresh (SimpleSpiceDisplay *ssd);void qemu_spice_add_memslot (SimpleSpiceDisplay *ssd,QXLDevMemSlot *memslot, -qxl_async_io async); +qxl_async_io async,uint64_t cookie);void qemu_spice_del_memslot (SimpleSpiceDisplay *ssd,uint32_t gid,uint32_t sid);void qemu_spice_create_primary_surface (SimpleSpiceDisplay *ssd,uint32_t id,QXLDevSurfaceCreate *surface, -qxl_async_io async); +qxl_async_io async,uint64_t cookie);void qemu_spice_destroy_primary_surface (SimpleSpiceDisplay *ssd, -uint32_t id,qxl_async_io async); +uint32_t id,qxl_async_io async, +uint64_t cookie);void qemu_spice_wakeup (SimpleSpiceDisplay *ssd);void qemu_spice_start (SimpleSpiceDisplay *ssd);void qemu_spice_stop (SimpleSpiceDisplay *ssd);
Signature · 1 line
1.7.7
Re: [Qemu-devel] [PATCH 3/5] qxl: support concurrent async commands
Hi,
hw/qxl.c static void qxl_create_guest_primary_complete(PCIQXLDevice *d); · line 756
Quoted 7 lines
hw/qxl.c +6
-0+SpiceAsyncCommand *push_spice_async_command (PCIQXLDevice *qxl, +uint32_t async_io,int size) +/* caller must call g_free */ +static SpiceAsyncCommand *pop_spice_async_command(PCIQXLDevice *qxl, + uint64_t cookie) +{
push/pop naming implies stack-like operation, which isn't true though. pop will lookup by cookie. Also an explicit release function would be good (list unlink and g_free call can go there).
Maybe have spice_async_cmd_{alloc,lookup,free} ?
Have you considered passing down a SpiceAsyncCommand pointer instead of the cookie value everywhere? Seems to be a bit cleaner and more future-proof to me. Not sure it buys us much in practice though, so maybe it isn't worth the trouble.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 3/5] qxl: support concurrent async commands
Quoted 14 lines · Gerd Hoffmann
Hi,
hw/qxl.c static void qxl_create_guest_primary_complete(PCIQXLDevice *d); · line 756
Quoted 7 lines
hw/qxl.c +6
-0+SpiceAsyncCommand *push_spice_async_command (PCIQXLDevice *qxl, +uint32_t async_io,int size) +/* caller must call g_free */ +static SpiceAsyncCommand *pop_spice_async_command(PCIQXLDevice *qxl, + uint64_t cookie) +{push/pop naming implies stack-like operation, which isn't true though. pop will lookup by cookie. Also an explicit release function would be good (list unlink and
g_freecall can go there).
Quoted 2 lines
Maybe have spice_async_cmd_{alloc,lookup,free} ?
Will do.
Quoted 5 lines
Have you considered passing down a SpiceAsyncCommand pointer instead of the cookie value everywhere? Seems to be a bit cleaner and more future-proof to me. Not sure it buys us much in practice though, so maybe it isn't worth the trouble.
That would still require casting, since we want to ensure we can later support 32 bit architectures, so the cookie size of uint64_t will remain. I guess I'll do it.
Quoted 2 lines
cheers,
Gerd
PATCH 4/5 qxl: split qxl_render_display_resized
In reply to Alon Levy--- hw/qxl-render.c | 75 ++++++++++++++++++++++++++++++------------------------- 1 files changed, 41 insertions(+), 34 deletions(-)
hw/qxl-render.c +41 -34
@@ -70,47 +70,54 @@ void qxl_render_resize(PCIQXLDevice *qxl) } } +static void qxl_render_display_resized (PCIQXLDevice *qxl) +{ +VGACommonState *vga = &qxl->vga; +void *ptr; + + qxl->guest_primary.resized =0 ; + +if (qxl->guest_primary.flipped) { +g_free (qxl->guest_primary.flipped); + qxl->guest_primary.flipped =NULL ; + } +qemu_free_displaysurface (vga->ds); + + qxl->guest_primary.data =memory_region_get_ram_ptr (&qxl->vga.vram); +if (qxl->guest_primary.stride <0 ) { +/* spice surface is upside down -> need extra buffer to flip */ + qxl->guest_primary.stride = -qxl->guest_primary.stride; + qxl->guest_primary.flipped =g_malloc (qxl->guest_primary.surface.width * + qxl->guest_primary.stride); + ptr = qxl->guest_primary.flipped; + }else { + ptr = qxl->guest_primary.data; + } +dprint (qxl,1 ,"%s: %dx%d, stride %d, bpp %d, depth %d, flip %s\n" , + __func__, + qxl->guest_primary.surface.width, + qxl->guest_primary.surface.height, + qxl->guest_primary.stride, + qxl->guest_primary.bytes_pp, + qxl->guest_primary.bits_pp, + qxl->guest_primary.flipped ?"yes" :"no" ); + vga->ds->surface = +qemu_create_displaysurface_from (qxl->guest_primary.surface.width, + qxl->guest_primary.surface.height, + qxl->guest_primary.bits_pp, + qxl->guest_primary.stride, + ptr); +dpy_resize (vga->ds); +} +void qxl_render_update (PCIQXLDevice *qxl) {VGACommonState *vga = &qxl->vga;QXLRect dirty[32 ], update; -void *ptr;int i;if (qxl->guest_primary.resized) { - qxl->guest_primary.resized =0 ; - -if (qxl->guest_primary.flipped) { -g_free (qxl->guest_primary.flipped); - qxl->guest_primary.flipped =NULL ; - } -qemu_free_displaysurface (vga->ds); - - qxl->guest_primary.data =memory_region_get_ram_ptr (&qxl->vga.vram); -if (qxl->guest_primary.stride <0 ) { -/* spice surface is upside down -> need extra buffer to flip */ - qxl->guest_primary.stride = -qxl->guest_primary.stride; - qxl->guest_primary.flipped =g_malloc (qxl->guest_primary.surface.width * - qxl->guest_primary.stride); - ptr = qxl->guest_primary.flipped; - }else { - ptr = qxl->guest_primary.data; - } -dprint (qxl,1 ,"%s: %dx%d, stride %d, bpp %d, depth %d, flip %s\n" , - __FUNCTION__, - qxl->guest_primary.surface.width, - qxl->guest_primary.surface.height, - qxl->guest_primary.stride, - qxl->guest_primary.bytes_pp, - qxl->guest_primary.bits_pp, - qxl->guest_primary.flipped ?"yes" :"no" ); - vga->ds->surface = -qemu_create_displaysurface_from (qxl->guest_primary.surface.width, - qxl->guest_primary.surface.height, - qxl->guest_primary.bits_pp, - qxl->guest_primary.stride, - ptr); -dpy_resize (vga->ds); +qxl_render_display_resized (qxl); }if (!qxl->guest_primary.commands) {
Signature · 1 line
1.7.7
PATCH 5/5 qxl: support async monitor screen dump
In reply to Alon LevySplit qxl_spice_update_area_complete from qxl_render_update, use SPICE_INTERFACE_QXL_MINOR 2 introduced spice_qxl_update_area_dirty_async to retrive the dirty rectangles asyncronously (the previous spice_qxl_update_area_async did not accept a dirty rectangles array).
Introduce SpiceAsyncMonitorScreenDump for a screen_dump.
vga mode screen dumps are still synchronous.
---
patchcheck gives one false positive, identifying a point function argument as a multiplication:
ERROR: need consistent spacing around '*' (ctx:WxV)
#135: FILE: hw/qxl.c:148:
+ SpiceAsyncCommand *async_command)
^ --- hw/qxl-render.c | 67 +++++++++++++++++++++++++++++--------- hw/qxl.c | 95 +++++++++++++++++++++++++++++++++++++++++++----------- hw/qxl.h | 38 ++++++++++++++++++++-- 3 files changed, 161 insertions(+), 39 deletions(-)
hw/qxl-render.c +51 -16
@@ -27,6 +27,10 @@ static void qxl_flip(PCIQXLDevice *qxl, QXLRect *rect)uint8_t *dst = qxl->guest_primary.flipped;int len, i; +assert (rect->bottom >=0 ); +assert (rect->bottom <= qxl->guest_primary.surface.height); +assert (rect->top >=0 ); +assert (rect->top <= qxl->guest_primary.surface.height); src += (qxl->guest_primary.surface.height - rect->top -1 ) * qxl->guest_primary.stride; dst += rect->top * qxl->guest_primary.stride;
@@ -110,17 +114,39 @@ static void qxl_render_display_resized(PCIQXLDevice *qxl)dpy_resize (vga->ds); } -void qxl_render_update (PCIQXLDevice *qxl) +void qxl_spice_update_area_complete (PCIQXLDevice *qxl,QXLRect *dirty, +int n_dirty) {VGACommonState *vga = &qxl->vga; -QXLRect dirty[32 ], update;int i; +for (i =0 ; i < n_dirty; i++) { +if (qemu_spice_rect_is_empty (dirty + i)) { +break ; + } +if (qxl->guest_primary.flipped) { +qxl_flip (qxl, dirty + i); + } +dpy_update (vga->ds, + dirty[i].left, dirty[i].top, + dirty[i].right - dirty[i].left, + dirty[i].bottom - dirty[i].top); + } +} + +void qxl_render_update (PCIQXLDevice *qxl, +SpiceAsyncMonitorScreenDump *async_screen_dump) +{ +QXLRect dirty[32 ], update; +if (qxl->guest_primary.resized) {qxl_render_display_resized (qxl); } -if (!qxl->guest_primary.commands) { +if (async_screen_dump) { +dprint (qxl,2 ,"%s: no update required\n" , __func__); +complete_spice_async_command (qxl, &async_screen_dump->base); + }return ; } qxl->guest_primary.commands =0 ;
@@ -131,20 +157,29 @@ void qxl_render_update(PCIQXLDevice *qxl) update.bottom = qxl->guest_primary.surface.height;memset (dirty,0 ,sizeof (dirty)); +if (async_screen_dump) { +#if SPICE_INTERFACE_QXL_MINOR >=2 +dprint (qxl,2 ,"A-SYNC update_area 0 (%d,%d,%d,%d)\n" , + update.top, update.left, update.bottom, update.right); + async_screen_dump->n_dirty =32 ; + async_screen_dump->dirty =g_malloc0 (sizeof (QXLRect) * + async_screen_dump->n_dirty); +qxl_spice_update_area (qxl,0 , &update, + async_screen_dump->dirty, + async_screen_dump->n_dirty,1 , + &async_screen_dump->base); +return ; +#else +fprintf (stderr,"%s: warning: fallback to sync, spice-server < 0.8.4\n" , + __func__); +#endif + } +dprint (qxl,2 ,"SYNC update_area\n" );qxl_spice_update_area (qxl,0 , &update, - dirty,ARRAY_SIZE (dirty),1 ,QXL_SYNC ,0 ); - -for (i =0 ; i <ARRAY_SIZE (dirty); i++) { -if (qemu_spice_rect_is_empty (dirty+i)) { -break ; - } -if (qxl->guest_primary.flipped) { -qxl_flip (qxl, dirty+i); - } -dpy_update (vga->ds, - dirty[i].left, dirty[i].top, - dirty[i].right - dirty[i].left, - dirty[i].bottom - dirty[i].top); + dirty,ARRAY_SIZE (dirty),1 ,NULL ); +qxl_spice_update_area_complete (qxl, dirty,ARRAY_SIZE (dirty)); +if (async_screen_dump) { +complete_spice_async_command (qxl, &async_screen_dump->base); } }
hw/qxl.c +75 -20
181 lines not on this page · raw message
hw/qxl.h +35 -3
@@ -17,6 +17,26 @@ enum qxl_mode {#define QXL_UNDEFINED_IO UINT32_MAX +/* The monitor's screen_dump triggers a update_area +* command which must be done asynchroniously to prevent the following +* deadlock scenario when the spice client is also a monitor client and +* is running single threaded: +* +* io thread worker thread client +* +* <---------------------------------------------------- screendump +* do_screen_dump-> read-------> +* flush, read +* client socket-------------> +* +* To avoid adding these to the spice-protocol/spice/qxl_dev.h, they +* are defined here. */ +enum { +/* Must start larger then QXL_IO_RANGE_SIZE, but that is a moving +* target, so split in half. */ +MONITOR_UPDATE_AREA_ASYNC =0x80000000 , +}; +typedef struct PCIQXLDevice PCIQXLDevice ;typedef struct SpiceAsyncCommand SpiceAsyncCommand ; typedef void (*SpiceAsyncCommandCompletion)(PCIQXLDevice *,
@@ -27,11 +47,20 @@ typedef void (*SpiceAsyncCommandCompletion)(PCIQXLDevice *,struct SpiceAsyncCommand {uint64_t cookie;void *opaque; -uint32_t async_io; +uint32_t io;SpiceAsyncCommandCompletion completion;QLIST_ENTRY (SpiceAsyncCommand) next; }; +typedef struct SpiceAsyncMonitorScreenDump { +SpiceAsyncCommand base; +MonitorCompletion *cb; +void *cb_opaque; +const char *filename; +QXLRect *dirty; +int n_dirty; +}SpiceAsyncMonitorScreenDump ; +struct PCIQXLDevice {PCIDevice pci;SimpleSpiceDisplay ssd;
@@ -132,7 +161,7 @@ void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id, struct QXLRect *area, struct QXLRect *dirty_rects, uint32_t num_dirty_rects, uint32_t clear_dirty_region, - qxl_async_io async, uint64_t cookie); + SpiceAsyncCommand *async_command);void qxl_spice_loadvm_commands (PCIQXLDevice *qxl,struct QXLCommandExt *ext,uint32_t count);void qxl_spice_oom (PCIQXLDevice *qxl);
@@ -151,11 +180,14 @@ 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, +SpiceAsyncMonitorScreenDump *async_screen_dump);void qxl_render_cursor (PCIQXLDevice *qxl,QXLCommandExt *ext);#if SPICE_INTERFACE_QXL_MINOR >=1 void qxl_spice_update_area_async (PCIQXLDevice *qxl,uint32_t surface_id,struct QXLRect *area,uint32_t clear_dirty_region,int is_vga); +void qxl_spice_update_area_complete (PCIQXLDevice *qxl,QXLRect *dirty, +int n_dirty);#endif
Signature · 1 line
1.7.7
Re: [Qemu-devel] [PATCH 5/5] qxl: support async monitor screen dump
Quoted 6 lines · Alon Levy
Split
qxl_spice_update_area_completefromqxl_render_update, useSPICE_INTERFACE_QXL_MINOR2 introducedspice_qxl_update_area_dirty_asyncto retrive the dirty rectangles asyncronously (the previousspice_qxl_update_area_asyncdid not accept a dirty rectangles array).Introduce SpiceAsyncMonitorScreenDump for a
screen_dump.
That one conflicts with the screendump/SDL fixes pushed to the spice.v44 branch. Have you seen the mail? Had you time to look at the patches?
cheers,
Gerd
Re: [Qemu-devel] [PATCH 5/5] qxl: support async monitor screen dump
Quoted 10 lines · Gerd Hoffmann
Quoted 6 lines · Alon Levy
Split
qxl_spice_update_area_completefromqxl_render_update, useSPICE_INTERFACE_QXL_MINOR2 introducedspice_qxl_update_area_dirty_asyncto retrive the dirty rectangles asyncronously (the previousspice_qxl_update_area_asyncdid not accept a dirty rectangles array).Introduce SpiceAsyncMonitorScreenDump for a
screen_dump.That one conflicts with the screendump/SDL fixes pushed to the spice.v44 branch. Have you seen the mail? Had you time to look at the patches?
Yes and no. I will.
Quoted 4 lines
cheers,
Gerd