Fix qemu hang when i386 Linux host resumes from suspend
PATCH 1/1 Fix qemu hang when i386 Linux host resumes from suspend
qemu hangs when an i386 Linux host resumes from suspend (swsusp2), because the host's TSC is reset to a value lower than it was before the suspend.
Although this is a bug in the host OS, the attached patch (originally from John Coiner) is simple and makes qemu more resilient to weird host tick counter behavior.
--Ed
vl.c +10 -3
@@ -579,14 +579,21 @@#error unsupported CPU#endif -static int64_t cpu_ticks_offset; -static int cpu_ticks_enabled; +static int64_t cpu_ticks_prev; +static int64_t cpu_ticks_offset; +static int cpu_ticks_enabled;static inline int64_t cpu_get_ticks (void ) {if (!cpu_ticks_enabled) {return cpu_ticks_offset; }else { +int64_t ticks; + ticks =cpu_get_real_ticks (); +if (cpu_ticks_prev > ticks) { + cpu_ticks_offset += cpu_ticks_prev - ticks; + } + cpu_ticks_prev = ticks; -return cpu_get_real_ticks () + cpu_ticks_offset; +return ticks + cpu_ticks_offset; } }