qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCHv2 0/6] ui/vnc: update optimizations
@ 2013-11-21  8:51 Peter Lieven
  2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 1/6] ui/vnc: introduce VNC_DIRTY_PIXELS_PER_BIT macro Peter Lieven
                   ` (6 more replies)
  0 siblings, 7 replies; 11+ messages in thread
From: Peter Lieven @ 2013-11-21  8:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: corentincj, Peter Lieven, hengqing.hu, anthony

this series includes several optimizations for the ui/vnc guest to server and server to client
update cycles. comments/reviews appreciated.

v1->v2: - new patches 2,4,5
        - patch3: added performance test [Anthony]
        - patch3: further optimized the vnc_update_client by searching for the next zero bit
          with find_next_zero_bit.
        - patch3: further optimized vnc_dpy_switch by using bitmap_set to mask bits dirty.

Peter

Peter Lieven (6):
  ui/vnc: introduce VNC_DIRTY_PIXELS_PER_BIT macro
  ui/vnc: derive cmp_bytes from VNC_DIRTY_PIXELS_PER_BIT
  ui/vnc: optimize dirty bitmap tracking
  ui/vnc: optimize clearing in find_and_clear_dirty_height()
  ui/vnc: optimize setting in vnc_dpy_update()
  ui/vnc: disable adaptive update calculations if not needed

 ui/vnc.c |  185 ++++++++++++++++++++++++++++++++++++--------------------------
 ui/vnc.h |    9 ++-
 2 files changed, 115 insertions(+), 79 deletions(-)

-- 
1.7.9.5

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

* [Qemu-devel] [PATCHv2 1/6] ui/vnc: introduce VNC_DIRTY_PIXELS_PER_BIT macro
  2013-11-21  8:51 [Qemu-devel] [PATCHv2 0/6] ui/vnc: update optimizations Peter Lieven
@ 2013-11-21  8:51 ` Peter Lieven
  2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 2/6] ui/vnc: derive cmp_bytes from VNC_DIRTY_PIXELS_PER_BIT Peter Lieven
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Peter Lieven @ 2013-11-21  8:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: corentincj, Peter Lieven, hengqing.hu, anthony

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 ui/vnc.c |   55 ++++++++++++++++++++++++++++++++++---------------------
 ui/vnc.h |    6 +++++-
 2 files changed, 39 insertions(+), 22 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 5601cc3..67b1f75 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -442,17 +442,19 @@ static void vnc_dpy_update(DisplayChangeListener *dcl,
        iteration.  otherwise, if (x % 16) != 0, the last iteration may span
        two 16-pixel blocks but we only mark the first as dirty
     */
-    w += (x % 16);
-    x -= (x % 16);
+    w += (x % VNC_DIRTY_PIXELS_PER_BIT);
+    x -= (x % VNC_DIRTY_PIXELS_PER_BIT);
 
     x = MIN(x, width);
     y = MIN(y, height);
     w = MIN(x + w, width) - x;
     h = MIN(h, height);
 
-    for (; y < h; y++)
-        for (i = 0; i < w; i += 16)
-            set_bit((x + i) / 16, s->dirty[y]);
+    for (; y < h; y++) {
+        for (i = 0; i < w; i += VNC_DIRTY_PIXELS_PER_BIT) {
+            set_bit((x + i) / VNC_DIRTY_PIXELS_PER_BIT, s->dirty[y]);
+        }
+    }
 }
 
 void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
@@ -769,11 +771,11 @@ static void vnc_dpy_copy(DisplayChangeListener *dcl,
         y = dst_y + h - 1;
         inc = -1;
     }
-    w_lim = w - (16 - (dst_x % 16));
+    w_lim = w - (VNC_DIRTY_PIXELS_PER_BIT - (dst_x % VNC_DIRTY_PIXELS_PER_BIT));
     if (w_lim < 0)
         w_lim = w;
     else
-        w_lim = w - (w_lim % 16);
+        w_lim = w - (w_lim % VNC_DIRTY_PIXELS_PER_BIT);
     for (i = 0; i < h; i++) {
         for (x = 0; x <= w_lim;
                 x += s, src_row += cmp_bytes, dst_row += cmp_bytes) {
@@ -781,10 +783,10 @@ static void vnc_dpy_copy(DisplayChangeListener *dcl,
                 if ((s = w - w_lim) == 0)
                     break;
             } else if (!x) {
-                s = (16 - (dst_x % 16));
+                s = (16 - (dst_x % VNC_DIRTY_PIXELS_PER_BIT));
                 s = MIN(s, w_lim);
             } else {
-                s = 16;
+                s = VNC_DIRTY_PIXELS_PER_BIT;
             }
             cmp_bytes = s * VNC_SERVER_FB_BYTES;
             if (memcmp(src_row, dst_row, cmp_bytes) == 0)
@@ -911,7 +913,7 @@ static int vnc_update_client(VncState *vs, int has_dirty)
         for (y = 0; y < height; y++) {
             int x;
             int last_x = -1;
-            for (x = 0; x < width / 16; x++) {
+            for (x = 0; x < width / VNC_DIRTY_PIXELS_PER_BIT; x++) {
                 if (test_and_clear_bit(x, vs->dirty[y])) {
                     if (last_x == -1) {
                         last_x = x;
@@ -921,16 +923,21 @@ static int vnc_update_client(VncState *vs, int has_dirty)
                         int h = find_and_clear_dirty_height(vs, y, last_x, x,
                                                             height);
 
-                        n += vnc_job_add_rect(job, last_x * 16, y,
-                                              (x - last_x) * 16, h);
+                        n += vnc_job_add_rect(job,
+                                              last_x * VNC_DIRTY_PIXELS_PER_BIT,
+                                              y,
+                                              (x - last_x) * VNC_DIRTY_PIXELS_PER_BIT,
+                                              h);
                     }
                     last_x = -1;
                 }
             }
             if (last_x != -1) {
                 int h = find_and_clear_dirty_height(vs, y, last_x, x, height);
-                n += vnc_job_add_rect(job, last_x * 16, y,
-                                      (x - last_x) * 16, h);
+                n += vnc_job_add_rect(job, last_x * VNC_DIRTY_PIXELS_PER_BIT,
+                                      y,
+                                      (x - last_x) * VNC_DIRTY_PIXELS_PER_BIT,
+                                      h);
             }
         }
 
@@ -1861,7 +1868,7 @@ static void framebuffer_update_request(VncState *vs, int incremental,
                                        int w, int h)
 {
     int i;
-    const size_t width = surface_width(vs->vd->ds) / 16;
+    const size_t width = surface_width(vs->vd->ds) / VNC_DIRTY_PIXELS_PER_BIT;
     const size_t height = surface_height(vs->vd->ds);
 
     if (y_position > height) {
@@ -2563,7 +2570,9 @@ static int vnc_refresh_lossy_rect(VncDisplay *vd, int x, int y)
 
         vs->lossy_rect[sty][stx] = 0;
         for (j = 0; j < VNC_STAT_RECT; ++j) {
-            bitmap_set(vs->dirty[y + j], x / 16, VNC_STAT_RECT / 16);
+            bitmap_set(vs->dirty[y + j],
+                       x / VNC_DIRTY_PIXELS_PER_BIT,
+                       VNC_STAT_RECT / VNC_DIRTY_PIXELS_PER_BIT);
         }
         has_dirty++;
     }
@@ -2710,17 +2719,21 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
             }
             server_ptr = server_row;
 
-            for (x = 0; x + 15 < width;
-                    x += 16, guest_ptr += cmp_bytes, server_ptr += cmp_bytes) {
-                if (!test_and_clear_bit((x / 16), vd->guest.dirty[y]))
+            for (x = 0; x + VNC_DIRTY_PIXELS_PER_BIT - 1 < width;
+                 x += VNC_DIRTY_PIXELS_PER_BIT, guest_ptr += cmp_bytes,
+                 server_ptr += cmp_bytes) {
+                if (!test_and_clear_bit((x / VNC_DIRTY_PIXELS_PER_BIT),
+                    vd->guest.dirty[y])) {
                     continue;
-                if (memcmp(server_ptr, guest_ptr, cmp_bytes) == 0)
+                }
+                if (memcmp(server_ptr, guest_ptr, cmp_bytes) == 0) {
                     continue;
+                }
                 memcpy(server_ptr, guest_ptr, cmp_bytes);
                 if (!vd->non_adaptive)
                     vnc_rect_updated(vd, x, y, &tv);
                 QTAILQ_FOREACH(vs, &vd->clients, next) {
-                    set_bit((x / 16), vs->dirty[y]);
+                    set_bit((x / VNC_DIRTY_PIXELS_PER_BIT), vs->dirty[y]);
                 }
                 has_dirty++;
             }
diff --git a/ui/vnc.h b/ui/vnc.h
index 6e99213..4a8f33c 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -81,8 +81,12 @@ typedef void VncSendHextileTile(VncState *vs,
 #define VNC_MAX_WIDTH 2560
 #define VNC_MAX_HEIGHT 2048
 
+/* VNC_DIRTY_PIXELS_PER_BIT is the number of dirty pixels represented
+ * by one bit in the dirty bitmap */
+#define VNC_DIRTY_PIXELS_PER_BIT 16
+
 /* VNC_DIRTY_BITS is the number of bits in the dirty bitmap. */
-#define VNC_DIRTY_BITS (VNC_MAX_WIDTH / 16)
+#define VNC_DIRTY_BITS (VNC_MAX_WIDTH / VNC_DIRTY_PIXELS_PER_BIT)
 
 #define VNC_STAT_RECT  64
 #define VNC_STAT_COLS (VNC_MAX_WIDTH / VNC_STAT_RECT)
-- 
1.7.9.5

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

* [Qemu-devel] [PATCHv2 2/6] ui/vnc: derive cmp_bytes from VNC_DIRTY_PIXELS_PER_BIT
  2013-11-21  8:51 [Qemu-devel] [PATCHv2 0/6] ui/vnc: update optimizations Peter Lieven
  2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 1/6] ui/vnc: introduce VNC_DIRTY_PIXELS_PER_BIT macro Peter Lieven
@ 2013-11-21  8:51 ` Peter Lieven
  2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 3/6] ui/vnc: optimize dirty bitmap tracking Peter Lieven
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Peter Lieven @ 2013-11-21  8:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: corentincj, Peter Lieven, hengqing.hu, anthony

this allows for setting VNC_DIRTY_PIXELS_PER_BIT to different
values than 16 if desired.

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 ui/vnc.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 67b1f75..0c93058 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -2695,7 +2695,7 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
      * Check and copy modified bits from guest to server surface.
      * Update server dirty map.
      */
-    cmp_bytes = 64;
+    cmp_bytes = VNC_DIRTY_PIXELS_PER_BIT * VNC_SERVER_FB_BYTES;
     if (cmp_bytes > vnc_server_fb_stride(vd)) {
         cmp_bytes = vnc_server_fb_stride(vd);
     }
-- 
1.7.9.5

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

* [Qemu-devel] [PATCHv2 3/6] ui/vnc: optimize dirty bitmap tracking
  2013-11-21  8:51 [Qemu-devel] [PATCHv2 0/6] ui/vnc: update optimizations Peter Lieven
  2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 1/6] ui/vnc: introduce VNC_DIRTY_PIXELS_PER_BIT macro Peter Lieven
  2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 2/6] ui/vnc: derive cmp_bytes from VNC_DIRTY_PIXELS_PER_BIT Peter Lieven
@ 2013-11-21  8:51 ` Peter Lieven
  2013-11-21 15:16   ` Eric Blake
  2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 4/6] ui/vnc: optimize clearing in find_and_clear_dirty_height() Peter Lieven
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: Peter Lieven @ 2013-11-21  8:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: corentincj, Peter Lieven, hengqing.hu, anthony

vnc_update_client currently scans the dirty bitmap of each client
bitwise which is a very costly operation if only few bits are dirty.
vnc_refresh_server_surface does almost the same.
this patch optimizes both by utilizing the heavily optimized
function find_next_bit to find the offset of the next dirty
bit in the dirty bitmaps.

The following artifical test (just the bitmap operation part) running
vnc_update_client 65536 times on a 2560x2048 surface illustrates the
performance difference:

All bits clean - vnc_update_client_new: 0.07 secs
                 vnc_update_client_old: 10.98 secs

All bits dirty - vnc_update_client_new: 11.26 secs
                 vnc_update_client_old: 20.19 secs

Few bits dirty - vnc_update_client_new: 0.08 secs
                 vnc_update_client_old: 10.98 secs

The case for all bits dirty is still rather slow, this
is due to the implementation of find_and_clear_dirty_height.
This will be addresses in a separate patch.

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 ui/vnc.c |  153 ++++++++++++++++++++++++++++++++++----------------------------
 ui/vnc.h |    3 ++
 2 files changed, 86 insertions(+), 70 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 0c93058..5dd1efe 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -572,6 +572,14 @@ void *vnc_server_fb_ptr(VncDisplay *vd, int x, int y)
     ptr += x * VNC_SERVER_FB_BYTES;
     return ptr;
 }
+/* this sets only the visible pixels of a dirty bitmap */
+#define VNC_SET_VISIBLE_PIXELS_DIRTY(bitmap, w, h) {\
+        int y;\
+        memset(bitmap, 0x00, sizeof(bitmap));\
+        for (y = 0; y < h; y++) {\
+            bitmap_set(bitmap[y], 0, w / VNC_DIRTY_PIXELS_PER_BIT);\
+        } \
+    }
 
 static void vnc_dpy_switch(DisplayChangeListener *dcl,
                            DisplaySurface *surface)
@@ -597,7 +605,9 @@ static void vnc_dpy_switch(DisplayChangeListener *dcl,
     qemu_pixman_image_unref(vd->guest.fb);
     vd->guest.fb = pixman_image_ref(surface->image);
     vd->guest.format = surface->format;
-    memset(vd->guest.dirty, 0xFF, sizeof(vd->guest.dirty));
+    VNC_SET_VISIBLE_PIXELS_DIRTY(vd->guest.dirty,
+                                 surface_width(vd->ds),
+                                 surface_height(vd->ds));
 
     QTAILQ_FOREACH(vs, &vd->clients, next) {
         vnc_colordepth(vs);
@@ -605,7 +615,9 @@ static void vnc_dpy_switch(DisplayChangeListener *dcl,
         if (vs->vd->cursor) {
             vnc_cursor_define(vs);
         }
-        memset(vs->dirty, 0xFF, sizeof(vs->dirty));
+        VNC_SET_VISIBLE_PIXELS_DIRTY(vs->dirty,
+                                     surface_width(vd->ds),
+                                     surface_height(vd->ds));
     }
 }
 
@@ -888,10 +900,9 @@ static int vnc_update_client(VncState *vs, int has_dirty)
         VncDisplay *vd = vs->vd;
         VncJob *job;
         int y;
-        int width, height;
+        int height;
         int n = 0;
 
-
         if (vs->output.offset && !vs->audio_cap && !vs->force_update)
             /* kernel send buffers are full -> drop frames to throttle */
             return 0;
@@ -907,38 +918,27 @@ static int vnc_update_client(VncState *vs, int has_dirty)
          */
         job = vnc_job_new(vs);
 
-        width = MIN(pixman_image_get_width(vd->server), vs->client_width);
         height = MIN(pixman_image_get_height(vd->server), vs->client_height);
 
-        for (y = 0; y < height; y++) {
-            int x;
-            int last_x = -1;
-            for (x = 0; x < width / VNC_DIRTY_PIXELS_PER_BIT; x++) {
-                if (test_and_clear_bit(x, vs->dirty[y])) {
-                    if (last_x == -1) {
-                        last_x = x;
-                    }
-                } else {
-                    if (last_x != -1) {
-                        int h = find_and_clear_dirty_height(vs, y, last_x, x,
-                                                            height);
-
-                        n += vnc_job_add_rect(job,
-                                              last_x * VNC_DIRTY_PIXELS_PER_BIT,
-                                              y,
-                                              (x - last_x) * VNC_DIRTY_PIXELS_PER_BIT,
-                                              h);
-                    }
-                    last_x = -1;
-                }
-            }
-            if (last_x != -1) {
-                int h = find_and_clear_dirty_height(vs, y, last_x, x, height);
-                n += vnc_job_add_rect(job, last_x * VNC_DIRTY_PIXELS_PER_BIT,
-                                      y,
-                                      (x - last_x) * VNC_DIRTY_PIXELS_PER_BIT,
-                                      h);
+        y = 0;
+        for (;;) {
+            int x, h;
+            unsigned long x2;
+            unsigned long offset = find_next_bit((unsigned long *) &vs->dirty,
+                                                 height * VNC_DIRTY_BITS_PER_LINE(vs),
+                                                 y * VNC_DIRTY_BITS_PER_LINE(vs));
+            if (offset == height * VNC_DIRTY_BITS_PER_LINE(vs)) {
+                /* no more dirty bits */
+                break;
             }
+            y = offset / VNC_DIRTY_BITS_PER_LINE(vs);
+            x = offset % VNC_DIRTY_BITS_PER_LINE(vs);
+            x2 = find_next_zero_bit((unsigned long *) &vs->dirty[y],
+                                    VNC_DIRTY_BITS_PER_LINE(vs), x);
+            bitmap_clear(vs->dirty[y], x, x2 - x);
+            h = find_and_clear_dirty_height(vs, y, x, x2, height);
+            n += vnc_job_add_rect(job, x * VNC_DIRTY_PIXELS_PER_BIT, y,
+                                  (x2 - x) * VNC_DIRTY_PIXELS_PER_BIT, h);
         }
 
         vnc_job_push(job);
@@ -2676,8 +2676,8 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
     int width = pixman_image_get_width(vd->guest.fb);
     int height = pixman_image_get_height(vd->guest.fb);
     int y;
-    uint8_t *guest_row;
-    uint8_t *server_row;
+    uint8_t *guest_row0 = NULL, *server_row0;
+    int guest_stride = 0, server_stride;
     int cmp_bytes;
     VncState *vs;
     int has_dirty = 0;
@@ -2702,44 +2702,57 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
     if (vd->guest.format != VNC_SERVER_FB_FORMAT) {
         int width = pixman_image_get_width(vd->server);
         tmpbuf = qemu_pixman_linebuf_create(VNC_SERVER_FB_FORMAT, width);
-    }
-    guest_row = (uint8_t *)pixman_image_get_data(vd->guest.fb);
-    server_row = (uint8_t *)pixman_image_get_data(vd->server);
-    for (y = 0; y < height; y++) {
-        if (!bitmap_empty(vd->guest.dirty[y], VNC_DIRTY_BITS)) {
-            int x;
-            uint8_t *guest_ptr;
-            uint8_t *server_ptr;
-
-            if (vd->guest.format != VNC_SERVER_FB_FORMAT) {
-                qemu_pixman_linebuf_fill(tmpbuf, vd->guest.fb, width, 0, y);
-                guest_ptr = (uint8_t *)pixman_image_get_data(tmpbuf);
-            } else {
-                guest_ptr = guest_row;
-            }
-            server_ptr = server_row;
+    } else {
+        guest_row0 = (uint8_t *)pixman_image_get_data(vd->guest.fb);
+        guest_stride = pixman_image_get_stride(vd->guest.fb);
+    }
+    server_row0 = (uint8_t *)pixman_image_get_data(vd->server);
+    server_stride = pixman_image_get_stride(vd->server);
+
+    y = 0;
+    for (;;) {
+        int x;
+        uint8_t *guest_ptr, *server_ptr;
+        unsigned long offset = find_next_bit((unsigned long *) &vd->guest.dirty,
+                                             height * VNC_DIRTY_BITS_PER_LINE(&vd->guest),
+                                             y * VNC_DIRTY_BITS_PER_LINE(&vd->guest));
+        if (offset == height * VNC_DIRTY_BITS_PER_LINE(&vd->guest)) {
+            /* no more dirty bits */
+            break;
+        }
+        y = offset / VNC_DIRTY_BITS_PER_LINE(&vd->guest);
 
-            for (x = 0; x + VNC_DIRTY_PIXELS_PER_BIT - 1 < width;
-                 x += VNC_DIRTY_PIXELS_PER_BIT, guest_ptr += cmp_bytes,
-                 server_ptr += cmp_bytes) {
-                if (!test_and_clear_bit((x / VNC_DIRTY_PIXELS_PER_BIT),
-                    vd->guest.dirty[y])) {
-                    continue;
-                }
-                if (memcmp(server_ptr, guest_ptr, cmp_bytes) == 0) {
-                    continue;
-                }
-                memcpy(server_ptr, guest_ptr, cmp_bytes);
-                if (!vd->non_adaptive)
-                    vnc_rect_updated(vd, x, y, &tv);
-                QTAILQ_FOREACH(vs, &vd->clients, next) {
-                    set_bit((x / VNC_DIRTY_PIXELS_PER_BIT), vs->dirty[y]);
-                }
-                has_dirty++;
+        server_ptr = server_row0 + y * server_stride;
+
+        if (vd->guest.format != VNC_SERVER_FB_FORMAT) {
+            qemu_pixman_linebuf_fill(tmpbuf, vd->guest.fb, width, 0, y);
+            guest_ptr = (uint8_t *)pixman_image_get_data(tmpbuf);
+        } else {
+            guest_ptr = guest_row0 + y * guest_stride;
+        }
+
+        for (x = offset % VNC_DIRTY_BITS_PER_LINE(&vd->guest);
+             x + VNC_DIRTY_PIXELS_PER_BIT - 1 < width;
+             x += VNC_DIRTY_PIXELS_PER_BIT, guest_ptr += cmp_bytes,
+             server_ptr += cmp_bytes) {
+            if (!test_and_clear_bit((x / VNC_DIRTY_PIXELS_PER_BIT),
+                vd->guest.dirty[y])) {
+                continue;
+            }
+            if (memcmp(server_ptr, guest_ptr, cmp_bytes) == 0) {
+                continue;
+            }
+            memcpy(server_ptr, guest_ptr, cmp_bytes);
+            if (!vd->non_adaptive) {
+                vnc_rect_updated(vd, x, y, &tv);
             }
+            QTAILQ_FOREACH(vs, &vd->clients, next) {
+                set_bit((x / VNC_DIRTY_PIXELS_PER_BIT), vs->dirty[y]);
+            }
+            has_dirty++;
         }
-        guest_row  += pixman_image_get_stride(vd->guest.fb);
-        server_row += pixman_image_get_stride(vd->server);
+
+        y++;
     }
     qemu_pixman_image_unref(tmpbuf);
     return has_dirty;
diff --git a/ui/vnc.h b/ui/vnc.h
index 4a8f33c..82c8ea8 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -88,6 +88,9 @@ typedef void VncSendHextileTile(VncState *vs,
 /* VNC_DIRTY_BITS is the number of bits in the dirty bitmap. */
 #define VNC_DIRTY_BITS (VNC_MAX_WIDTH / VNC_DIRTY_PIXELS_PER_BIT)
 
+/* VNC_DIRTY_BITS_PER_LINE might be greater than VNC_DIRTY_BITS due to alignment */
+#define VNC_DIRTY_BITS_PER_LINE(x) (sizeof((x)->dirty) / VNC_MAX_HEIGHT * BITS_PER_BYTE)
+
 #define VNC_STAT_RECT  64
 #define VNC_STAT_COLS (VNC_MAX_WIDTH / VNC_STAT_RECT)
 #define VNC_STAT_ROWS (VNC_MAX_HEIGHT / VNC_STAT_RECT)
-- 
1.7.9.5

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

* [Qemu-devel] [PATCHv2 4/6] ui/vnc: optimize clearing in find_and_clear_dirty_height()
  2013-11-21  8:51 [Qemu-devel] [PATCHv2 0/6] ui/vnc: update optimizations Peter Lieven
                   ` (2 preceding siblings ...)
  2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 3/6] ui/vnc: optimize dirty bitmap tracking Peter Lieven
@ 2013-11-21  8:51 ` Peter Lieven
  2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 5/6] ui/vnc: optimize setting in vnc_dpy_update() Peter Lieven
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Peter Lieven @ 2013-11-21  8:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: corentincj, Peter Lieven, hengqing.hu, anthony

The following artifical test (just the bitmap operation part) running
vnc_update_client 65536 times on a 2560x2048 surface illustrates the
performance difference:

All bits clean - vnc_update_client_new: 0.07 secs
                 vnc_update_client_new2: 0.07 secs
                 vnc_update_client_old: 10.98 secs

All bits dirty - vnc_update_client_new: 11.26 secs
               - vnc_update_client_new2: 0.29 secs
                 vnc_update_client_old: 20.19 secs

Few bits dirty - vnc_update_client_new: 0.07 secs
               - vnc_update_client_new2: 0.07 secs
                 vnc_update_client_old: 10.98 secs

vnc_update_client_new2 shows the performance of vnc_update_client
with this patch added.

Comparing with the test run of the last patch the performance
is at least unchanged while it is significantly improved
for the all bits dirty case.

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 ui/vnc.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 5dd1efe..3bbf2af 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -875,13 +875,10 @@ static int find_and_clear_dirty_height(struct VncState *vs,
     int h;
 
     for (h = 1; h < (height - y); h++) {
-        int tmp_x;
         if (!test_bit(last_x, vs->dirty[y + h])) {
             break;
         }
-        for (tmp_x = last_x; tmp_x < x; tmp_x++) {
-            clear_bit(tmp_x, vs->dirty[y + h]);
-        }
+        bitmap_clear(vs->dirty[y + h], last_x, x - last_x);
     }
 
     return h;
-- 
1.7.9.5

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

* [Qemu-devel] [PATCHv2 5/6] ui/vnc: optimize setting in vnc_dpy_update()
  2013-11-21  8:51 [Qemu-devel] [PATCHv2 0/6] ui/vnc: update optimizations Peter Lieven
                   ` (3 preceding siblings ...)
  2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 4/6] ui/vnc: optimize clearing in find_and_clear_dirty_height() Peter Lieven
@ 2013-11-21  8:51 ` Peter Lieven
  2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 6/6] ui/vnc: disable adaptive update calculations if not needed Peter Lieven
  2013-12-04 17:56 ` [Qemu-devel] RESEND: [PATCHv2 0/6] ui/vnc: update optimizations Peter Lieven
  6 siblings, 0 replies; 11+ messages in thread
From: Peter Lieven @ 2013-11-21  8:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: corentincj, Peter Lieven, hengqing.hu, anthony

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 ui/vnc.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 3bbf2af..5134456 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -430,7 +430,6 @@ static int vnc_refresh_server_surface(VncDisplay *vd);
 static void vnc_dpy_update(DisplayChangeListener *dcl,
                            int x, int y, int w, int h)
 {
-    int i;
     VncDisplay *vd = container_of(dcl, VncDisplay, dcl);
     struct VncSurface *s = &vd->guest;
     int width = surface_width(vd->ds);
@@ -451,9 +450,7 @@ static void vnc_dpy_update(DisplayChangeListener *dcl,
     h = MIN(h, height);
 
     for (; y < h; y++) {
-        for (i = 0; i < w; i += VNC_DIRTY_PIXELS_PER_BIT) {
-            set_bit((x + i) / VNC_DIRTY_PIXELS_PER_BIT, s->dirty[y]);
-        }
+        bitmap_set(s->dirty[y], x / VNC_DIRTY_PIXELS_PER_BIT, w / VNC_DIRTY_PIXELS_PER_BIT);
     }
 }
 
-- 
1.7.9.5

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

* [Qemu-devel] [PATCHv2 6/6] ui/vnc: disable adaptive update calculations if not needed
  2013-11-21  8:51 [Qemu-devel] [PATCHv2 0/6] ui/vnc: update optimizations Peter Lieven
                   ` (4 preceding siblings ...)
  2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 5/6] ui/vnc: optimize setting in vnc_dpy_update() Peter Lieven
@ 2013-11-21  8:51 ` Peter Lieven
  2013-12-04 17:56 ` [Qemu-devel] RESEND: [PATCHv2 0/6] ui/vnc: update optimizations Peter Lieven
  6 siblings, 0 replies; 11+ messages in thread
From: Peter Lieven @ 2013-11-21  8:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: corentincj, Peter Lieven, hengqing.hu, anthony

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 ui/vnc.c |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/ui/vnc.c b/ui/vnc.c
index 5134456..46a9428 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -3169,7 +3169,9 @@ void vnc_display_open(DisplayState *ds, const char *display, Error **errp)
             acl = 1;
 #endif
         } else if (strncmp(options, "lossy", 5) == 0) {
+#ifdef CONFIG_VNC_JPEG
             vs->lossy = true;
+#endif
         } else if (strncmp(options, "non-adaptive", 12) == 0) {
             vs->non_adaptive = true;
         } else if (strncmp(options, "share=", 6) == 0) {
@@ -3186,6 +3188,13 @@ void vnc_display_open(DisplayState *ds, const char *display, Error **errp)
         }
     }
 
+    /* adaptive updates are only used with tight encoding and
+     * if lossy updates are enabled so we can disable all the
+     * calculations otherwise */
+    if (!vs->lossy) {
+        vs->non_adaptive = true;
+    }
+
 #ifdef CONFIG_VNC_TLS
     if (acl && x509 && vs->tls.x509verify) {
         if (!(vs->tls.acl = qemu_acl_init("vnc.x509dname"))) {
-- 
1.7.9.5

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

* Re: [Qemu-devel] [PATCHv2 3/6] ui/vnc: optimize dirty bitmap tracking
  2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 3/6] ui/vnc: optimize dirty bitmap tracking Peter Lieven
@ 2013-11-21 15:16   ` Eric Blake
  0 siblings, 0 replies; 11+ messages in thread
From: Eric Blake @ 2013-11-21 15:16 UTC (permalink / raw)
  To: Peter Lieven, qemu-devel; +Cc: corentincj, hengqing.hu, anthony

[-- Attachment #1: Type: text/plain, Size: 1243 bytes --]

On 11/21/2013 01:51 AM, Peter Lieven wrote:
> vnc_update_client currently scans the dirty bitmap of each client
> bitwise which is a very costly operation if only few bits are dirty.
> vnc_refresh_server_surface does almost the same.
> this patch optimizes both by utilizing the heavily optimized
> function find_next_bit to find the offset of the next dirty
> bit in the dirty bitmaps.
> 
> The following artifical test (just the bitmap operation part) running

s/artifical/artificial/

> vnc_update_client 65536 times on a 2560x2048 surface illustrates the
> performance difference:
> 
> All bits clean - vnc_update_client_new: 0.07 secs
>                  vnc_update_client_old: 10.98 secs
> 
> All bits dirty - vnc_update_client_new: 11.26 secs
>                  vnc_update_client_old: 20.19 secs
> 
> Few bits dirty - vnc_update_client_new: 0.08 secs
>                  vnc_update_client_old: 10.98 secs
> 
> The case for all bits dirty is still rather slow, this
> is due to the implementation of find_and_clear_dirty_height.
> This will be addresses in a separate patch.

s/addresses/addressed/

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 621 bytes --]

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

* [Qemu-devel] RESEND: [PATCHv2 0/6] ui/vnc: update optimizations
  2013-11-21  8:51 [Qemu-devel] [PATCHv2 0/6] ui/vnc: update optimizations Peter Lieven
                   ` (5 preceding siblings ...)
  2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 6/6] ui/vnc: disable adaptive update calculations if not needed Peter Lieven
@ 2013-12-04 17:56 ` Peter Lieven
  2013-12-04 18:20   ` Stefan Weil
  6 siblings, 1 reply; 11+ messages in thread
From: Peter Lieven @ 2013-12-04 17:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: corentincj, Peter Lieven, hengqing.hu, anthony

Ping

Am 21.11.2013 09:51, schrieb Peter Lieven:
> this series includes several optimizations for the ui/vnc guest to server and server to client
> update cycles. comments/reviews appreciated.
>
> v1->v2: - new patches 2,4,5
>         - patch3: added performance test [Anthony]
>         - patch3: further optimized the vnc_update_client by searching for the next zero bit
>           with find_next_zero_bit.
>         - patch3: further optimized vnc_dpy_switch by using bitmap_set to mask bits dirty.
>
> Peter
>
> Peter Lieven (6):
>   ui/vnc: introduce VNC_DIRTY_PIXELS_PER_BIT macro
>   ui/vnc: derive cmp_bytes from VNC_DIRTY_PIXELS_PER_BIT
>   ui/vnc: optimize dirty bitmap tracking
>   ui/vnc: optimize clearing in find_and_clear_dirty_height()
>   ui/vnc: optimize setting in vnc_dpy_update()
>   ui/vnc: disable adaptive update calculations if not needed
>
>  ui/vnc.c |  185 ++++++++++++++++++++++++++++++++++++--------------------------
>  ui/vnc.h |    9 ++-
>  2 files changed, 115 insertions(+), 79 deletions(-)
>

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

* Re: [Qemu-devel] RESEND: [PATCHv2 0/6] ui/vnc: update optimizations
  2013-12-04 17:56 ` [Qemu-devel] RESEND: [PATCHv2 0/6] ui/vnc: update optimizations Peter Lieven
@ 2013-12-04 18:20   ` Stefan Weil
  2013-12-04 21:04     ` Peter Lieven
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Weil @ 2013-12-04 18:20 UTC (permalink / raw)
  To: Peter Lieven, qemu-devel; +Cc: corentincj, hengqing.hu, anthony

Am 04.12.2013 18:56, schrieb Peter Lieven:
> Ping
>
> Am 21.11.2013 09:51, schrieb Peter Lieven:
>> this series includes several optimizations for the ui/vnc guest to server and server to client
>> update cycles. comments/reviews appreciated.
>>
>> v1->v2: - new patches 2,4,5
>>         - patch3: added performance test [Anthony]
>>         - patch3: further optimized the vnc_update_client by searching for the next zero bit
>>           with find_next_zero_bit.
>>         - patch3: further optimized vnc_dpy_switch by using bitmap_set to mask bits dirty.
>>
>> Peter
>>
>> Peter Lieven (6):
>>   ui/vnc: introduce VNC_DIRTY_PIXELS_PER_BIT macro
>>   ui/vnc: derive cmp_bytes from VNC_DIRTY_PIXELS_PER_BIT
>>   ui/vnc: optimize dirty bitmap tracking
>>   ui/vnc: optimize clearing in find_and_clear_dirty_height()
>>   ui/vnc: optimize setting in vnc_dpy_update()
>>   ui/vnc: disable adaptive update calculations if not needed
>>
>>  ui/vnc.c |  185 ++++++++++++++++++++++++++++++++++++--------------------------
>>  ui/vnc.h |    9 ++-
>>  2 files changed, 115 insertions(+), 79 deletions(-)

Hallo Peter,

there was an e-mail from Eric which you might consider in a 2nd version
of your patch series.

Please check also your patches using scripts/checkpatch.pl. Some of them
currently produce warnings:

total: 0 errors, 1 warnings, 139 lines
checked0001-ui-vnc-introduce-VNC_DIRTY_PIXELS_PER_BIT-macro.patch

total: 0 errors, 6 warnings, 212 lines
checked0003-ui-vnc-optimize-dirty-bitmap-tracking.patch

total: 0 errors, 1 warnings, 17 lines
checked0005-ui-vnc-optimize-setting-in-vnc_dpy_update.patch

I think it would also be reasonable to fix the coding style for this
code location in a separate patch
before modifying the else statement, but maybe this is optional:

     else
-        w_lim = w - (w_lim % 16);
+        w_lim = w - (w_lim % VNC_DIRTY_PIXELS_PER_BIT);


Viele Grüße

Stefan Weil

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

* Re: [Qemu-devel] RESEND: [PATCHv2 0/6] ui/vnc: update optimizations
  2013-12-04 18:20   ` Stefan Weil
@ 2013-12-04 21:04     ` Peter Lieven
  0 siblings, 0 replies; 11+ messages in thread
From: Peter Lieven @ 2013-12-04 21:04 UTC (permalink / raw)
  To: Stefan Weil, qemu-devel; +Cc: corentincj, hengqing.hu, anthony

Am 04.12.2013 19:20, schrieb Stefan Weil:
> Am 04.12.2013 18:56, schrieb Peter Lieven:
>> Ping
>>
>> Am 21.11.2013 09:51, schrieb Peter Lieven:
>>> this series includes several optimizations for the ui/vnc guest to server and server to client
>>> update cycles. comments/reviews appreciated.
>>>
>>> v1->v2: - new patches 2,4,5
>>>         - patch3: added performance test [Anthony]
>>>         - patch3: further optimized the vnc_update_client by searching for the next zero bit
>>>           with find_next_zero_bit.
>>>         - patch3: further optimized vnc_dpy_switch by using bitmap_set to mask bits dirty.
>>>
>>> Peter
>>>
>>> Peter Lieven (6):
>>>   ui/vnc: introduce VNC_DIRTY_PIXELS_PER_BIT macro
>>>   ui/vnc: derive cmp_bytes from VNC_DIRTY_PIXELS_PER_BIT
>>>   ui/vnc: optimize dirty bitmap tracking
>>>   ui/vnc: optimize clearing in find_and_clear_dirty_height()
>>>   ui/vnc: optimize setting in vnc_dpy_update()
>>>   ui/vnc: disable adaptive update calculations if not needed
>>>
>>>  ui/vnc.c |  185 ++++++++++++++++++++++++++++++++++++--------------------------
>>>  ui/vnc.h |    9 ++-
>>>  2 files changed, 115 insertions(+), 79 deletions(-)
> Hallo Peter,
>
> there was an e-mail from Eric which you might consider in a 2nd version
> of your patch series.
>
> Please check also your patches using scripts/checkpatch.pl. Some of them
> currently produce warnings:
ups, i was sure to have checked this...
>
> total: 0 errors, 1 warnings, 139 lines
> checked0001-ui-vnc-introduce-VNC_DIRTY_PIXELS_PER_BIT-macro.patch
>
> total: 0 errors, 6 warnings, 212 lines
> checked0003-ui-vnc-optimize-dirty-bitmap-tracking.patch
>
> total: 0 errors, 1 warnings, 17 lines
> checked0005-ui-vnc-optimize-setting-in-vnc_dpy_update.patch
>
> I think it would also be reasonable to fix the coding style for this
> code location in a separate patch
> before modifying the else statement, but maybe this is optional:
>
>      else
> -        w_lim = w - (w_lim % 16);
> +        w_lim = w - (w_lim % VNC_DIRTY_PIXELS_PER_BIT);
i will wait for further feedback and fix all these in v3.

Thanks,
Peter

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

end of thread, other threads:[~2013-12-04 21:04 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-21  8:51 [Qemu-devel] [PATCHv2 0/6] ui/vnc: update optimizations Peter Lieven
2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 1/6] ui/vnc: introduce VNC_DIRTY_PIXELS_PER_BIT macro Peter Lieven
2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 2/6] ui/vnc: derive cmp_bytes from VNC_DIRTY_PIXELS_PER_BIT Peter Lieven
2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 3/6] ui/vnc: optimize dirty bitmap tracking Peter Lieven
2013-11-21 15:16   ` Eric Blake
2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 4/6] ui/vnc: optimize clearing in find_and_clear_dirty_height() Peter Lieven
2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 5/6] ui/vnc: optimize setting in vnc_dpy_update() Peter Lieven
2013-11-21  8:51 ` [Qemu-devel] [PATCHv2 6/6] ui/vnc: disable adaptive update calculations if not needed Peter Lieven
2013-12-04 17:56 ` [Qemu-devel] RESEND: [PATCHv2 0/6] ui/vnc: update optimizations Peter Lieven
2013-12-04 18:20   ` Stefan Weil
2013-12-04 21:04     ` Peter Lieven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).