All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 3 of 3] variable timer intervals
@ 2009-07-29 12:09 Stefano Stabellini
  2009-07-29 14:41 ` Gerd Hoffmann
  0 siblings, 1 reply; 3+ messages in thread
From: Stefano Stabellini @ 2009-07-29 12:09 UTC (permalink / raw)
  To: qemu-devel

This patch introduces dynamic timer intervals: we slow down the refresh
rate when there in no much activity but we get back to a fast refresh
rate when the activity resume.

Please note that qemu_timer_expired is not an inline function any more
because I needed to call it from vnc.c however I don't think this change
should have any serious consequence.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

---

diff --git a/qemu-timer.h b/qemu-timer.h
index 3f8880d..8f69467 100644
--- a/qemu-timer.h
+++ b/qemu-timer.h
@@ -24,6 +24,7 @@ void qemu_free_timer(QEMUTimer *ts);
 void qemu_del_timer(QEMUTimer *ts);
 void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
 int qemu_timer_pending(QEMUTimer *ts);
+int qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time);
 
 extern int64_t ticks_per_sec;
 
diff --git a/vl.c b/vl.c
index ce213c2..e433223 100644
--- a/vl.c
+++ b/vl.c
@@ -1001,7 +1001,7 @@ int qemu_timer_pending(QEMUTimer *ts)
     return 0;
 }
 
-static inline int qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time)
+int qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time)
 {
     if (!timer_head)
         return 0;
diff --git a/vnc.c b/vnc.c
index fa8547f..ca3046a 100644
--- a/vnc.c
+++ b/vnc.c
@@ -30,7 +30,9 @@
 #include "qemu-timer.h"
 #include "acl.h"
 
-#define VNC_REFRESH_INTERVAL (1000 / 30)
+#define VNC_REFRESH_INTERVAL_BASE 30
+#define VNC_REFRESH_INTERVAL_INC  50
+#define VNC_REFRESH_INTERVAL_MAX  2000
 
 #include "vnc_keysym.h"
 #include "d3des.h"
@@ -215,7 +217,7 @@ static inline uint32_t vnc_has_feature(VncState *vs, int feature) {
    3) resolutions > 1024
 */
 
-static void vnc_update_client(VncState *vs, int has_dirty);
+static int vnc_update_client(VncState *vs, int has_dirty);
 static void vnc_disconnect_start(VncState *vs);
 static void vnc_disconnect_finish(VncState *vs);
 static void vnc_init_timer(VncDisplay *vd);
@@ -693,7 +695,7 @@ static int find_and_clear_dirty_height(struct VncState *vs,
     return h;
 }
 
-static void vnc_update_client(VncState *vs, int has_dirty)
+static int vnc_update_client(VncState *vs, int has_dirty)
 {
     if (vs->need_update && vs->csock != -1) {
         VncDisplay *vd = vs->vd;
@@ -703,10 +705,10 @@ static void vnc_update_client(VncState *vs, int has_dirty)
 
         if (vs->output.offset && !vs->audio_cap && !vs->force_update)
             /* kernel send buffers are full -> drop frames to throttle */
-            return;
+            return 0;
 
         if (!has_dirty && !vs->audio_cap && !vs->force_update)
-            return;
+            return 0;
 
         /*
          * Send screen updates to the vnc client using the server
@@ -748,11 +750,13 @@ static void vnc_update_client(VncState *vs, int has_dirty)
         vs->output.buffer[saved_offset + 1] = n_rectangles & 0xFF;
         vnc_flush(vs);
         vs->force_update = 0;
-
+        return n_rectangles;
     }
 
     if (vs->csock == -1)
         vnc_disconnect_finish(vs);
+
+    return 0;
 }
 
 /* audio */
@@ -1643,6 +1647,13 @@ static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len)
 {
     int i;
     uint16_t limit;
+    VncDisplay *vd = vs->vd;
+
+    if (data[0] > 3) {
+        vd->timer_interval = VNC_REFRESH_INTERVAL_BASE;
+        if (!qemu_timer_expired(vd->timer, qemu_get_clock(rt_clock) + vd->timer_interval))
+            qemu_mod_timer(vd->timer, qemu_get_clock(rt_clock) + vd->timer_interval);
+    }
 
     switch (data[0]) {
     case 0:
@@ -2001,7 +2012,7 @@ static void vnc_refresh(void *opaque)
     uint8_t *server_row;
     int cmp_bytes;
     uint32_t width_mask[VNC_DIRTY_WORDS];
-    int has_dirty = 0;
+    int has_dirty = 0, rects = 0;
 
     vga_hw_update();
 
@@ -2045,15 +2056,25 @@ static void vnc_refresh(void *opaque)
 
     vs = vd->clients;
     while (vs != NULL) {
-        vnc_update_client(vs, has_dirty);
+        rects += vnc_update_client(vs, has_dirty);
         vs = vs->next;
     }
 
-    qemu_mod_timer(vd->timer, qemu_get_clock(rt_clock) + VNC_REFRESH_INTERVAL);
+    if (has_dirty && rects) {
+        vd->timer_interval /= 2;
+        if (vd->timer_interval < VNC_REFRESH_INTERVAL_BASE)
+            vd->timer_interval = VNC_REFRESH_INTERVAL_BASE;
+    } else {
+        vd->timer_interval += VNC_REFRESH_INTERVAL_INC;
+        if (vd->timer_interval > VNC_REFRESH_INTERVAL_MAX)
+            vd->timer_interval = VNC_REFRESH_INTERVAL_MAX;
+    }
+    qemu_mod_timer(vd->timer, qemu_get_clock(rt_clock) + vd->timer_interval);
 }
 
 static void vnc_init_timer(VncDisplay *vd)
 {
+    vd->timer_interval = VNC_REFRESH_INTERVAL_BASE;
     if (vd->timer == NULL && vd->clients != NULL) {
         vd->timer = qemu_new_timer(rt_clock, vnc_refresh, vd);
         vnc_refresh(vd);
diff --git a/vnc.h b/vnc.h
index 5c903de..fcc6824 100644
--- a/vnc.h
+++ b/vnc.h
@@ -93,6 +93,7 @@ struct VncSurface
 struct VncDisplay
 {
     QEMUTimer *timer;
+    int timer_interval;
     int lsock;
     DisplayState *ds;
     VncState *clients;

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

* Re: [Qemu-devel] [PATCH 3 of 3] variable timer intervals
  2009-07-29 12:09 [Qemu-devel] [PATCH 3 of 3] variable timer intervals Stefano Stabellini
@ 2009-07-29 14:41 ` Gerd Hoffmann
  2009-07-29 14:48   ` Stefano Stabellini
  0 siblings, 1 reply; 3+ messages in thread
From: Gerd Hoffmann @ 2009-07-29 14:41 UTC (permalink / raw)
  To: Stefano Stabellini; +Cc: qemu-devel

On 07/29/09 14:09, Stefano Stabellini wrote:
> This patch introduces dynamic timer intervals: we slow down the refresh
> rate when there in no much activity but we get back to a fast refresh
> rate when the activity resume.

Looks good in principle.  Untested though because it doesn't apply 
without patch #2.

>           if (vs->output.offset&&  !vs->audio_cap&&  !vs->force_update)
>               /* kernel send buffers are full ->  drop frames to throttle */
> -            return;
> +            return 0;

Maybe it makes sense to integrate this throttle logic into the refresh 
rate adaption?

cheers,
   Gerd

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

* Re: [Qemu-devel] [PATCH 3 of 3] variable timer intervals
  2009-07-29 14:41 ` Gerd Hoffmann
@ 2009-07-29 14:48   ` Stefano Stabellini
  0 siblings, 0 replies; 3+ messages in thread
From: Stefano Stabellini @ 2009-07-29 14:48 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel@nongnu.org, Stefano Stabellini

On Wed, 29 Jul 2009, Gerd Hoffmann wrote:
> On 07/29/09 14:09, Stefano Stabellini wrote:
> > This patch introduces dynamic timer intervals: we slow down the refresh
> > rate when there in no much activity but we get back to a fast refresh
> > rate when the activity resume.
> 
> Looks good in principle.  Untested though because it doesn't apply 
> without patch #2.
> 
> >           if (vs->output.offset&&  !vs->audio_cap&&  !vs->force_update)
> >               /* kernel send buffers are full ->  drop frames to throttle */
> > -            return;
> > +            return 0;
> 
> Maybe it makes sense to integrate this throttle logic into the refresh 
> rate adaption?

Please don't drop #2 just because of copyrect: I would rather fix
copyrect myself before #2 and rebase #2 on top of it.

I also prefer to keep #3 separated and at the end of the series because we
can have a better logic to understand when it makes sense to slow down
the refresh rate.

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

end of thread, other threads:[~2009-07-29 14:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-29 12:09 [Qemu-devel] [PATCH 3 of 3] variable timer intervals Stefano Stabellini
2009-07-29 14:41 ` Gerd Hoffmann
2009-07-29 14:48   ` Stefano Stabellini

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.