Message ID | 4C23C17B8E87E74E906A25A3254A03F4FA22100C@SHASXM06.verisilicon.com |
---|---|
State | New |
Headers | show |
Series | ui: avoid unnecessary memory operations in vnc_refresh_server_surface() | expand |
Hi On Tue, Mar 15, 2022 at 11:24 AM Wen, Jianxian <Jianxian.Wen@verisilicon.com> wrote: > Check the dirty bits in advance to avoid unnecessary memory operations. > In the case that guest surface has different format than the server, > but it does not have dirty bits which means no refresh is actually needed, > the memory operations is not necessary. > > Signed-off-by: Jianxian Wen <jianxian.wen@verisilicon.com> > Signed-off-by: Lu Gao <lu.gao@verisilicon.com> > --- > ui/vnc.c | 26 +++++++++++++++++--------- > 1 file changed, 17 insertions(+), 9 deletions(-) > > diff --git a/ui/vnc.c b/ui/vnc.c > index 3ccd33dedc..310a873c21 100644 > --- a/ui/vnc.c > +++ b/ui/vnc.c > @@ -3098,6 +3098,9 @@ static int vnc_refresh_server_surface(VncDisplay *vd) > VncState *vs; > int has_dirty = 0; > pixman_image_t *tmpbuf = NULL; > + unsigned long offset; > + int x; > + uint8_t *guest_ptr, *server_ptr; > > struct timeval tv = { 0, 0 }; > > @@ -3106,6 +3109,13 @@ static int vnc_refresh_server_surface(VncDisplay > *vd) > has_dirty = vnc_update_stats(vd, &tv); > } > > + offset = find_next_bit((unsigned long *) &vd->guest.dirty, > + height * VNC_DIRTY_BPL(&vd->guest), 0); > + if (offset == height * VNC_DIRTY_BPL(&vd->guest)) { > + /* no dirty bits in guest surface */ > + return has_dirty; > + } > + > /* > * Walk through the guest dirty map. > * Check and copy modified bits from guest to server surface. > @@ -3130,15 +3140,6 @@ static int vnc_refresh_server_surface(VncDisplay > *vd) > line_bytes = MIN(server_stride, guest_ll); > > for (;;) { > - int x; > - uint8_t *guest_ptr, *server_ptr; > - unsigned long offset = find_next_bit((unsigned long *) > &vd->guest.dirty, > - height * > VNC_DIRTY_BPL(&vd->guest), > - y * > VNC_DIRTY_BPL(&vd->guest)); > - if (offset == height * VNC_DIRTY_BPL(&vd->guest)) { > - /* no more dirty bits */ > - break; > - } > y = offset / VNC_DIRTY_BPL(&vd->guest); > x = offset % VNC_DIRTY_BPL(&vd->guest); > > @@ -3177,6 +3178,13 @@ static int vnc_refresh_server_surface(VncDisplay > *vd) > } > > y++; > + offset = find_next_bit((unsigned long *) &vd->guest.dirty, > + height * VNC_DIRTY_BPL(&vd->guest), > + y * VNC_DIRTY_BPL(&vd->guest)); > + if (offset == height * VNC_DIRTY_BPL(&vd->guest)) { > + /* no more dirty bits */ > + break; > + } > } > qemu_pixman_image_unref(tmpbuf); > return has_dirty; > -- > 2.33.0 > > lgtm, Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
diff --git a/ui/vnc.c b/ui/vnc.c index 3ccd33dedc..310a873c21 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3098,6 +3098,9 @@ static int vnc_refresh_server_surface(VncDisplay *vd) VncState *vs; int has_dirty = 0; pixman_image_t *tmpbuf = NULL; + unsigned long offset; + int x; + uint8_t *guest_ptr, *server_ptr; struct timeval tv = { 0, 0 }; @@ -3106,6 +3109,13 @@ static int vnc_refresh_server_surface(VncDisplay *vd) has_dirty = vnc_update_stats(vd, &tv); } + offset = find_next_bit((unsigned long *) &vd->guest.dirty, + height * VNC_DIRTY_BPL(&vd->guest), 0); + if (offset == height * VNC_DIRTY_BPL(&vd->guest)) { + /* no dirty bits in guest surface */ + return has_dirty; + } + /* * Walk through the guest dirty map. * Check and copy modified bits from guest to server surface. @@ -3130,15 +3140,6 @@ static int vnc_refresh_server_surface(VncDisplay *vd) line_bytes = MIN(server_stride, guest_ll); for (;;) { - int x; - uint8_t *guest_ptr, *server_ptr; - unsigned long offset = find_next_bit((unsigned long *) &vd->guest.dirty, - height * VNC_DIRTY_BPL(&vd->guest), - y * VNC_DIRTY_BPL(&vd->guest)); - if (offset == height * VNC_DIRTY_BPL(&vd->guest)) { - /* no more dirty bits */ - break; - } y = offset / VNC_DIRTY_BPL(&vd->guest); x = offset % VNC_DIRTY_BPL(&vd->guest); @@ -3177,6 +3178,13 @@ static int vnc_refresh_server_surface(VncDisplay *vd) } y++; + offset = find_next_bit((unsigned long *) &vd->guest.dirty, + height * VNC_DIRTY_BPL(&vd->guest), + y * VNC_DIRTY_BPL(&vd->guest)); + if (offset == height * VNC_DIRTY_BPL(&vd->guest)) { + /* no more dirty bits */ + break; + } } qemu_pixman_image_unref(tmpbuf); return has_dirty;