From patchwork Fri Feb 4 08:05:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Chary X-Patchwork-Id: 81829 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B9051B710E for ; Fri, 4 Feb 2011 19:55:16 +1100 (EST) Received: from localhost ([127.0.0.1]:34533 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PlGp6-0007fT-DA for incoming@patchwork.ozlabs.org; Fri, 04 Feb 2011 03:15:20 -0500 Received: from [140.186.70.92] (port=49327 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PlGez-0003fn-75 for qemu-devel@nongnu.org; Fri, 04 Feb 2011 03:04:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PlGex-0001hw-NJ for qemu-devel@nongnu.org; Fri, 04 Feb 2011 03:04:53 -0500 Received: from smtp5-g21.free.fr ([212.27.42.5]:51402) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PlGex-0001hB-6F for qemu-devel@nongnu.org; Fri, 04 Feb 2011 03:04:51 -0500 Received: from localhost.localdomain (unknown [82.241.209.44]) by smtp5-g21.free.fr (Postfix) with ESMTP id B1CF0D480FB; Fri, 4 Feb 2011 09:04:45 +0100 (CET) From: Corentin Chary To: Anthony Liguori Date: Fri, 4 Feb 2011 09:05:56 +0100 Message-Id: <1296806768-27787-5-git-send-email-corentincj@iksaif.net> X-Mailer: git-send-email 1.7.4 In-Reply-To: <1296806768-27787-1-git-send-email-corentincj@iksaif.net> References: <1296806768-27787-1-git-send-email-corentincj@iksaif.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 212.27.42.5 Cc: Corentin Chary , Andre Przywara , Qemu-development List , Alexander Graf Subject: [Qemu-devel] [PATCH v3 04/16] vnc: refresh lossy rect after a given timeout X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If an adaptive encoding has choosen to send a lossy update based on the result of vnc_update_freq(), then it should advertise it with vnc_sent_lossy_rect(). This will allow to automatically refresh this rect once it's static again. Signed-off-by: Corentin Chary --- ui/vnc-jobs-async.c | 2 + ui/vnc.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++-- ui/vnc.h | 3 ++ 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/ui/vnc-jobs-async.c b/ui/vnc-jobs-async.c index 0b5d750..bfe8e86 100644 --- a/ui/vnc-jobs-async.c +++ b/ui/vnc-jobs-async.c @@ -166,6 +166,7 @@ static void vnc_async_encoding_start(VncState *orig, VncState *local) local->features = orig->features; local->ds = orig->ds; local->vd = orig->vd; + local->lossy_rect = orig->lossy_rect; local->write_pixels = orig->write_pixels; local->clientds = orig->clientds; local->tight = orig->tight; @@ -182,6 +183,7 @@ static void vnc_async_encoding_end(VncState *orig, VncState *local) orig->tight = local->tight; orig->zlib = local->zlib; orig->hextile = local->hextile; + orig->lossy_rect = local->lossy_rect; } static int vnc_worker_thread_loop(VncJobQueue *queue) diff --git a/ui/vnc.c b/ui/vnc.c index 6eacd1d..697b836 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -1014,6 +1014,8 @@ static void vnc_disconnect_start(VncState *vs) static void vnc_disconnect_finish(VncState *vs) { + int i; + vnc_jobs_join(vs); /* Wait encoding jobs */ vnc_lock_output(vs); @@ -1050,6 +1052,10 @@ static void vnc_disconnect_finish(VncState *vs) #ifdef CONFIG_VNC_THREAD qemu_mutex_destroy(&vs->output_mutex); #endif + for (i = 0; i < VNC_STAT_ROWS; ++i) { + qemu_free(vs->lossy_rect[i]); + } + qemu_free(vs->lossy_rect); qemu_free(vs); } @@ -2267,10 +2273,57 @@ static VncRectStat *vnc_stat_rect(VncDisplay *vd, int x, int y) return &vs->stats[y / VNC_STAT_RECT][x / VNC_STAT_RECT]; } -static void vnc_update_stats(VncDisplay *vd, struct timeval * tv) +void vnc_sent_lossy_rect(VncState *vs, int x, int y, int w, int h) +{ + int i, j; + + w = (x + w) / VNC_STAT_RECT; + h = (y + h) / VNC_STAT_RECT; + x /= VNC_STAT_RECT; + y /= VNC_STAT_RECT; + + for (j = y; j <= y + h; j++) { + for (i = x; i <= x + w; i++) { + vs->lossy_rect[j][i] = 1; + } + } +} + +static int vnc_refresh_lossy_rect(VncDisplay *vd, int x, int y) +{ + VncState *vs; + int sty = y / VNC_STAT_RECT; + int stx = x / VNC_STAT_RECT; + int has_dirty = 0; + + y = y / VNC_STAT_RECT * VNC_STAT_RECT; + x = x / VNC_STAT_RECT * VNC_STAT_RECT; + + QTAILQ_FOREACH(vs, &vd->clients, next) { + int j; + + /* kernel send buffers are full -> refresh later */ + if (vs->output.offset) { + continue; + } + + if (!vs->lossy_rect[sty][stx]) { + continue; + } + vs->lossy_rect[sty][stx] = 0; + for (j = 0; j < VNC_STAT_RECT; ++j) { + vnc_set_bits(vs->dirty[y + j], x / 16, VNC_STAT_RECT / 16); + } + has_dirty++; + } + return has_dirty; +} + +static int vnc_update_stats(VncDisplay *vd, struct timeval * tv) { int x, y; struct timeval res; + int has_dirty = 0; for (y = 0; y < vd->guest.ds->height; y += VNC_STAT_RECT) { for (x = 0; x < vd->guest.ds->width; x += VNC_STAT_RECT) { @@ -2283,7 +2336,7 @@ static void vnc_update_stats(VncDisplay *vd, struct timeval * tv) timersub(tv, &VNC_REFRESH_STATS, &res); if (timercmp(&vd->guest.last_freq_check, &res, >)) { - return ; + return has_dirty; } vd->guest.last_freq_check = *tv; @@ -2302,6 +2355,7 @@ static void vnc_update_stats(VncDisplay *vd, struct timeval * tv) if (timercmp(&res, &VNC_REFRESH_LOSSY, >)) { rect->freq = 0; + has_dirty += vnc_refresh_lossy_rect(vd, x, y); memset(rect->times, 0, sizeof (rect->times)); continue ; } @@ -2315,6 +2369,7 @@ static void vnc_update_stats(VncDisplay *vd, struct timeval * tv) rect->freq = 1. / rect->freq; } } + return has_dirty; } double vnc_update_freq(VncState *vs, int x, int y, int w, int h) @@ -2366,7 +2421,7 @@ static int vnc_refresh_server_surface(VncDisplay *vd) struct timeval tv; gettimeofday(&tv, NULL); - vnc_update_stats(vd, &tv); + has_dirty = vnc_update_stats(vd, &tv); /* * Walk through the guest dirty map. @@ -2468,7 +2523,13 @@ static void vnc_remove_timer(VncDisplay *vd) static void vnc_connect(VncDisplay *vd, int csock) { VncState *vs = qemu_mallocz(sizeof(VncState)); + int i; + vs->csock = csock; + vs->lossy_rect = qemu_mallocz(VNC_STAT_ROWS * sizeof (*vs->lossy_rect)); + for (i = 0; i < VNC_STAT_ROWS; ++i) { + vs->lossy_rect[i] = qemu_mallocz(VNC_STAT_COLS * sizeof (uint8_t)); + } VNC_DEBUG("New client on socket %d\n", csock); dcl->idle = 0; diff --git a/ui/vnc.h b/ui/vnc.h index c0e5ff3..57835f1 100644 --- a/ui/vnc.h +++ b/ui/vnc.h @@ -217,6 +217,8 @@ struct VncState DisplayState *ds; uint32_t dirty[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS]; + uint8_t **lossy_rect; /* Not an Array to avoid costly memcpy in + * vnc-jobs-async.c */ VncDisplay *vd; int need_update; @@ -498,6 +500,7 @@ void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h, void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v); double vnc_update_freq(VncState *vs, int x, int y, int w, int h); +void vnc_sent_lossy_rect(VncState *vs, int x, int y, int w, int h); /* Encodings */ int vnc_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);