]> git.proxmox.com Git - qemu.git/commitdiff
main-loop: For tools, initialize timers as part of qemu_init_main_loop()
authorMichael Roth <mdroth@linux.vnet.ibm.com>
Sat, 21 Jan 2012 17:13:53 +0000 (11:13 -0600)
committerAnthony Liguori <aliguori@us.ibm.com>
Wed, 1 Feb 2012 20:45:02 +0000 (14:45 -0600)
In some cases initializing the alarm timers can lead to non-negligable
overhead from programs that link against qemu-tool.o. At least,
setting a max-resolution WinMM alarm timer via mm_start_timer() (the
current default for Windows) can increase the "tick rate" on Windows
OSs and affect frequency scaling, and in the case of tools that run
in guest OSs such has qemu-ga, the impact can be fairly dramatic
(+20%/20% user/sys time on a core 2 processor was observed from an idle
Windows XP guest).

This patch doesn't address the issue directly (not sure what a good
solution would be for Windows, or what other situations it might be
noticeable), but it at least limits the scope of the issue to programs
that "opt-in" to using the main-loop.c functions by only enabling alarm
timers when qemu_init_main_loop() is called, which is already required
to make use of those facilities, so existing users shouldn't be
affected.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
main-loop.c
main-loop.h
qemu-tool.c
vl.c

index 62d95b96379e9c3cf265bf89308a1cb4229b732d..db23de04971ddf3dbafaa89c796227d7ce0fe652 100644 (file)
@@ -199,7 +199,7 @@ static int qemu_signal_init(void)
 }
 #endif
 
-int qemu_init_main_loop(void)
+int main_loop_init(void)
 {
     int ret;
 
index f9710136c9f582c93206b87acdedce95cb685d59..4987041ce7e487952d47ccfb70c4a5c97c3b9c07 100644 (file)
  * SIGUSR2, thread signals (SIGFPE, SIGILL, SIGSEGV, SIGBUS) and real-time
  * signals if available.  Remember that Windows in practice does not have
  * signals, though.
+ *
+ * In the case of QEMU tools, this will also start/initialize timers.
  */
 int qemu_init_main_loop(void);
 
+/**
+ * main_loop_init: Initializes main loop
+ *
+ * Internal (but shared for compatibility reasons) initialization routine
+ * for the main loop. This should not be used by applications directly,
+ * use qemu_init_main_loop() instead.
+ *
+ */
+int main_loop_init(void);
+
 /**
  * main_loop_wait: Run one iteration of the main loop.
  *
index 6b69668258da748f25536bc3c1d5c06a2b017768..183a583fec262c8c4f8663ff26067e7a481d5a74 100644 (file)
@@ -83,11 +83,12 @@ void qemu_clock_warp(QEMUClock *clock)
 {
 }
 
-static void __attribute__((constructor)) init_main_loop(void)
+int qemu_init_main_loop(void)
 {
     init_clocks();
     init_timer_alarm();
     qemu_clock_enable(vm_clock, false);
+    return main_loop_init();
 }
 
 void slirp_select_fill(int *pnfds, fd_set *readfds,
diff --git a/vl.c b/vl.c
index 138f6bc1ef1053a6b02d27c00d387a8d18c37bb5..2d464cf65c611dea7593dce907bf4d804794be0f 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -2167,6 +2167,11 @@ static void free_and_trace(gpointer mem)
     free(mem);
 }
 
+int qemu_init_main_loop(void)
+{
+    return main_loop_init();
+}
+
 int main(int argc, char **argv, char **envp)
 {
     const char *gdbstub_dev = NULL;