All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH V2] vnc: destroy server surface if no client is connected
@ 2015-09-25 18:36 Peter Lieven
  2015-09-29 10:28 ` Gerd Hoffmann
  0 siblings, 1 reply; 12+ messages in thread
From: Peter Lieven @ 2015-09-25 18:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Lieven, kraxel

if no client is connected there is no need to keep the server
surface. Throw it away to save memory.

Signed-off-by: Peter Lieven <pl@kamp.de>
---
v1->v2: don't create a dummy surface just set vd->server = NULL [Gerd]

 ui/vnc.c | 38 +++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index eba3fba..8c12ff5 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -630,8 +630,14 @@ static void vnc_dpy_update(DisplayChangeListener *dcl,
 {
     VncDisplay *vd = container_of(dcl, VncDisplay, dcl);
     struct VncSurface *s = &vd->guest;
-    int width = pixman_image_get_width(vd->server);
-    int height = pixman_image_get_height(vd->server);
+    int width, height;
+
+    if (!vd->server) {
+        return;
+    }
+
+    width = pixman_image_get_width(vd->server);
+    height = pixman_image_get_height(vd->server);
 
     vnc_set_area_dirty(s->dirty, width, height, x, y, w, h);
 }
@@ -712,8 +718,17 @@ static void vnc_dpy_switch(DisplayChangeListener *dcl,
 
     vnc_abort_display_jobs(vd);
 
-    /* server surface */
     qemu_pixman_image_unref(vd->server);
+    vd->server = NULL;
+    qemu_pixman_image_unref(vd->guest.fb);
+    vd->guest.fb = NULL;
+
+    /* if no client is connected we don't need a server surface */
+    if (QTAILQ_EMPTY(&vd->clients)) {
+        return;
+    }
+
+    /* server surface */
     vd->ds = surface;
     width = MIN(VNC_MAX_WIDTH, ROUND_UP(surface_width(vd->ds),
                                         VNC_DIRTY_PIXELS_PER_BIT));
@@ -726,7 +741,6 @@ static void vnc_dpy_switch(DisplayChangeListener *dcl,
     if (ds_get_bytes_per_pixel(ds) != vd->guest.ds->pf.bytes_per_pixel)
         console_color_init(ds);
 #endif
-    qemu_pixman_image_unref(vd->guest.fb);
     vd->guest.fb = pixman_image_ref(surface->image);
     vd->guest.format = surface->format;
     memset(vd->guest.dirty, 0x00, sizeof(vd->guest.dirty));
@@ -900,6 +914,10 @@ static void vnc_dpy_copy(DisplayChangeListener *dcl,
     int i, x, y, pitch, inc, w_lim, s;
     int cmp_bytes;
 
+    if (!vd->server) {
+        return;
+    }
+
     vnc_refresh_server_surface(vd);
     QTAILQ_FOREACH_SAFE(vs, &vd->clients, next, vn) {
         if (vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {
@@ -1213,6 +1231,9 @@ void vnc_disconnect_finish(VncState *vs)
 
     if (vs->initialized) {
         QTAILQ_REMOVE(&vs->vd->clients, vs, next);
+        if (QTAILQ_EMPTY(&vs->vd->clients)) {
+            vnc_dpy_switch(&vs->vd->dcl, NULL);
+        }
         qemu_remove_mouse_mode_change_notifier(&vs->mouse_mode_notifier);
     }
 
@@ -3049,6 +3070,7 @@ void vnc_init_state(VncState *vs)
 {
     vs->initialized = true;
     VncDisplay *vd = vs->vd;
+    bool first_client;
 
     vs->last_x = -1;
     vs->last_y = -1;
@@ -3061,9 +3083,15 @@ void vnc_init_state(VncState *vs)
     qemu_mutex_init(&vs->output_mutex);
     vs->bh = qemu_bh_new(vnc_jobs_bh, vs);
 
+    first_client = QTAILQ_EMPTY(&vd->clients);
     QTAILQ_INSERT_TAIL(&vd->clients, vs, next);
 
-    graphic_hw_update(vd->dcl.con);
+    if (first_client) {
+        /* set/restore the correct surface in the VNC server */
+        console_select(0);
+    } else {
+        graphic_hw_update(vd->dcl.con);
+    }
 
     vnc_write(vs, "RFB 003.008\n", 12);
     vnc_flush(vs);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH V2] vnc: destroy server surface if no client is connected
  2015-09-25 18:36 [Qemu-devel] [PATCH V2] vnc: destroy server surface if no client is connected Peter Lieven
@ 2015-09-29 10:28 ` Gerd Hoffmann
  2015-09-29 12:41   ` Peter Lieven
  0 siblings, 1 reply; 12+ messages in thread
From: Gerd Hoffmann @ 2015-09-29 10:28 UTC (permalink / raw)
  To: Peter Lieven; +Cc: qemu-devel

  Hi,

> -    graphic_hw_update(vd->dcl.con);
> +    if (first_client) {
> +        /* set/restore the correct surface in the VNC server */
> +        console_select(0);

Nah, that has unwanted side effects.

Pushed some patches to git://git.kraxel.org/qemu rebase/ui-vnc-next,
could you have a look?

thanks,
  Gerd

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH V2] vnc: destroy server surface if no client is connected
  2015-09-29 10:28 ` Gerd Hoffmann
@ 2015-09-29 12:41   ` Peter Lieven
  2015-09-29 12:49     ` Gerd Hoffmann
  0 siblings, 1 reply; 12+ messages in thread
From: Peter Lieven @ 2015-09-29 12:41 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel


> Am 29.09.2015 um 12:28 schrieb Gerd Hoffmann <kraxel@redhat.com>:
> 
>  Hi,
> 
>> -    graphic_hw_update(vd->dcl.con);
>> +    if (first_client) {
>> +        /* set/restore the correct surface in the VNC server */
>> +        console_select(0);
> 
> Nah, that has unwanted side effects.

okay, ill try to respin without this hack.

> 
> Pushed some patches to git://git.kraxel.org/qemu rebase/ui-vnc-next,
> could you have a look?

if you mean the RFC patches on the list I already send a bunch of comments on them.

Peter

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH V2] vnc: destroy server surface if no client is connected
  2015-09-29 12:41   ` Peter Lieven
@ 2015-09-29 12:49     ` Gerd Hoffmann
  2015-09-29 13:31       ` Peter Lieven
  0 siblings, 1 reply; 12+ messages in thread
From: Gerd Hoffmann @ 2015-09-29 12:49 UTC (permalink / raw)
  To: Peter Lieven; +Cc: qemu-devel

On Di, 2015-09-29 at 14:41 +0200, Peter Lieven wrote:
> > Am 29.09.2015 um 12:28 schrieb Gerd Hoffmann <kraxel@redhat.com>:
> > 
> >  Hi,
> > 
> >> -    graphic_hw_update(vd->dcl.con);
> >> +    if (first_client) {
> >> +        /* set/restore the correct surface in the VNC server */
> >> +        console_select(0);
> > 
> > Nah, that has unwanted side effects.
> 
> okay, ill try to respin without this hack.
> 
> > 
> > Pushed some patches to git://git.kraxel.org/qemu rebase/ui-vnc-next,
> > could you have a look?
> 
> if you mean the RFC patches on the list I already send a bunch of comments on them.

It's updated, taking your comments in account, reworking the server
surface code so we can free it without clients, also added
qio_buffer_shrink() but added no calls yet.

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH V2] vnc: destroy server surface if no client is connected
  2015-09-29 12:49     ` Gerd Hoffmann
@ 2015-09-29 13:31       ` Peter Lieven
  2015-09-29 14:08         ` Gerd Hoffmann
  0 siblings, 1 reply; 12+ messages in thread
From: Peter Lieven @ 2015-09-29 13:31 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel


> Am 29.09.2015 um 14:49 schrieb Gerd Hoffmann <kraxel@redhat.com>:
> 
> On Di, 2015-09-29 at 14:41 +0200, Peter Lieven wrote:
>>> Am 29.09.2015 um 12:28 schrieb Gerd Hoffmann <kraxel@redhat.com>:
>>> 
>>> Hi,
>>> 
>>>> -    graphic_hw_update(vd->dcl.con);
>>>> +    if (first_client) {
>>>> +        /* set/restore the correct surface in the VNC server */
>>>> +        console_select(0);
>>> 
>>> Nah, that has unwanted side effects.
>> 
>> okay, ill try to respin without this hack.
>> 
>>> 
>>> Pushed some patches to git://git.kraxel.org/qemu rebase/ui-vnc-next,
>>> could you have a look?
>> 
>> if you mean the RFC patches on the list I already send a bunch of comments on them.
> 
> It's updated, taking your comments in account, reworking the server
> surface code so we can free it without clients, also added
> qio_buffer_shrink() but added no calls yet.
> 

had a quick look (without testing).

what about Recycling the output buffer as worker thread buffer?

about shrinking: I had the idea to count the number of times the buffer was (significantly) too big and only shrink if that counter has reached a reasonable value. and reset that counter to zero if the buffer has the right size.

i would check this in qio_buffer_resize. as you suggested earlier.

Peter 


> cheers,
>  Gerd
> 
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH V2] vnc: destroy server surface if no client is connected
  2015-09-29 13:31       ` Peter Lieven
@ 2015-09-29 14:08         ` Gerd Hoffmann
  2015-09-29 14:36           ` Peter Lieven
  2015-10-01  9:52           ` Peter Lieven
  0 siblings, 2 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2015-09-29 14:08 UTC (permalink / raw)
  To: Peter Lieven; +Cc: qemu-devel

  Hi,

> what about Recycling the output buffer as worker thread buffer?

You can't do that as vs is allocated on the stack, therefore not valid
any more when vnc_worker_thread_loop returns.


> about shrinking: I had the idea to count the number of times the buffer was (significantly) too big and only shrink if that counter has reached a reasonable value. and reset that counter to zero if the buffer has the right size.
> 
> i would check this in qio_buffer_resize. as you suggested earlier.

Not sure whenever it is a good idea to do that on every reserve call.
Maybe better place shrink calls in places where you know it is worth
checking, to have lower overhead.

Patches are welcome in any case ;)

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH V2] vnc: destroy server surface if no client is connected
  2015-09-29 14:08         ` Gerd Hoffmann
@ 2015-09-29 14:36           ` Peter Lieven
  2015-10-01  9:52           ` Peter Lieven
  1 sibling, 0 replies; 12+ messages in thread
From: Peter Lieven @ 2015-09-29 14:36 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel


> Am 29.09.2015 um 16:08 schrieb Gerd Hoffmann <kraxel@redhat.com>:
> 
>  Hi,
> 
>> what about Recycling the output buffer as worker thread buffer?
> 
> You can't do that as vs is allocated on the stack, therefore not valid
> any more when vnc_worker_thread_loop returns.

why not? buffer_move_free only moves the heap allocated buffer allocation not the Buffer structure itself.


> 
> 
>> about shrinking: I had the idea to count the number of times the buffer was (significantly) too big and only shrink if that counter has reached a reasonable value. and reset that counter to zero if the buffer has the right size.
>> 
>> i would check this in qio_buffer_resize. as you suggested earlier.
> 
> Not sure whenever it is a good idea to do that on every reserve call.
> Maybe better place shrink calls in places where you know it is worth
> checking, to have lower overhead.
> 
> Patches are welcome in any case ;)
> 

will have a look.

Peter

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH V2] vnc: destroy server surface if no client is connected
  2015-09-29 14:08         ` Gerd Hoffmann
  2015-09-29 14:36           ` Peter Lieven
@ 2015-10-01  9:52           ` Peter Lieven
  2015-10-02  7:36             ` Gerd Hoffmann
  1 sibling, 1 reply; 12+ messages in thread
From: Peter Lieven @ 2015-10-01  9:52 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel

Am 29.09.2015 um 16:08 schrieb Gerd Hoffmann:
>   Hi,
>
>> what about Recycling the output buffer as worker thread buffer?
> You can't do that as vs is allocated on the stack, therefore not valid
> any more when vnc_worker_thread_loop returns.
>
>
>> about shrinking: I had the idea to count the number of times the buffer was (significantly) too big and only shrink if that counter has reached a reasonable value. and reset that counter to zero if the buffer has the right size.
>>
>> i would check this in qio_buffer_resize. as you suggested earlier.
> Not sure whenever it is a good idea to do that on every reserve call.
> Maybe better place shrink calls in places where you know it is worth
> checking, to have lower overhead.
>
> Patches are welcome in any case ;)

Please have a look at:

https://github.com/plieven/qemu/tree/vnc-next-2.0

Peter

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH V2] vnc: destroy server surface if no client is connected
  2015-10-01  9:52           ` Peter Lieven
@ 2015-10-02  7:36             ` Gerd Hoffmann
  2015-10-02  8:03               ` Peter Lieven
  2015-10-05 15:14               ` Peter Lieven
  0 siblings, 2 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2015-10-02  7:36 UTC (permalink / raw)
  To: Peter Lieven; +Cc: qemu-devel

  Hi,

> Please have a look at:
> 
> https://github.com/plieven/qemu/tree/vnc-next-2.0

Moving code to buf_adj_size and buf_req_size should go to a separate
patch.

The avg_size logic needs some description.

Picked up the "recycle empty vs->output buffer" patch.

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH V2] vnc: destroy server surface if no client is connected
  2015-10-02  7:36             ` Gerd Hoffmann
@ 2015-10-02  8:03               ` Peter Lieven
  2015-10-02  8:17                 ` Gerd Hoffmann
  2015-10-05 15:14               ` Peter Lieven
  1 sibling, 1 reply; 12+ messages in thread
From: Peter Lieven @ 2015-10-02  8:03 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel



> Am 02.10.2015 um 09:36 schrieb Gerd Hoffmann <kraxel@redhat.com>:
> 
>  Hi,
> 
>> Please have a look at:
>> 
>> https://github.com/plieven/qemu/tree/vnc-next-2.0
> 
> Moving code to buf_adj_size and buf_req_size should go to a separate
> patch.
> 
> The avg_size logic needs some description.

will send monday.

> 
> Picked up the "recycle empty vs->output buffer" patch.

please stash the dtc part from that Patch.

Peter

> 
> cheers,
>  Gerd
> 
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH V2] vnc: destroy server surface if no client is connected
  2015-10-02  8:03               ` Peter Lieven
@ 2015-10-02  8:17                 ` Gerd Hoffmann
  0 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2015-10-02  8:17 UTC (permalink / raw)
  To: Peter Lieven; +Cc: qemu-devel

  Hi,

> > Picked up the "recycle empty vs->output buffer" patch.
> 
> please stash the dtc part from that Patch.

Already done, git rebase handled it for me ;)

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH V2] vnc: destroy server surface if no client is connected
  2015-10-02  7:36             ` Gerd Hoffmann
  2015-10-02  8:03               ` Peter Lieven
@ 2015-10-05 15:14               ` Peter Lieven
  1 sibling, 0 replies; 12+ messages in thread
From: Peter Lieven @ 2015-10-05 15:14 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel

Am 02.10.2015 um 09:36 schrieb Gerd Hoffmann:
>    Hi,
>
>> Please have a look at:
>>
>> https://github.com/plieven/qemu/tree/vnc-next-2.0
> Moving code to buf_adj_size and buf_req_size should go to a separate
> patch.
>
> The avg_size logic needs some description.

Please have a look at:

https://github.com/plieven/qemu/tree/vnc-next-3.0

Peter

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-10-05 15:14 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-25 18:36 [Qemu-devel] [PATCH V2] vnc: destroy server surface if no client is connected Peter Lieven
2015-09-29 10:28 ` Gerd Hoffmann
2015-09-29 12:41   ` Peter Lieven
2015-09-29 12:49     ` Gerd Hoffmann
2015-09-29 13:31       ` Peter Lieven
2015-09-29 14:08         ` Gerd Hoffmann
2015-09-29 14:36           ` Peter Lieven
2015-10-01  9:52           ` Peter Lieven
2015-10-02  7:36             ` Gerd Hoffmann
2015-10-02  8:03               ` Peter Lieven
2015-10-02  8:17                 ` Gerd Hoffmann
2015-10-05 15:14               ` Peter Lieven

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.