Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ec7C5-0001rB-F4 for qemu-devel@nongnu.org; Tue, 15 Nov 2005 15:14:17 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ec7C3-0001qL-MK for qemu-devel@nongnu.org; Tue, 15 Nov 2005 15:14:17 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ec7C3-0001qF-Hn for qemu-devel@nongnu.org; Tue, 15 Nov 2005 15:14:15 -0500 Received: from [195.168.1.142] (helo=mailhub3.nextra.sk) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Ec7C3-0005WA-7w for qemu-devel@nongnu.org; Tue, 15 Nov 2005 15:14:15 -0500 Message-ID: <437A4093.7050306@atlas.sk> Date: Tue, 15 Nov 2005 21:09:55 +0100 From: ace MIME-Version: 1.0 Subject: Re: [Qemu-devel] [patch] fix QEMU hang after hibernate References: <4349FB21.9040205@stanfordalumni.org> In-Reply-To: <4349FB21.9040205@stanfordalumni.org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org I can confirm this patch applied alone to 0.7.2 did something for me. I suspended the PC for 1 minute (just to reboot the machine) and after resume, my quest win95 was still working. I will of course try longer periods later. Peter John Coiner wrote: > > After I hibernate my x86 linux host machine (using the "swsusp2" > package) and resume, QEMU and guest hang. That is odd, because > hibernation is transparent to all other user programs. > > Has anyone else noticed this? If so please try the patch. > > You know QEMU is doing something weird, for it to be sensitive to > hibernation. Indeed, the cause is something you don't see every day: > > QEMU implements timers partly by reading the CPU's tick counter directly > from hardware, with an architecture-specific assembly instruction > ('rdtsc' on intel, and so on for other archs) rather than using purely > OS-provided features to get the time. > > The problem is that following hibernation, the CPU tick counter isn't > what it used to be. On my host, it has a lower value -- it jumped > backwards. This breaks QEMU's timers. Some of them decide to block for a > very long time, which causes the guest to hang or behave oddly. > > (Maybe this is technically a bug in "swsusp2", maybe it should restore > the CPU tick counter to the previous value upon resume. But who cares. > It's easy to fix this in QEMU, and it would not be easy to check and fix > all hibernation schemes on all architectures and operating systems.) > > The following patch fixes the 'cpu_get_ticks()' function to always > return a non-decreasing value, even if the value read from hardware > decreases. Hope it helps. Feedback is welcome. > > -- John > > > > --- qemu-0.7.2-dmapatch/vl.c 2005-09-04 13:11:31.000000000 -0400 > +++ qemu-0.7.2-broken/vl.c 2005-10-10 00:54:08.000000000 -0400 > @@ -545,14 +547,21 @@ > #error unsupported CPU > #endif > > -static int64_t cpu_ticks_offset; > -static int cpu_ticks_enabled; > +static int64_t cpu_ticks_prev = 0; > +static int64_t cpu_ticks_offset = 0; > +static int cpu_ticks_enabled = 0; > > static inline int64_t cpu_get_ticks(void) > { > if (!cpu_ticks_enabled) { > return cpu_ticks_offset; > } else { > + int64_t 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; > } > } > > > > _______________________________________________ > Qemu-devel mailing list > Qemu-devel@nongnu.org > http://lists.nongnu.org/mailman/listinfo/qemu-devel > > > > >