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
|
static void
|
||||||
sleeperproc(void *)
|
sleeperproc(void *)
|
||||||
{
|
{
|
||||||
vlong then, now;
|
vlong then, now, dt, adj;
|
||||||
|
|
||||||
timerid = threadid();
|
timerid = threadid();
|
||||||
timerevent = nanosec() + SleeperPoll;
|
timerevent = nanosec() + SleeperPoll;
|
||||||
unlock(&timerlock);
|
unlock(&timerlock);
|
||||||
threadsetname("sleeper");
|
threadsetname("sleeper");
|
||||||
|
adj = 0;
|
||||||
for(;;){
|
for(;;){
|
||||||
lock(&timerlock);
|
lock(&timerlock);
|
||||||
then = timerevent;
|
then = timerevent;
|
||||||
now = nanosec();
|
now = nanosec();
|
||||||
if(then <= now) timerevent = now + SleeperPoll;
|
if(then <= now) timerevent = now + SleeperPoll;
|
||||||
unlock(&timerlock);
|
unlock(&timerlock);
|
||||||
if(then - now >= MinSleep){
|
if(then > now){
|
||||||
sleep((then - now) / MSEC);
|
dt = then - now;
|
||||||
continue;
|
if(dt+adj >= MinSleep){
|
||||||
|
sleep((dt + adj) / MSEC);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
adj = dt;
|
||||||
}
|
}
|
||||||
while(nanosec() < then)
|
|
||||||
;
|
|
||||||
sendul(sleepch, 0);
|
sendul(sleepch, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue