vmx: reduce cpu load by eliminating nop-loop
Sacrifice some of the sub-millisecond timer precision in favor of less cpu load when the timer is about to be kicked a bit early. Result is visible *especially* when the guest idling. Timer proc *still* has to send to the channel (in order to kick PIT and RTC logic), which takes time, and compensates a bit for possibly early runs.
This commit is contained in:
parent
007d42e741
commit
692919521c
1 changed files with 10 additions and 6 deletions
|
@ -423,24 +423,28 @@ int timerid;
|
|||
static void
|
||||
sleeperproc(void *)
|
||||
{
|
||||
vlong then, now;
|
||||
vlong then, now, dt, adj;
|
||||
|
||||
timerid = threadid();
|
||||
timerevent = nanosec() + SleeperPoll;
|
||||
unlock(&timerlock);
|
||||
threadsetname("sleeper");
|
||||
adj = 0;
|
||||
for(;;){
|
||||
lock(&timerlock);
|
||||
then = timerevent;
|
||||
now = nanosec();
|
||||
if(then <= now) timerevent = now + SleeperPoll;
|
||||
unlock(&timerlock);
|
||||
if(then - now >= MinSleep){
|
||||
sleep((then - now) / MSEC);
|
||||
continue;
|
||||
if(then > now){
|
||||
dt = then - now;
|
||||
if(dt+adj >= MinSleep){
|
||||
sleep((dt + adj) / MSEC);
|
||||
continue;
|
||||
}
|
||||
adj = dt;
|
||||
}
|
||||
while(nanosec() < then)
|
||||
;
|
||||
|
||||
sendul(sleepch, 0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue