From de188751da8db3c77a681bf903035a0e5218c463 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 3 Sep 2012 17:34:32 +0200 Subject: qemu-timer: properly arm alarm timer for timers set by device initialization QEMU will hang when fed the following command-line qemu-system-mips -kernel vmlinux-2.6.32-5-4kc-malta -append "console=ttyS0" -nographic -net none The -net none is important otherwise it seems some events are generated causing the things to work. When it doesn't work, the guest hangs when measuring the CPU frequency, after the following line: [ 0.000000] NR_IRQS:256 Pressing a key on the serial port unblocks it, hinting that the problem is due to the recent elimination of the 1 second timeout in the main loop. The problem is that because init_timer_alarm sets the timer's pending flag to true, the alarm timer is never armed until after the first time through the main loop. Thus the bug started when QEMU started testing the pending flag in qemu_mod_timer (commit 1828be3, more alarm timer cleanup, 2010-03-10). But actually, it isn't true at all that a timer is pending when the alarm timer is created, and the real bug has been latent forever: the fix is to remove the bogus setting of pending flag. Reported-by: Aurelien Jarno Signed-off-by: Paolo Bonzini Reviewed-by: Jan Kiszka Tested-by: Aurelien Jarno Tested-by: Michael Tokarev Signed-off-by: Aurelien Jarno --- qemu-timer.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 5aea94e..c7a1551 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -759,11 +759,8 @@ int init_timer_alarm(void) goto fail; } - /* first event is at time 0 */ atexit(quit_timers); - t->pending = true; alarm_timer = t; - return 0; fail: -- cgit v1.1 From 144b97c26cdef7fecd62dae2db6ce312cd493751 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 19 Sep 2012 15:52:44 +0200 Subject: qemu-timer: simplify qemu_run_timers ptimer_head is an invariant pointer to clock->active_timers. Remove it, and just reference clock->active_timers directly. Signed-off-by: Paolo Bonzini Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index c7a1551..908a103 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -372,21 +372,20 @@ bool qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time) void qemu_run_timers(QEMUClock *clock) { - QEMUTimer **ptimer_head, *ts; + QEMUTimer *ts; int64_t current_time; if (!clock->enabled) return; current_time = qemu_get_clock_ns(clock); - ptimer_head = &clock->active_timers; for(;;) { - ts = *ptimer_head; + ts = clock->active_timers; if (!qemu_timer_expired_ns(ts, current_time)) { break; } /* remove timer from the list before calling the callback */ - *ptimer_head = ts->next; + clock->active_timers = ts->next; ts->next = NULL; /* run the callback (the timer list can be modified) */ -- cgit v1.1 From 1e9737da4aafb54681203931dfe8f8eea21fcef7 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Tue, 23 Oct 2012 07:33:00 +1000 Subject: qemu-timer: Check for usable fields for SIGEV_THREAD_ID Older glibc (RHEL 5.x, Debian 5.x) does not have the _sigev_un._tid member in its structure definition, while the accompanying kernel headers do define SIGEV_THREAD_ID. We need configure to check for both before using it. Signed-off-by: Richard Henderson Signed-off-by: Aurelien Jarno --- qemu-timer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 908a103..ede84ff 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -494,12 +494,12 @@ static int dynticks_start_timer(struct qemu_alarm_timer *t) memset(&ev, 0, sizeof(ev)); ev.sigev_value.sival_int = 0; ev.sigev_notify = SIGEV_SIGNAL; -#ifdef SIGEV_THREAD_ID +#ifdef CONFIG_SIGEV_THREAD_ID if (qemu_signalfd_available()) { ev.sigev_notify = SIGEV_THREAD_ID; ev._sigev_un._tid = qemu_get_thread_id(); } -#endif /* SIGEV_THREAD_ID */ +#endif /* CONFIG_SIGEV_THREAD_ID */ ev.sigev_signo = SIGALRM; if (timer_create(CLOCK_REALTIME, &ev, &host_timer)) { -- cgit v1.1 From 744ca8e3754e6808c6b5331d287adc533fca0ad3 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 29 Oct 2012 15:26:28 +0100 Subject: qemu-timer: make initialization functions idempotent Signed-off-by: Paolo Bonzini --- qemu-timer.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 908a103..b71e9a6 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -430,9 +430,11 @@ void qemu_unregister_clock_reset_notifier(QEMUClock *clock, Notifier *notifier) void init_clocks(void) { - rt_clock = qemu_new_clock(QEMU_CLOCK_REALTIME); - vm_clock = qemu_new_clock(QEMU_CLOCK_VIRTUAL); - host_clock = qemu_new_clock(QEMU_CLOCK_HOST); + if (!rt_clock) { + rt_clock = qemu_new_clock(QEMU_CLOCK_REALTIME); + vm_clock = qemu_new_clock(QEMU_CLOCK_VIRTUAL); + host_clock = qemu_new_clock(QEMU_CLOCK_HOST); + } } uint64_t qemu_timer_expire_time_ns(QEMUTimer *ts) @@ -745,6 +747,10 @@ int init_timer_alarm(void) struct qemu_alarm_timer *t = NULL; int i, err = -1; + if (alarm_timer) { + return 0; + } + for (i = 0; alarm_timers[i].name; i++) { t = &alarm_timers[i]; -- cgit v1.1 From c8122c35e611385b31e2d8ccb059d0687540244a Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 2 Nov 2012 15:43:22 +0100 Subject: qemu-timer: reinitialize timers after fork Timers are not inherited by the child of a fork(2), so just use pthread_atfork to reinstate them after daemonize. Signed-off-by: Paolo Bonzini Signed-off-by: Anthony Liguori --- qemu-timer.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index f3426c9..7b2217a 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -742,6 +742,17 @@ static void quit_timers(void) t->stop(t); } +static void reinit_timers(void) +{ + struct qemu_alarm_timer *t = alarm_timer; + t->stop(t); + if (t->start(t)) { + fprintf(stderr, "Internal timer error: aborting\n"); + exit(1); + } + qemu_rearm_alarm_timer(t); +} + int init_timer_alarm(void) { struct qemu_alarm_timer *t = NULL; @@ -765,6 +776,9 @@ int init_timer_alarm(void) } atexit(quit_timers); +#ifdef CONFIG_POSIX + pthread_atfork(NULL, NULL, reinit_timers); +#endif alarm_timer = t; return 0; -- cgit v1.1 From 30ea833941a7de51454cf99913f5edb3e7e21c0d Mon Sep 17 00:00:00 2001 From: Anthony Liguori Date: Fri, 2 Nov 2012 16:12:53 -0500 Subject: build: pthread_atfork() needs include of pthread.h Cc: Paolo Bonzini Signed-off-by: Anthony Liguori --- qemu-timer.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 7b2217a..8d9cf38 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -30,6 +30,9 @@ #include "hw/hw.h" #include "qemu-timer.h" +#ifdef CONFIG_POSIX +#include +#endif #ifdef _WIN32 #include -- cgit v1.1 From 253ecf83bcc658316bab3250401943d9b44c7898 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sun, 4 Nov 2012 21:42:08 +0100 Subject: qemu-timer: Fix compilation for non-POSIX hosts A compiler warning is caused by the unused local function reinit_timers on non-POSIX hosts. Include that function only for POSIX hosts. Signed-off-by: Stefan Weil Signed-off-by: Blue Swirl --- qemu-timer.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 8d9cf38..0d2bb94 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -745,6 +745,7 @@ static void quit_timers(void) t->stop(t); } +#ifdef CONFIG_POSIX static void reinit_timers(void) { struct qemu_alarm_timer *t = alarm_timer; @@ -755,6 +756,7 @@ static void reinit_timers(void) } qemu_rearm_alarm_timer(t); } +#endif /* CONFIG_POSIX */ int init_timer_alarm(void) { -- cgit v1.1 From 7fa22f2bf7a06d5345283a00a7c6d86b8a345228 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 24 Oct 2012 09:36:33 +0200 Subject: net: do not include net.h everywhere Signed-off-by: Paolo Bonzini --- qemu-timer.c | 1 - 1 file changed, 1 deletion(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 0d2bb94..9b9585b 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -23,7 +23,6 @@ */ #include "sysemu.h" -#include "net.h" #include "monitor.h" #include "console.h" -- cgit v1.1 From 28ecbaeecb139a214f019207402a35d7b58aec0f Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 28 Nov 2012 12:06:30 +0100 Subject: ui: move files to ui/ and include/ui/ Signed-off-by: Paolo Bonzini --- qemu-timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 9b9585b..5a99403 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -24,7 +24,7 @@ #include "sysemu.h" #include "monitor.h" -#include "console.h" +#include "ui/console.h" #include "hw/hw.h" -- cgit v1.1 From 83c9089e73b81c69dc1ecdf859fa84d2c500fb5f Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 17 Dec 2012 18:19:49 +0100 Subject: monitor: move include files to include/monitor/ Signed-off-by: Paolo Bonzini --- qemu-timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 5a99403..8e0dccc 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -23,7 +23,7 @@ */ #include "sysemu.h" -#include "monitor.h" +#include "monitor/monitor.h" #include "ui/console.h" #include "hw/hw.h" -- cgit v1.1 From 1de7afc984b49af164e2619e6850b9732b173b34 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 17 Dec 2012 18:20:00 +0100 Subject: misc: move include files to include/qemu/ Signed-off-by: Paolo Bonzini --- qemu-timer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 8e0dccc..80b3f2e 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -28,7 +28,7 @@ #include "hw/hw.h" -#include "qemu-timer.h" +#include "qemu/timer.h" #ifdef CONFIG_POSIX #include #endif @@ -477,7 +477,7 @@ static void host_alarm_handler(int host_signum) #if defined(__linux__) -#include "compatfd.h" +#include "qemu/compatfd.h" static int dynticks_start_timer(struct qemu_alarm_timer *t) { -- cgit v1.1 From 9c17d615a66ebd655871bf891ec0fe901ad8b332 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 17 Dec 2012 18:20:04 +0100 Subject: softmmu: move include files to include/sysemu/ Signed-off-by: Paolo Bonzini --- qemu-timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 80b3f2e..8fb5c75 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -22,7 +22,7 @@ * THE SOFTWARE. */ -#include "sysemu.h" +#include "sysemu/sysemu.h" #include "monitor/monitor.h" #include "ui/console.h" -- cgit v1.1