From: Jan Kiszka <jan.kiszka@siemens.com>
To: qemu-devel <qemu-devel@nongnu.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>, Stefan Weil <weil@mail.berlios.de>
Subject: [Qemu-devel] [RFC][PATCH] qemu-timer: Run timers in alarm timer handler
Date: Thu, 23 Aug 2012 13:23:37 +0200 [thread overview]
Message-ID: <503612B9.1070601@siemens.com> (raw)
No need for this indirection via qemu_notify_event. On Unix, we already
catch SIGALRM via signalfd (or its emulation) and run the handler
synchronously. Under Win32, handlers run in separate threads. So we just
need to grab the global lock around the handler execution.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
The Unix side looks safe to me, but I'm not yet 100% confident about
Win32. This is part of an ongoing effort to create separate alarm
timers over their own io-threads. A lengthy effort. But these bits
appear useful to me already.
main-loop.c | 2 --
qemu-timer.c | 21 +++++++++++++--------
qemu-timer.h | 1 -
3 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/main-loop.c b/main-loop.c
index eb3b6e6..1a6ea25 100644
--- a/main-loop.c
+++ b/main-loop.c
@@ -499,8 +499,6 @@ int main_loop_wait(int nonblocking)
slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0));
#endif
- qemu_run_all_timers();
-
/* Check bottom-halves last in case any of the earlier events triggered
them. */
qemu_bh_poll();
diff --git a/qemu-timer.c b/qemu-timer.c
index 5aea94e..26411a2 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -441,7 +441,7 @@ uint64_t qemu_timer_expire_time_ns(QEMUTimer *ts)
return qemu_timer_pending(ts) ? ts->expire_time : -1;
}
-void qemu_run_all_timers(void)
+static void qemu_run_all_timers(void)
{
alarm_timer->pending = false;
@@ -457,11 +457,7 @@ void qemu_run_all_timers(void)
}
}
-#ifdef _WIN32
-static void CALLBACK host_alarm_handler(PVOID lpParam, BOOLEAN unused)
-#else
static void host_alarm_handler(int host_signum)
-#endif
{
struct qemu_alarm_timer *t = alarm_timer;
if (!t)
@@ -469,7 +465,7 @@ static void host_alarm_handler(int host_signum)
t->expired = true;
t->pending = true;
- qemu_notify_event();
+ qemu_run_all_timers();
}
#if defined(__linux__)
@@ -613,9 +609,11 @@ static void CALLBACK mm_alarm_handler(UINT uTimerID, UINT uMsg,
if (!t) {
return;
}
+ qemu_mutex_lock_iothread();
t->expired = true;
t->pending = true;
- qemu_notify_event();
+ qemu_run_all_timers();
+ qemu_mutex_unlock_iothread();
}
static int mm_start_timer(struct qemu_alarm_timer *t)
@@ -668,6 +666,13 @@ static void mm_rearm_timer(struct qemu_alarm_timer *t, int64_t delta)
}
}
+static void CALLBACK win32_alarm_handler(PVOID lpParam, BOOLEAN unused)
+{
+ qemu_mutex_lock_iothread();
+ host_alarm_handler(0);
+ qemu_mutex_unlock_iothread();
+}
+
static int win32_start_timer(struct qemu_alarm_timer *t)
{
HANDLE hTimer;
@@ -679,7 +684,7 @@ static int win32_start_timer(struct qemu_alarm_timer *t)
interval in the dynticks case. */
success = CreateTimerQueueTimer(&hTimer,
NULL,
- host_alarm_handler,
+ win32_alarm_handler,
t,
1,
3600000,
diff --git a/qemu-timer.h b/qemu-timer.h
index f8af595..b9bf313 100644
--- a/qemu-timer.h
+++ b/qemu-timer.h
@@ -58,7 +58,6 @@ bool qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time);
uint64_t qemu_timer_expire_time_ns(QEMUTimer *ts);
void qemu_run_timers(QEMUClock *clock);
-void qemu_run_all_timers(void);
void configure_alarms(char const *opt);
void init_clocks(void);
int init_timer_alarm(void);
--
1.7.3.4
next reply other threads:[~2012-08-23 11:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-23 11:23 Jan Kiszka [this message]
2012-08-23 11:39 ` [Qemu-devel] [RFC][PATCH] qemu-timer: Run timers in alarm timer handler Paolo Bonzini
2012-08-23 12:10 ` Jan Kiszka
2012-08-23 12:24 ` Paolo Bonzini
2012-08-23 13:01 ` Jan Kiszka
2012-08-23 13:11 ` Paolo Bonzini
2012-08-23 18:09 ` Jan Kiszka
2012-08-24 7:45 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=503612B9.1070601@siemens.com \
--to=jan.kiszka@siemens.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=weil@mail.berlios.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.