What happens when the Guest OS resumes after being Paused

This is for discussing general topics about how to use VirtualBox.
Post Reply
hartz
Posts: 6
Joined: 24. Mar 2011, 12:48
Primary OS: Ubuntu other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Solaris, Windows, Linux

What happens when the Guest OS resumes after being Paused

Post by hartz »

Hello gurus.

Last time I checked, the OS probed the system hardware time at startup, and then tracked time in software based on interrupts.

OS internal time is used for everything, including file access and modification times, logs/events, and for when an application requests the time via a system call. It is also used to calculate things like on-CPU time and CPU idle time.

What I am curious about is what does the operating system do when it continues running after having been Paused. I've noticed that the time shows correctly in the Guest OS, but I am curious as to how/why the guest OS would know to update its internal representation of time. What happens to uptime counters, process CPU-time counters, etc?

By the way, is my assumption that the "Machine Pause" function is the same as the "Save Machine State" function? If so I should log a bug for disambiguation.
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, Linux

Re: What happens when the Guest OS resumes after being Paused

Post by scottgus1 »

Not sure about the newest version, but in the version (3.1.2) I'm using, Save Machine State is like Windows' Hibernate. The VM saves everything the virtual CPU/memory are doing (to a .sav file) and shuts off the virtual "power switch". When you restart the VM, the contents of the .sav file are reloaded into the VM's CPU/memory, and it picks up right where it left off, everything up-to-date.

Pause/Resume, is almost the same, AFAIK. The VM simply quits executing stuff and sits there. I think the physical memory is released, so the contents of the VM's memory might get stored in a file. Don't know for sure. But the "power" to the VM is not cut off. I believe that killing the VM while it is paused is not the same as Saving State. It's more like pulling the plug on a real PC.

As far as updating the VM's OS as to the time that has passed, no doubt Virtualbox does this in its internal guts. My saved-state VM's always seem to be updated properly. Since everything takes place in software there are no CPU decay times, hardware resets, etc., that have to be handled, because there really isn't a CPU or hardware that shuts off power when a VM saves state or pauses.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: What happens when the Guest OS resumes after being Paused

Post by mpack »

scottgus1 wrote:As far as updating the VM's OS as to the time that has passed, no doubt Virtualbox does this in its internal guts
VirtualBox can't provide any hardware feature that the guest OS doesn't look for, and if the guest doesn't reload the time from the RTC after a resume, then the clocks would be out of sync. There is a VirtualBox GA which is supposed to help maintain (or deliberately alter!) time sync, but I'm not sure how it works, and in any case is only of interest on some OS. In essence this a problem for the guest OS, not for VirtualBox.

My own best guess is that there's an ACPI signal which VBox can assert which alerts a modern OS that it just resumed from a hibernated state - after all hibernation is a feature of all OS that want to run on modern laptops.

I guess we could check the code, but guessing is more fun and takes less time... :)
hartz
Posts: 6
Joined: 24. Mar 2011, 12:48
Primary OS: Ubuntu other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Solaris, Windows, Linux

Re: What happens when the Guest OS resumes after being Paused

Post by hartz »

My code reading skills do not allow me to find this answer.

Other than something initiated via user-space (eg a tool to adjust system date/atime) I am not aware of kernel interfaces to set the clock after bootup. But I have long guessed that some interface similar to setting the system clock at bootup exists for when a system comes out of suspend or out of hibernation. Does VirtualBox utilize the Guest's Sleep/hibernate/suspend/whatever functions, eg by means of an ACPI signal, when it "restores the machine state" ? What about when the host comes out of suspend?

I notice that (most of) my VMs (Guest OS) don't allow me to put them into sleep mode. This is all tested on an Ubuntu 10.10 host.
o Windows 7: sleep is greyed-out
o Solaris Express 11: Suspend is missing from the shut down options.
o Linux Mint 8 xfce: Suspend option available on the shut-down dialog, but have no apparent effect (Not even an event in the system logs) Hybernate seems to work in the usual way (or as close as can be expected given the virtual nature of the hardware. Virtualbox Closes the VM, and on Startup, Linux detects the saved system state and resumes correctly)
o OpenIndiana: Suspend button on the ShutDown menu seems to work. The Guest continues to "run" (with a black screen) and consume memory as if nothing has happened. There does not appear to be a way to recover from this state.
o Ubuntu 10.10 guest: Hybernate functions more or less "as expected", i.e. VirtualBox stops the VM, but it fails to come out of hibernation (After waiting a few minutes nothing has happened). The Suspend function causes a black-screen, and subsequently moving the mouse presents a "unlock the session" dialog box, but nothing gets logged in system logs.
o When I feel more motivated I will add tests for OpenSUSE and a few as of yet un-installed Linux distributions.

FWIW: Of my current test candidates, LinuxMint was the only one that sucesfully went into and came out of hibernate. A number of candidates appeared to go into hibernate, but would not come out.

Solaris 10 do not support suspend/resume. When I start a loop in a terminal window to monitor the system clock, and then PAUSE the guest and wait 1 minute, then resume the guest, I see that the guest lost (near enough) 60 seconds relatively to the host. When coming out of SAVE MACHINE STATE I was surprised to see that about 4 seconds later the time was fixed (system time jump forward to match the host time)

It appears that VirtualBox do not (fully) implement suspend/resume features in its virtual hardware, but I still expect that this would be the path to getting the guest OS to update its local representation of time.

Any more educated opinions most welcome. Also speculation welcome, I love it all.

_J
hartz
Posts: 6
Joined: 24. Mar 2011, 12:48
Primary OS: Ubuntu other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Solaris, Windows, Linux

Re: What happens when the Guest OS resumes after being Paused

Post by hartz »

I just learned that guest additions affect this. For example pausing the Windows guest, then later un-pausing, the time will be lost on the guest, but it will start to catch up slowly (drift) until the guest time is correct!
hartz
Posts: 6
Joined: 24. Mar 2011, 12:48
Primary OS: Ubuntu other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Solaris, Windows, Linux

Guest additions largely takes care of this

Post by hartz »

And it is documented here:

http://www.virtualbox.org/manual/ch09.h ... getimesync

Now the only remaining questions is: "But what about when Guest Additions is not installed??"

_J
Post Reply