diff --git a/cpus.c b/cpus.c index c1e74d98248..fe0b528ce89 100644 --- a/cpus.c +++ b/cpus.c @@ -211,7 +211,7 @@ static int64_t cpu_get_clock_locked(void) ticks = timers_state.cpu_clock_offset; if (timers_state.cpu_ticks_enabled) { - ticks += get_clock(); + ticks += get_virtual_clock(); } return ticks; diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 99392464a69..86d1303922a 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -825,6 +825,11 @@ static inline int64_t get_clock(void) return muldiv64(ti.QuadPart, get_ticks_per_sec(), clock_freq); } +static inline int64_t get_virtual_clock(void) +{ + return get_clock(); +} + #else extern int use_rt_clock; @@ -844,6 +849,19 @@ static inline int64_t get_clock(void) return get_clock_realtime(); } } + +static inline int64_t get_virtual_clock(void) +{ +#ifdef CLOCK_VIRTUAL + struct timespec ts; + + clock_gettime(CLOCK_VIRTUAL, &ts); + return ts.tv_sec * 1000000000LL + ts.tv_nsec; +#else + return get_clock(); +#endif +} + #endif /* icount */ diff --git a/qemu-timer.c b/qemu-timer.c index 49da1d532f5..2463fe6f6ac 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -565,7 +565,7 @@ int64_t qemu_clock_get_ns(QEMUClockType type) default: case QEMU_CLOCK_VIRTUAL: if (use_icount) { - return (cpu_get_icount() << 4) | (cpu_get_clock() & 0xful); + return cpu_get_icount(); } else { return cpu_get_clock(); }