From 7bd427d801e1e3293a634d3c83beadaa90ffb911 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 11 Mar 2011 16:47:48 +0100 Subject: change all rt_clock references to use millisecond resolution accessors This was done with: sed -i '/get_clock\>.*rt_clock/s/get_clock\>/get_clock_ms/' \ $(git grep -l 'get_clock\>.*rt_clock' ) sed -i '/new_timer\>.*rt_clock/s/new_timer\>/new_timer_ms/' \ $(git grep -l 'new_timer\>.*rt_clock' ) after checking that get_clock and new_timer never occur twice on the same line. There were no missed occurrences; however, even if there had been, they would have been caught by the compiler. Signed-off-by: Paolo Bonzini --- qemu-timer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 1939d6b..8bea74a 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -264,7 +264,7 @@ static void icount_adjust(void) static void icount_adjust_rt(void * opaque) { qemu_mod_timer(icount_rt_timer, - qemu_get_clock(rt_clock) + 1000); + qemu_get_clock_ms(rt_clock) + 1000); icount_adjust(); } @@ -601,9 +601,9 @@ void configure_icount(const char *option) the virtual time trigger catches emulated time passing too fast. Realtime triggers occur even when idle, so use them less frequently than VM triggers. */ - icount_rt_timer = qemu_new_timer(rt_clock, icount_adjust_rt, NULL); + icount_rt_timer = qemu_new_timer_ms(rt_clock, icount_adjust_rt, NULL); qemu_mod_timer(icount_rt_timer, - qemu_get_clock(rt_clock) + 1000); + qemu_get_clock_ms(rt_clock) + 1000); icount_vm_timer = qemu_new_timer(vm_clock, icount_adjust_vm, NULL); qemu_mod_timer(icount_vm_timer, qemu_get_clock(vm_clock) + get_ticks_per_sec() / 10); -- cgit v1.1 From 74475455442398a64355428b37422d14ccc293cb Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 11 Mar 2011 16:47:48 +0100 Subject: change all other clock references to use nanosecond resolution accessors This was done with: sed -i 's/qemu_get_clock\>/qemu_get_clock_ns/' \ $(git grep -l 'qemu_get_clock\>' ) sed -i 's/qemu_new_timer\>/qemu_new_timer_ns/' \ $(git grep -l 'qemu_new_timer\>' ) after checking that get_clock and new_timer never occur twice on the same line. There were no missed occurrences; however, even if there had been, they would have been caught by the compiler. There was exactly one false positive in qemu_run_timers: - current_time = qemu_get_clock (clock); + current_time = qemu_get_clock_ns (clock); which is of course not in this patch. Signed-off-by: Paolo Bonzini --- qemu-timer.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 8bea74a..bc818ae 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -242,7 +242,7 @@ static void icount_adjust(void) return; cur_time = cpu_get_clock(); - cur_icount = qemu_get_clock(vm_clock); + cur_icount = qemu_get_clock_ns(vm_clock); delta = cur_icount - cur_time; /* FIXME: This is a very crude algorithm, somewhat prone to oscillation. */ if (delta > 0 @@ -271,7 +271,7 @@ static void icount_adjust_rt(void * opaque) static void icount_adjust_vm(void * opaque) { qemu_mod_timer(icount_vm_timer, - qemu_get_clock(vm_clock) + get_ticks_per_sec() / 10); + qemu_get_clock_ns(vm_clock) + get_ticks_per_sec() / 10); icount_adjust(); } @@ -604,9 +604,9 @@ void configure_icount(const char *option) icount_rt_timer = qemu_new_timer_ms(rt_clock, icount_adjust_rt, NULL); qemu_mod_timer(icount_rt_timer, qemu_get_clock_ms(rt_clock) + 1000); - icount_vm_timer = qemu_new_timer(vm_clock, icount_adjust_vm, NULL); + icount_vm_timer = qemu_new_timer_ns(vm_clock, icount_adjust_vm, NULL); qemu_mod_timer(icount_vm_timer, - qemu_get_clock(vm_clock) + get_ticks_per_sec() / 10); + qemu_get_clock_ns(vm_clock) + get_ticks_per_sec() / 10); } void qemu_run_all_timers(void) @@ -646,7 +646,7 @@ static void host_alarm_handler(int host_signum) static int64_t delta_min = INT64_MAX; static int64_t delta_max, delta_cum, last_clock, delta, ti; static int count; - ti = qemu_get_clock(vm_clock); + ti = qemu_get_clock_ns(vm_clock); if (last_clock != 0) { delta = ti - last_clock; if (delta < delta_min) @@ -706,7 +706,7 @@ static int64_t qemu_next_alarm_deadline(void) if (!use_icount && active_timers[QEMU_CLOCK_VIRTUAL]) { delta = active_timers[QEMU_CLOCK_VIRTUAL]->expire_time - - qemu_get_clock(vm_clock); + qemu_get_clock_ns(vm_clock); } else { delta = INT32_MAX; } -- cgit v1.1 From 4a998740b22aa673ea475060c787da7c545588cf Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 11 Mar 2011 16:33:58 +0100 Subject: add a generic scaling mechanism for timers 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 --- qemu-timer.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index bc818ae..ec8b446 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; @@ -386,7 +386,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; @@ -394,6 +395,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; } @@ -424,7 +426,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; @@ -457,6 +459,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; @@ -471,7 +480,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) @@ -482,7 +491,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; @@ -559,7 +568,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); } @@ -717,7 +726,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; -- cgit v1.1 From 6d5ad9bf9318b1555d5567cd7e1760a51a55ebf8 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 11 Mar 2011 18:27:26 +0100 Subject: remove qemu_get_clock These patches are already not doing a great service to out-of-tree modifications to QEMU. However, at least we can warn them by getting rid of the old confusing functions, or otherwise causing compilation errors. This patch removes qemu_get_clock; the previous one changed qemu_new_timer's signature. Signed-off-by: Paolo Bonzini --- qemu-timer.c | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index ec8b446..50f1943 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -506,23 +506,6 @@ static void qemu_run_timers(QEMUClock *clock) } } -int64_t qemu_get_clock(QEMUClock *clock) -{ - switch(clock->type) { - case QEMU_CLOCK_REALTIME: - return get_clock() / 1000000; - default: - case QEMU_CLOCK_VIRTUAL: - if (use_icount) { - return cpu_get_icount(); - } else { - return cpu_get_clock(); - } - case QEMU_CLOCK_HOST: - return get_clock_realtime(); - } -} - int64_t qemu_get_clock_ns(QEMUClock *clock) { switch(clock->type) { -- cgit v1.1