qemu-timer: more clock functions

These will be used when moving icount accounting to cpus.c.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2011-09-12 15:50:16 +02:00
parent f3fc6e2e96
commit dc2dfcf000
2 changed files with 28 additions and 0 deletions

View File

@ -495,6 +495,31 @@ void qemu_clock_warp(QEMUClock *clock)
} }
} }
int64_t qemu_clock_has_timers(QEMUClock *clock)
{
return !!clock->active_timers;
}
int64_t qemu_clock_expired(QEMUClock *clock)
{
return (clock->active_timers &&
clock->active_timers->expire_time < qemu_get_clock_ns(clock));
}
int64_t qemu_clock_deadline(QEMUClock *clock)
{
/* To avoid problems with overflow limit this to 2^32. */
int64_t delta = INT32_MAX;
if (clock->active_timers) {
delta = clock->active_timers->expire_time - qemu_get_clock_ns(clock);
}
if (delta < 0) {
delta = 0;
}
return delta;
}
QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale, QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale,
QEMUTimerCB *cb, void *opaque) QEMUTimerCB *cb, void *opaque)
{ {

View File

@ -38,6 +38,9 @@ extern QEMUClock *vm_clock;
extern QEMUClock *host_clock; extern QEMUClock *host_clock;
int64_t qemu_get_clock_ns(QEMUClock *clock); int64_t qemu_get_clock_ns(QEMUClock *clock);
int64_t qemu_clock_has_timers(QEMUClock *clock);
int64_t qemu_clock_expired(QEMUClock *clock);
int64_t qemu_clock_deadline(QEMUClock *clock);
void qemu_clock_enable(QEMUClock *clock, int enabled); void qemu_clock_enable(QEMUClock *clock, int enabled);
void qemu_clock_warp(QEMUClock *clock); void qemu_clock_warp(QEMUClock *clock);