Laptops and busy wait
Neil Toronto
ntoronto at cs.byu.edu
Tue Mar 14 03:18:55 EST 2006
For no good reason, I'm developing on a laptop running Linux. Quake 3
presents it with a special problem: even with com_maxfps set, it runs
busy wait loop, which eats up CPU (near 100%), which turns on frequency
throttling (or scaling), which lowers the framerate.
I don't recall having this problem when I was developing mods on
Windows. (However, looking through the engine source, I can't see a good
reason it wouldn't have done it there.)
The busy wait loop is in common.c:
do {
<call event processing loop>
...
} while (msec < minMsec);
Possible solution:
do {
<call event processing loop>
...
if (msec < minMsec) Sys_Sleep(0);
} while (msec < minMsec);
This kicks Quake 3 off the scheduler if the frame didn't take long
enough, so the CPU is free to pause for a half millisecond and cool off.
Sys_Sleep() is a new function in unix_shared.c and win_shared.c. On unix
systems it calls usleep(msec * 1000), on Windows, Sleep(msec). On both
systems, Sys_Sleep(0) behaves the same way.
I don't know what this would do when a server is running. My own
codebase is heavily modified - no server, no netcode, etc. It works fine
with just a client game, though.
Thoughts?
Neil
More information about the quake3
mailing list