Skip to contentSkip to conversation

Slowdown SDL while minimized

PATCH In review Samuel Thibault 2 participants 4 messages Mar 11, 2008 – Mar 12, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Slowdown SDL while minimized

When SDL is invisible/minimized, there is no need to keep calling the VGA refresh 33 times per second. This patch reduces in that case the rate to 2 times per second, which should be responsive enough for the un-minimizing event.

Index: console.h
===================================================================
RCS file: /sources/qemu/qemu/console.h,v
retrieving revision 1.2

console.h +1 -0
diff -u -p -r1.2 console.h
@@ -71,6 +71,7 @@
     int height;
     void *opaque;
     struct QEMUTimer *gui_timer;
+    uint64_t gui_timer_interval;
 
     void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
     void (*dpy_resize)(struct DisplayState *s, int w, int h);

Index: sdl.c
===================================================================
RCS file: /sources/qemu/qemu/sdl.c,v
retrieving revision 1.46

sdl.c +9 -0
@@ -506,6 +506,15 @@
                 !ev->active.gain && !gui_fullscreen_initial_grab) {
                 sdl_grab_end();
             }
+	    if (ev->active.state & SDL_APPACTIVE) {
+		if (ev->active.gain) {
+		    /* Back to default interval */
+		    ds->gui_timer_interval = 0;
+		} else {
+		    /* Sleeping interval */
+		    ds->gui_timer_interval = 500;
+		}
+	    }
             break;
         default:
             break;

Index: vl.c
===================================================================
RCS file: /sources/qemu/qemu/vl.c,v
retrieving revision 1.410

vl.c +5 -1
@@ -7208,7 +7200,11 @@
 {
     DisplayState *ds = opaque;
     ds->dpy_refresh(ds);
-    qemu_mod_timer(ds->gui_timer, GUI_REFRESH_INTERVAL + qemu_get_clock(rt_clock));
+    qemu_mod_timer(ds->gui_timer,
+        (ds->gui_timer_interval ?
+	    ds->gui_timer_interval :
+	    GUI_REFRESH_INTERVAL)
+	+ qemu_get_clock(rt_clock));
 }
 
 struct vm_change_state_entry {
#1 lore raw

BTW, it would be good for power consumption to provide a virtual HPET to the guest, and reprogram the host timer as appropriate. 10ms sleeps kill kitten ;)

Samuel

#2 lore raw
In reply to Samuel Thibault
Quoted 5 lines · Samuel Thibault

When SDL is invisible/minimized, there is no need to keep calling the VGA refresh 33 times per second. This patch reduces in that case the rate to 2 times per second, which should be responsive enough for the un-minimizing event.

Is there any need to update at all, if the canvas is not visible? How about some infrastructure for pausing the update completely? I think that could also be used for VNC displays, when no client is connected.

Anders.

#3 lore raw
Quoted 8 lines · Anders, le Wed 12 Mar 2008 00:56:42 +0100, a écrit :
Quoted 5 lines · Samuel Thibault

When SDL is invisible/minimized, there is no need to keep calling the VGA refresh 33 times per second. This patch reduces in that case the rate to 2 times per second, which should be responsive enough for the un-minimizing event.

Is there any need to update at all, if the canvas is not visible?

Indeed not. We however still need to have a look at the SDL queue, to detect the un-minimize event.

Quoted 3 lines

How about some infrastructure for pausing the update completely? I think that could also be used for VNC displays, when no client is connected.

Actually in Xen it goes even further: when the client hasn't sent an update request since a long time, the VNC server assumes the client is minimized, and in pratice that is the case.

Samuel