Commit eade0f192eef92f6c43ab036407cff46148be842
1 parent
07de1eaa
fix for hosts resuming from software suspend (initial patch by John Coiner)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1884 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
10 additions
and
1 deletions
vl.c
| ... | ... | @@ -558,6 +558,7 @@ int64_t cpu_get_real_ticks(void) |
| 558 | 558 | #error unsupported CPU |
| 559 | 559 | #endif |
| 560 | 560 | |
| 561 | +static int64_t cpu_ticks_prev; | |
| 561 | 562 | static int64_t cpu_ticks_offset; |
| 562 | 563 | static int cpu_ticks_enabled; |
| 563 | 564 | |
| ... | ... | @@ -566,7 +567,15 @@ static inline int64_t cpu_get_ticks(void) |
| 566 | 567 | if (!cpu_ticks_enabled) { |
| 567 | 568 | return cpu_ticks_offset; |
| 568 | 569 | } else { |
| 569 | - return cpu_get_real_ticks() + cpu_ticks_offset; | |
| 570 | + int64_t ticks; | |
| 571 | + ticks = cpu_get_real_ticks(); | |
| 572 | + if (cpu_ticks_prev > ticks) { | |
| 573 | + /* Note: non increasing ticks may happen if the host uses | |
| 574 | + software suspend */ | |
| 575 | + cpu_ticks_offset += cpu_ticks_prev - ticks; | |
| 576 | + } | |
| 577 | + cpu_ticks_prev = ticks; | |
| 578 | + return ticks + cpu_ticks_offset; | |
| 570 | 579 | } |
| 571 | 580 | } |
| 572 | 581 | ... | ... |