From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [RFC PATCH 4/5] add a generic scaling mechanism for timers
Date: Sat, 12 Mar 2011 18:04:19 +0100 [thread overview]
Message-ID: <1299949460-4387-5-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1299949460-4387-1-git-send-email-pbonzini@redhat.com>
This enables rt_clock timers to use nanosecond resolution, just by
using the _ns functions; there is really no reason to forbid that.
Migrated timers are all using vm_clock (of course; but I checked that
anyway) so the timers in the savevm files are already in nanosecond
resolution. So this patch makes no change to the migration format.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
qemu-timer.c | 25 +++++++++++++++++--------
qemu-timer.h | 9 ++++-----
2 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/qemu-timer.c b/qemu-timer.c
index f171e9c..1aed535 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -153,12 +153,12 @@ void cpu_disable_ticks(void)
struct QEMUClock {
int type;
int enabled;
- /* XXX: add frequency */
};
struct QEMUTimer {
QEMUClock *clock;
- int64_t expire_time;
+ int64_t expire_time; /* in nanoseconds */
+ int scale;
QEMUTimerCB *cb;
void *opaque;
struct QEMUTimer *next;
@@ -391,7 +391,8 @@ void qemu_clock_enable(QEMUClock *clock, int enabled)
clock->enabled = enabled;
}
-QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque)
+QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale,
+ QEMUTimerCB *cb, void *opaque)
{
QEMUTimer *ts;
@@ -399,6 +400,7 @@ QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque)
ts->clock = clock;
ts->cb = cb;
ts->opaque = opaque;
+ ts->scale = scale;
return ts;
}
@@ -429,7 +431,7 @@ void qemu_del_timer(QEMUTimer *ts)
/* modify the current timer so that it will be fired when current_time
>= expire_time. The corresponding callback will be called. */
-void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time)
+static void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time)
{
QEMUTimer **pt, *t;
@@ -462,6 +464,13 @@ void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time)
}
}
+/* modify the current timer so that it will be fired when current_time
+ >= expire_time. The corresponding callback will be called. */
+void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time)
+{
+ qemu_mod_timer_ns(ts, expire_time * ts->scale);
+}
+
int qemu_timer_pending(QEMUTimer *ts)
{
QEMUTimer *t;
@@ -476,7 +485,7 @@ int qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time)
{
if (!timer_head)
return 0;
- return (timer_head->expire_time <= current_time);
+ return (timer_head->expire_time <= current_time * timer_head->scale);
}
static void qemu_run_timers(QEMUClock *clock)
@@ -487,7 +496,7 @@ static void qemu_run_timers(QEMUClock *clock)
if (!clock->enabled)
return;
- current_time = qemu_get_clock (clock);
+ current_time = qemu_get_clock_ns(clock);
ptimer_head = &active_timers[clock->type];
for(;;) {
ts = *ptimer_head;
@@ -564,7 +573,7 @@ void qemu_get_timer(QEMUFile *f, QEMUTimer *ts)
expire_time = qemu_get_be64(f);
if (expire_time != -1) {
- qemu_mod_timer(ts, expire_time);
+ qemu_mod_timer_ns(ts, expire_time);
} else {
qemu_del_timer(ts);
}
@@ -724,7 +733,7 @@ static int64_t qemu_next_alarm_deadline(void)
delta = hdelta;
}
if (active_timers[QEMU_CLOCK_REALTIME]) {
- rtdelta = (active_timers[QEMU_CLOCK_REALTIME]->expire_time * 1000000 -
+ rtdelta = (active_timers[QEMU_CLOCK_REALTIME]->expire_time -
qemu_get_clock_ns(rt_clock));
if (rtdelta < delta)
delta = rtdelta;
diff --git a/qemu-timer.h b/qemu-timer.h
index 345feea..0ea77fb 100644
--- a/qemu-timer.h
+++ b/qemu-timer.h
@@ -41,7 +41,8 @@ int64_t qemu_get_clock(QEMUClock *clock);
int64_t qemu_get_clock_ns(QEMUClock *clock);
void qemu_clock_enable(QEMUClock *clock, int enabled);
-QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque);
+QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale,
+ QEMUTimerCB *cb, void *opaque);
void qemu_free_timer(QEMUTimer *ts);
void qemu_del_timer(QEMUTimer *ts);
void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
@@ -61,15 +62,13 @@ void quit_timers(void);
static inline QEMUTimer *qemu_new_timer_ns(QEMUClock *clock, QEMUTimerCB *cb,
void *opaque)
{
- assert(clock != rt_clock);
- return qemu_new_timer(clock, cb, opaque);
+ return qemu_new_timer(clock, SCALE_NS, cb, opaque);
}
static inline QEMUTimer *qemu_new_timer_ms(QEMUClock *clock, QEMUTimerCB *cb,
void *opaque)
{
- assert(clock == rt_clock);
- return qemu_new_timer(clock, cb, opaque);
+ return qemu_new_timer(clock, SCALE_MS, cb, opaque);
}
static inline int64_t qemu_get_clock_ms(QEMUClock *clock)
--
1.7.4
next prev parent reply other threads:[~2011-03-12 17:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-12 17:04 [Qemu-devel] [RFC PATCH 0/5] allow arbitrary scaling of timers Paolo Bonzini
2011-03-12 17:04 ` [Qemu-devel] [RFC PATCH 1/5] add more helper functions with explicit milli/nanosecond resolution Paolo Bonzini
2011-03-12 17:04 ` [Qemu-devel] [RFC PATCH 2/5] change all rt_clock references to use millisecond resolution accessors Paolo Bonzini
2011-03-12 17:04 ` [Qemu-devel] [RFC PATCH 3/5] change all other clock references to use nanosecond " Paolo Bonzini
2011-03-12 17:04 ` Paolo Bonzini [this message]
2011-03-12 17:04 ` [Qemu-devel] [RFC PATCH 5/5] remove qemu_get_clock Paolo Bonzini
2011-03-12 23:33 ` [Qemu-devel] [RFC PATCH 0/5] allow arbitrary scaling of timers Anthony Liguori
2011-03-14 7:14 ` Paolo Bonzini
2011-03-21 13:35 ` [Qemu-devel] [PULL] " Paolo Bonzini
2011-03-21 20:44 ` Aurelien Jarno
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=1299949460-4387-5-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).