Disable rdtsc emulation

This is for discussing general topics about how to use VirtualBox.
Post Reply
byronhawkins
Posts: 7
Joined: 10. May 2011, 07:22
Primary OS: Ubuntu 12.04
VBox Version: PUEL
Guest OSses: Windows 7, Kubuntu

Disable rdtsc emulation

Post by byronhawkins »

Performance of the rdtsc instruction is not very good in my VirtualBox install, apparently because that instruction is emulated. Is there any way to disable the emulation for this instruction to get native speed? I realize many programs would not want this behavior, but I am just running some research experiments and I only need a rough estimation of elapsed CPU cycles. The important thing is to have minimal latency in the rdtsc instruction itself. Context switches are already a factor at the guest level, so introducing more context switch artifacts at the host level is not a problem. Thanks for your help.
Ramshankar
Oracle Corporation
Posts: 793
Joined: 7. Jan 2008, 16:17

Re: Disable rdtsc emulation

Post by Ramshankar »

The instruction is not always emulated with hardware virtualization. By default, with hardware virtualization (on all CPUs capable of TSC offsetting), RDTSC's executed by the guest are intercepted or not in a dynamic fashion. VirtualBox will program an offset and let the hardware virtualization logic in the CPU compute the guest TSC without causing intercepts (which are still very expensive) and only interecept it when it needs to gradually "catch up" as guest time drifts apart due to time sharing the host and guest on the same hardware.

There is a CFGM setting to use the "real TSC" (host TSC) as a sort of passthru but for obvious reasons this is never the default.

Code: Select all

VBoxManage --modifyvm <vmname> VBoxInternal/TM/UseRealTSC 1
is the setting (if I remember right). Try at your own risk. The above will -not- present the guest with a consistent TSC flow.

This will use the host TSC as the time source (-not- recommended) but since you said you're doing some research that MAY be what you're looking for. Unfortunately there are several tunable variables in the TM component that interact in complicated ways and explaining everything possible setting and their effects on the guest here is not feasible.

In theory, VirtualBox could eventually never intercept RDTSC but use offsetting and simply increase the offsets to the expected guest time and cause a "jumpy behaviour" (due to late guest scheduling etc.) but currently we keep TSC ticking in the guest more smoothly as many guests cross-verify TSC with other time sources (like RTC) and unless the guest knows it's a virtualized environment it can get upset in upredictable ways (Windows BSODs, Solaris deadman panics etc.)
Oracle Corp.
Anoush
Posts: 1
Joined: 4. Dec 2015, 04:36

Re: Disable rdtsc emulation

Post by Anoush »

Ramshankar wrote:

Code: Select all

VBoxManage --modifyvm <vmname> VBoxInternal/TM/UseRealTSC 1
What is the VirtualBox 5 equivalent of this command? Debugging a performance issue involving RDTSC, and would really appreciate your help!
michaln
Oracle Corporation
Posts: 2973
Joined: 19. Dec 2007, 15:45
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: Any and all
Contact:

Re: Disable rdtsc emulation

Post by michaln »

Why not explain the problem and provide a VBox.log first.
Post Reply