diff options
author | Sigrid <ftrvxmtrx@gmail.com> | 2021-02-23 15:54:09 +0100 |
---|---|---|
committer | Sigrid <ftrvxmtrx@gmail.com> | 2021-02-23 15:54:09 +0100 |
commit | 692919521c15531cc0bed3006fd958b164a746ab (patch) | |
tree | 61d5288b0552cfa33e211d251610abf548d8ca3e | |
parent | 007d42e741b780aeecefd66776b1733c3dd53522 (diff) | |
download | plan9front-692919521c15531cc0bed3006fd958b164a746ab.tar.xz |
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.
-rw-r--r-- | sys/src/cmd/vmx/vmx.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/sys/src/cmd/vmx/vmx.c b/sys/src/cmd/vmx/vmx.c index b3b73d845..6ef70ac14 100644 --- a/sys/src/cmd/vmx/vmx.c +++ b/sys/src/cmd/vmx/vmx.c @@ -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); } } |