Patchwork [3/5] Fix and simplify gui timer logic.

login
register
mail settings
Submitter Gerd Hoffmann
Date June 15, 2010, 10:05 a.m.
Message ID <1276596347-9410-4-git-send-email-kraxel@redhat.com>
Download mbox | patch
Permalink /patch/55626/
State New
Headers show

Comments

Gerd Hoffmann - June 15, 2010, 10:05 a.m.
Kill the nographic and gui timers.  Add a single periodic_timer to
replace them.  We have a timer running anyway, so so the gui/nographic
separation is pretty pointless, we can just drive everything we need
from the single periodic timer.

Don't allocate the timer twice in case we have two display listeners.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 console.h |    1 -
 vl.c      |   40 ++++++++++++----------------------------
 2 files changed, 12 insertions(+), 29 deletions(-)

Patch

diff --git a/console.h b/console.h
index 3f77661..f866987 100644
--- a/console.h
+++ b/console.h
@@ -174,7 +174,6 @@  struct DisplayAllocator {
 struct DisplayState {
     struct DisplaySurface *surface;
     void *opaque;
-    struct QEMUTimer *gui_timer;
 
     struct DisplayAllocator* allocator;
     QLIST_HEAD(, DisplayChangeListener) listeners;
diff --git a/vl.c b/vl.c
index 34aa388..8fc63c7 100644
--- a/vl.c
+++ b/vl.c
@@ -227,7 +227,7 @@  int nb_numa_nodes;
 uint64_t node_mem[MAX_NODES];
 uint64_t node_cpumask[MAX_NODES];
 
-static QEMUTimer *nographic_timer;
+static QEMUTimer *periodic_timer;
 
 uint8_t qemu_uuid[16];
 
@@ -1041,29 +1041,24 @@  static QEMUMachine *find_default_machine(void)
 /***********************************************************/
 /* main execution loop */
 
-static void gui_update(void *opaque)
+static void periodic_update(void *opaque)
 {
     uint64_t interval = GUI_REFRESH_INTERVAL;
     DisplayState *ds = opaque;
     DisplayChangeListener *dcl;
 
     qemu_flush_coalesced_mmio_buffer();
-    dpy_refresh(ds);
 
-    QLIST_FOREACH(dcl, &ds->listeners, next) {
-        if (dcl->gui_timer_interval &&
-            dcl->gui_timer_interval < interval)
-            interval = dcl->gui_timer_interval;
+    if (ds != NULL && !QLIST_EMPTY(&ds->listeners)) {
+        dpy_refresh(ds);
+        QLIST_FOREACH(dcl, &ds->listeners, next) {
+            if (dcl->gui_timer_interval &&
+                dcl->gui_timer_interval < interval)
+                interval = dcl->gui_timer_interval;
+        }
     }
-    qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock(rt_clock));
-}
-
-static void nographic_update(void *opaque)
-{
-    uint64_t interval = GUI_REFRESH_INTERVAL;
 
-    qemu_flush_coalesced_mmio_buffer();
-    qemu_mod_timer(nographic_timer, interval + qemu_get_clock(rt_clock));
+    qemu_mod_timer(periodic_timer, interval + qemu_get_clock(rt_clock));
 }
 
 struct vm_change_state_entry {
@@ -1807,7 +1802,6 @@  int main(int argc, char **argv, char **envp)
     const char *kernel_filename, *kernel_cmdline;
     char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
     DisplayState *ds;
-    DisplayChangeListener *dcl;
     int cyls, heads, secs, translation;
     QemuOpts *hda_opts = NULL, *opts;
     int optind;
@@ -2924,18 +2918,8 @@  int main(int argc, char **argv, char **envp)
     }
     dpy_resize(ds);
 
-    QLIST_FOREACH(dcl, &ds->listeners, next) {
-        if (dcl->dpy_refresh != NULL) {
-            ds->gui_timer = qemu_new_timer(rt_clock, gui_update, ds);
-            qemu_mod_timer(ds->gui_timer, qemu_get_clock(rt_clock));
-            break;
-        }
-    }
-
-    if (display_type == DT_NOGRAPHIC || display_type == DT_VNC) {
-        nographic_timer = qemu_new_timer(rt_clock, nographic_update, NULL);
-        qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock));
-    }
+    periodic_timer = qemu_new_timer(rt_clock, periodic_update, ds);
+    qemu_mod_timer(periodic_timer, qemu_get_clock(rt_clock));
 
     text_consoles_set_display(ds);