Code: Select all
while (1) {
t0 = gettime();
sleep(1);
t1 = gettime();
print t1-t0;
}
Yes, sleep() is an imprecise beast, but it should not be sleeping 2-3 seconds on an otherwise idle system. What you'd normally expect is +/- 10ms perhaps at worst.
Known problem? Any known solutions?
(I'm kind of wondering how many other things this affects in a booted vbox Linux environment in general, it can't be limited to just my test script!)
An ideal solution would be to recompile the kernel due to a known offending kernel configuration wrt vbox.
Here's some actual code that measures sleep(1ms) into buckets:
Code: Select all
#!/usr/bin/perl
use Time::HiRes qw( nanosleep time );
$| = 1;
@c = (0,0,0, 0,0,0, 0,0,0, 0);
$max = 0;
$total = 0;
while (1) {
for ($x = 0; $x<1000; ++$x) {
$delta = time();
nanosleep(1000000);
$delta = int(1000*(time() - $delta));
if ($delta < 2.0) { ++$c[0]; }
elsif ($delta < 4.0) { ++$c[1]; }
elsif ($delta < 8.0) { ++$c[2]; }
elsif ($delta < 16.0) { ++$c[3]; }
elsif ($delta < 32.0) { ++$c[4]; }
elsif ($delta < 64.0) { ++$c[5]; }
elsif ($delta < 128.0) { ++$c[6]; }
elsif ($delta < 256.0) { ++$c[7]; }
elsif ($delta < 512.0) { ++$c[8]; }
else { ++$c[9]; }
if ($delta > $max) { $max = $delta; }
}
$total += $x;
print "$c[0] $c[1] $c[2] $c[3] $c[4] $c[5] $c[6] $c[7] $c[8] $c[9] max:$max total:$total\n";
}
Code: Select all
<2ms <4 <8 <16 <32 <64 <128 <256 <512 >=512ms
92845 4856 783 576 824 42 28 28 18 0 max:368 total:100000
Code: Select all
<2ms <4 <8 <16 <32 <64 <128 <256 <512 >=512ms
100000 0 0 0 0 0 0 0 0 0 max:1 total:100000