jaor/xmobar — pull request #195 by enomsg (2014-09-17 03:34:55+00:00)
Title: Locks: Power Consumption Fixes

Hi,

The extremely useful "Locks" plugin eats quite a lot of CPU (>2% here on a
old-ish laptop), unfortunately. The plug-in unnecessary reopens the
display, which is quite expensive operation. It results into 16 syscalls:

socket(PF_LOCAL) -> connect(sun_path=@"/tmp/.X11-unix/X0"})
-> getpeername() -> uname()
-> access(".Xauthority") -> open(".Xauthority")
-> fstat() -> mmap()
-> read() -> close()
-> munmap() -> getsockname()
-> fcntl(F_SETFD) -> fcntl(F_SETFL)
-> shutdown() -> close()

This is almost half of all the syscalls that we ought to execute for the
plug-in to work. Now, considering the useful work and that "Locks" runs
every 200 milliseconds, it gives us >300 syscalls (and a lot more
wake-ups) per second.

The first commit fixes the reopening issue, effectively halving the CPU
consumption (down to ~1%). The patch also makes it easier to implement
event-driven indicators that will reduce the idle CPU consumption to 0.

The second commit does more fundamental rework of the "Locks" plug-in,
making the plug-in fully event-driven and thus extremely power-efficient,
effectively zero CPU consumption while idling.

Thanks,
Anton