Linux time not accurate : Ubuntu 22.04 / Virtualbox 7 / MacOS Ventura 13.2

Discussions related to using VirtualBox on Mac OS X hosts.
Post Reply
Denis_Lyon
Posts: 3
Joined: 10. Mar 2023, 12:23

Linux time not accurate : Ubuntu 22.04 / Virtualbox 7 / MacOS Ventura 13.2

Post by Denis_Lyon »

Good Morning,
My Ubuntu 22.4 sometimes slow down just after upgrading MacOS Ventura 13.2 and Virtualbox 7.0.6
Symptom : Unix time is no more accurate.
Host : MacBook Retina, 12-inch, 2017 with Ventura 13.2 (Intel)
Guest : Ubuntu 22.4

This issue can be highlighted by this simple script :

while true; do date;sleep 10; done
Thu Mar 9 17:19:03 CET 2023
Thu Mar 9 17:19:14 CET 2023
Thu Mar 9 17:19:26 CET 2023
Thu Mar 9 17:19:37 CET 2023
Thu Mar 9 17:19:50 CET 2023
Thu Mar 9 17:20:03 CET 2023
Thu Mar 9 17:20:13 CET 2023
Thu Mar 9 17:20:26 CET 2023
Thu Mar 9 17:20:37 CET 2023
Thu Mar 9 17:20:49 CET 2023
Thu Mar 9 17:21:00 CET 2023
Thu Mar 9 17:21:11 CET 2023
Thu Mar 9 17:21:22 CET 2023
Thu Mar 9 17:21:32 CET 2023

Thank you for your help
granada29
Volunteer
Posts: 690
Joined: 3. Mar 2015, 07:27
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux, macOS, Windows

Re: Linux time not accurate : Ubuntu 22.04 / Virtualbox 7 / MacOS Ventura 13.2

Post by granada29 »

One way to solve this problem is to install NTP software on your guest. My preference is chrony but there are other options.

In addition to this, you need to also stop VirtualBox from performing its regular time updates - if they are not disabled they will cause big glitches in chrony (or other).

To disable VirtualBox time updates from host to guest:

1. Shutdown the guest VM
2. From the Terminal command line:
VBoxManage setextradata "your-VM-name" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1

3. Restart your guest and install the chrony package (apt install chrony)

Documented at:
9.11.4. Disabling the Guest Additions Time Synchronization
Denis_Lyon
Posts: 3
Joined: 10. Mar 2023, 12:23

Re: Linux time not accurate : Ubuntu 22.04 / Virtualbox 7 / MacOS Ventura 13.2

Post by Denis_Lyon »

Thank you for your answer. Unfortunately the command did not fix the issue.
This issue appears only with Ventura and Virtualbox 7.
I suspect a problem with the scheduling and I made a test to eliminate a potential NTP problem, using monotonic clock :

Code: Select all

#include <stdio.h>
#include <time.h>
#include <unistd.h>

int main() {
	struct timespec tv;
	while (1) {
        	clock_gettime(CLOCK_MONOTONIC_RAW,&tv);
		printf("%ld %ld\n", tv.tv_sec, tv.tv_nsec);
		sleep(10);
	}
}
The result is eloquent :
  • 1143 293276902
    1157 186425065
    1167 232788873
    1177 226542706
    1196 530990594 <= 19 seconds !
    1208 284267703
    1220 565961372
    1230 634813052
    1250 114750770
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Linux time not accurate : Ubuntu 22.04 / Virtualbox 7 / MacOS Ventura 13.2

Post by fth0 »

There is a major difference between VirtualBox 6.1 and 7.0 on macOS hosts:

VirtualBox 6.1 supports macOS hosts up to macOS Monterey (-12) and uses kernel extensions for direct hardware access.

VirtualBox 7.0 supports macOS hosts from macOS Catalina (10.15+) on and runs under the Apple Hypervisor. Since this is a new implementation, issues are to be expected. Therefore, I'd suggest to create a ticket in the Bugtracker.
Post Reply