Ticket #4912 (new enhancement)
pygtk does thousands of futex(,FUTEX_WAKE) calls unnecessarily
|Reported by:||gnu||Owned by:||marco|
|Deployments affected:||Blocked By:|
While debugging SimCity's helper process, I noticed that it was doing a lot of system calls in between calls to poll(). It's calling futex(addr, FUTEX_WAKE, 1) and getting a result of 0. This means it called into the kernel to wake up one process who was waiting on a shared semaphore, but no process was waiting.
Futexes are supposed to run entirely in user space, using atomic instructions, unless and until they detect that the semaphore is being waited on by some other process that shares the same memory. In that case, there's this system call (which allows both waiting, and waking). There's a bug, and the system call is being invoked frequently in circumstances where it's not needed.
In SimCity, the helper process which basically has nothing to do unless it gets a message from dbus, makes 6 futex() calls every time its poll() call returns (currently 10x/second).
Since Sugar is written in Python and uses GTK, it suffers from these excessive system calls.
Brief investigation showed that these calls are coming from a call to sem_post in Python's thread_pthread.c in PyThread_release_lock.