From: Liu Ping Fan <qemulist@gmail.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Jan Kiszka <jan.kiszka@siemens.com>,
Alex Bligh <alex@alex.org.uk>,
Anthony Liguori <anthony@codemonkey.ws>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [RFC v2 5/5] timer: run timers on aio_poll
Date: Mon, 29 Jul 2013 11:16:08 +0800 [thread overview]
Message-ID: <1375067768-11342-6-git-send-email-pingfank@linux.vnet.ibm.com> (raw)
In-Reply-To: <1375067768-11342-1-git-send-email-pingfank@linux.vnet.ibm.com>
Stop call timers in main loop and let each mini event-loop
run its own timers.
Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
---
aio-posix.c | 2 ++
include/qemu/timer.h | 4 ++--
main-loop.c | 2 --
qemu-timer.c | 15 ++++++++++-----
4 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/aio-posix.c b/aio-posix.c
index b68eccd..53fdb1a 100644
--- a/aio-posix.c
+++ b/aio-posix.c
@@ -191,6 +191,8 @@ bool aio_poll(AioContext *ctx, bool blocking)
progress = true;
}
+ progress |= qemu_run_all_timers();
+
if (progress && !blocking) {
return true;
}
diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index 3e5016b..9ff8a68 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -61,8 +61,8 @@ bool qemu_timer_pending(QEMUTimer *ts);
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);
+bool qemu_run_timers(QEMUClock *clock);
+bool qemu_run_all_timers(void);
void configure_alarms(char const *opt);
void init_clocks(void);
int init_timer_alarm(void);
diff --git a/main-loop.c b/main-loop.c
index 5fbdd4a..0214ed6 100644
--- a/main-loop.c
+++ b/main-loop.c
@@ -471,8 +471,6 @@ int main_loop_wait(int nonblocking)
slirp_pollfds_poll(gpollfds, (ret < 0));
#endif
- qemu_run_all_timers();
-
return ret;
}
diff --git a/qemu-timer.c b/qemu-timer.c
index f15c3e6..8331e18 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -463,12 +463,13 @@ bool qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time)
return qemu_timer_expired_ns(timer_head, current_time * timer_head->scale);
}
-void qemu_run_timers(QEMUClock *clock)
+bool qemu_run_timers(QEMUClock *clock)
{
QEMUTimer *ts;
int64_t current_time;
TimerList *tlist;
AioContext *ctx;
+ bool process = false;
atomic_inc(&clock->using);
if (unlikely(!clock->enabled)) {
@@ -494,6 +495,7 @@ void qemu_run_timers(QEMUClock *clock)
/* run the callback (the timer list can be modified) */
ts->cb(ts->opaque);
+ process = true;
}
exit:
@@ -504,6 +506,7 @@ exit:
}
}
qemu_mutex_unlock(&clock->lock);
+ return process;
}
int64_t qemu_get_clock_ns(QEMUClock *clock)
@@ -555,16 +558,17 @@ uint64_t qemu_timer_expire_time_ns(QEMUTimer *ts)
return qemu_timer_pending(ts) ? ts->expire_time : -1;
}
-void qemu_run_all_timers(void)
+bool qemu_run_all_timers(void)
{
bool timer_modified;
+ bool process = false;
alarm_timer->pending = false;
/* vm time timers */
- qemu_run_timers(vm_clock);
- qemu_run_timers(rt_clock);
- qemu_run_timers(host_clock);
+ process |= qemu_run_timers(vm_clock);
+ process |= qemu_run_timers(rt_clock);
+ process |= qemu_run_timers(host_clock);
/* Check if qemu_mod_timer_ns() has been called */
qemu_mutex_lock(&alarm_timer->timer_modified_lock);
@@ -580,6 +584,7 @@ void qemu_run_all_timers(void)
qemu_rearm_alarm_timer(alarm_timer);
}
+ return process;
}
#ifdef _WIN32
--
1.8.1.4
next prev parent reply other threads:[~2013-07-29 3:19 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-29 3:16 [Qemu-devel] [RFC v2 0/5] arm AioContext with its own timer stuff Liu Ping Fan
2013-07-29 3:16 ` [Qemu-devel] [RFC v2 1/5] timer: protect timers_state with lock Liu Ping Fan
2013-07-29 6:26 ` Paolo Bonzini
2013-07-29 8:01 ` liu ping fan
2013-07-29 3:16 ` [Qemu-devel] [RFC v2 2/5] timer: pick out timer list info from QemuClock Liu Ping Fan
2013-07-29 3:16 ` [Qemu-devel] [RFC v2 3/5] timer: make qemu_clock_enable sync between disable and timer's cb Liu Ping Fan
2013-07-29 6:30 ` Paolo Bonzini
2013-07-29 8:10 ` liu ping fan
2013-07-29 11:21 ` Paolo Bonzini
2013-07-30 2:42 ` liu ping fan
2013-07-30 9:17 ` Paolo Bonzini
2013-07-30 9:51 ` Alex Bligh
2013-07-30 10:12 ` Paolo Bonzini
2013-08-01 5:54 ` liu ping fan
2013-08-01 8:57 ` Paolo Bonzini
2013-08-01 9:35 ` Alex Bligh
2013-08-01 12:19 ` Paolo Bonzini
2013-08-01 13:28 ` Alex Bligh
2013-08-01 13:51 ` Paolo Bonzini
2013-08-01 14:20 ` Alex Bligh
2013-08-01 14:28 ` Paolo Bonzini
2013-08-02 3:31 ` liu ping fan
2013-08-02 10:01 ` Paolo Bonzini
2013-08-02 3:33 ` liu ping fan
2013-08-02 14:43 ` Stefan Hajnoczi
2013-08-05 2:13 ` liu ping fan
2013-07-29 3:16 ` [Qemu-devel] [RFC v2 4/5] timer: associate three timerlists with AioContext Liu Ping Fan
2013-07-29 6:32 ` Paolo Bonzini
2013-07-29 8:20 ` liu ping fan
2013-07-29 13:11 ` Paolo Bonzini
2013-07-30 2:35 ` liu ping fan
2013-07-29 3:16 ` Liu Ping Fan [this message]
2013-07-29 9:22 ` [Qemu-devel] [RFC v2 0/5] arm AioContext with its own timer stuff Stefan Hajnoczi
2013-07-29 10:23 ` Alex Bligh
2013-07-29 13:36 ` Stefan Hajnoczi
2013-07-29 13:56 ` Alex Bligh
2013-07-30 3:35 ` liu ping fan
2013-07-29 10:18 ` Alex Bligh
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=1375067768-11342-6-git-send-email-pingfank@linux.vnet.ibm.com \
--to=qemulist@gmail.com \
--cc=alex@alex.org.uk \
--cc=anthony@codemonkey.ws \
--cc=jan.kiszka@siemens.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).