Opened 23 months ago
#21544 new defect
VB7/Ventura : Issue with clock_gettime() in Ubuntu 22.04 VM
Reported by: | Denis_Lyon | Owned by: | |
---|---|---|---|
Component: | VM control | Version: | VirtualBox-7.0.6 |
Keywords: | Ventura Ubuntu clock_gettime | Cc: | |
Guest type: | Linux | Host type: | Mac OS X |
Description
I observe a strange behaviour that I’ve never experienced before. This appeared when upgrading from Monterey/VB6 to Ventura/VB7.
When I boot Ubuntu 22.04, the Linux scheduling is fine. But after some CPU load on this VM, I see an issue in the scheduling : For example the usleep() function is not accurate.
The code bellow highlight the issue. It sleeps for 10 seconds and display the difference between 2 calls to clock_gettime Using monotonic time.
Here is an extract of the result of this program :
9.984428045 9.936712734 9.976024270 19.841512940 10.741785027 17.570817783 9.965956486 9.933059723 9.978769179 9.990323837 10.203674177 14.49491216 10.497382894
And the code :
#include <stdio.h> #include <time.h> #include <unistd.h> #define NSEC_PER_SEC 1000000000 #define SUB_TIMESPEC(t1, t2)\ do {\ if (((t1).tv_nsec -= (t2).tv_nsec) < 0) {\ (t1).tv_nsec += NSEC_PER_SEC;\ (t1).tv_sec -= 1;\ }\ (t1).tv_sec -= (t2).tv_sec;\ } while (0) int main() { struct timespec diff, new, old; while (1) { clock_gettime(CLOCK_MONOTONIC_RAW,&old); usleep(10*1000000); clock_gettime(CLOCK_MONOTONIC_RAW,&new); diff = new; SUB_TIMESPEC(diff, old); printf("%ld.%ld\n", diff.tv_sec, diff.tv_nsec); } }