Windows XP Guest - timeBeginPeriod( ) slows system clock

Description

A system service running in a Windows XP SP3 Guest can use the Windows "timeBeginPeriod( )" function to change the system time tick resolution. That is common with multimedia or real-time applications. I have such a system service.

After the service has changed the Windows XP Guest timer resolution a problem occurs when running on a Windows 7 Host. The system time in the Guest updates at a much slower rate than normal and the time in the Guest falls behind the correct time. Any time related events occur at a slower than normal rate. For example, desktop fade effects, animated mouse pointers, Task Manager refreshing, and multimedia applications all appear to be "slow" due to the system time updating at a slower rate.

When the Windows time resolution is set back to the default by the system service then the time behaves normally again. If the Windows clock is reset to the correct time then it remains correct.

When the service is stopped it sets the time resolution back to normal.

/* Set the timer resolution back to normal */
if ( timeEndPeriod(gwTimerRes) != TIMERR_NOERROR ) {}

Other than the system time and timers being "slow" there are no other apparent problems in the Guest OS. I did not see excessive CPU usage, I/O or Interrupt activity. Although many things appear "slow" due to the incorrect time updates the execution of CPU instructions in the Guest does not seem to be affected.

I verified that the "timeBeginPeriod( )" Windows function causes the problem to occur and that the problem stops after calling "timeEndPeriod( )". This problem might explain some of the "Slow Windows Guest" complaints that are unresolved. The curious thing about the problem is that it does not appear to happen with Linux Host OS.

I have also tested the system service on a number of real PCs in order to verify that the problem is not the system service. After only seeing the problem in a VirtualBox guest I decided to investigate the problem further. I removed code from the system service until I found the functions causing the problem.

The problem also occurs with version 3.2.8 of VirtualBox under the same conditions. The problem occurs with or without the Guest Additions installed.

This may be a Windows problem that occurs when the hardware platform does not have enough performance to process all the multimedia timer events at the requested rate. I am running the VM on a Core i7 quad-core CPU at 3.65 GHz. and machines able to run the system service are considerably slower (Pentum III 1 Ghz.). That makes me believe that this should work in a VM. This could also be a scheduling problem in VirtualBox related to timer interrupts when the timer is reprogrammed in the virtual hardware.

After more testing I have verified that in my case I only see a problem when using a timer resolution of 1ms. I do not see the problem when using a timer resolution of 2ms. For now I will work around the problem using a slower timer resolution. I don't know if setting a 1ms. timer resolution is unusual or if any widely used Windows software does that.

I think this is a duplicate of #6842, see my last comment there (comment 17).

I agree with you. This does appear to be a duplicate. Hopefully I provided some additional information about the conditions that cause the problem. As long as there is some open ticket covering the problem it doesn't matter to me if this one is closed or added to the other. I hope that this is eventually addressed because it prevents me from using VirtualBox to do what I need for software development. I will be happy with a work around if it isn't something that can be solved in a more general way.