100% CPU while waiting for clang.
Closed this issue · 1 comments
I noticed the process waiting for clang to compile a kernel takes 100% CPU on a core while clang is taking 100% on a separate core. In my experience, this usually means some kind of spin wait. GDB suggests that the process is spining around at ProcessUtil.cpp:222 in vc4c::runProcess.
The while loop is supposed to check if the child process finished (isChildFinished) and then uses 'select' to check for output from the child process. According to the comments, 'select' is supposed to wait up to 1ms for output, then if there is none, return so that the cycle can start again. So, the while loop should only run about 1,000 times a second.
However, in the 'select' man page, it notes:
On Linux, select() modifies timeout to reflect the amount of time not
slept; most other implementations do not do this. (POSIX.1 permits
either behavior.) This causes problems both when Linux code which
reads timeout is ported to other operating systems, and when code is
ported to Linux that reuses a struct timeval for multiple select()s
in a loop without reinitializing it. Consider timeout to be unde‐
fined after select() returns.
So, if 'select' waits the the whole 1ms before returning (which it usually does), 'timeout' gets set to 0 and the next time through the while loop (and subsequent times), 'select' returns immediately, causing the loop to spin as fast as possible.
The fix is to simply move the assignment of 'timeout' inside the while loop, right before the 'select' statement, so that the timeout is set to the correct value before 'select' is executed every time. (Another option, would be to switch to 'pselect' [with a NULL sigmask]; unlike 'select', 'pselect' doesn't modify its 'timeout' parameter.)
@jkpeters37 is this fixed on your setup?