Hi!
I'm hunting a very high CPU usage on my game and I found out that the CPU increases after calling al_attach_mixer_to_voice().
I'm doing the following to initialize audio:
Before al_create_voice(), pulseaudio and my game are using less than 1% of CPU.
After al_create_voice(), pulseaudio is using 10% of CPU and my game still 1%.
When al_attach_mixer_to_voice() is called, pulseaudio start using 35% and my game 20%.
Those CPU percentages was checked using top while my game was on a sleep() after calling each function.
There is no threads running, just my main.c with this code.
My system is a Ubuntu Linux, kernel 3.8.0-35-generic 64 bits.
Could you provide a self-contained example? It'll be easier to nail down the problem that way.
EDIT: Nvm, I can reproduce it with just the code you gave... kind of odd, I bet we're spin-locking somewhere. I'll see if it's easy to find/fix.
EDIT2: It doesn't appear to be obvious... gdb shows 4 threads:
the main thread is sleeping in al_rest()
thread 2 is waiting for events from the window
thread 3 appears to be polling inside pulse audio, and I suspect this is responsible for the CPU usage
thread 4 is waiting on a condition variable inside the voice thread
So one'd have to find out why thread 3 exists and what it is doing... the backtrace is not helpful:
#0 0x00007ffff73dca43 in __GI___poll (fds=<optimized out>, nfds=<optimized out>, timeout=<optimized out>) at ../sysdeps/unix/sysv/linux/poll.c:87 #1 0x00007ffff5e61b6f in ?? () from /usr/lib/x86_64-linux-gnu/libpulse.so.0 #2 0x00007ffff5e530b5 in pa_mainloop_poll () from /usr/lib/x86_64-linux-gnu/libpulse.so.0 #3 0x00007ffff5e53719 in pa_mainloop_iterate () from /usr/lib/x86_64-linux-gnu/libpulse.so.0 #4 0x00007ffff5e537d0 in pa_mainloop_run () from /usr/lib/x86_64-linux-gnu/libpulse.so.0 #5 0x00007ffff5e61b1f in ?? () from /usr/lib/x86_64-linux-gnu/libpulse.so.0 #6 0x00007ffff4a2c543 in ?? () from /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-2.1.so #7 0x00007ffff6de2e9a in start_thread (arg=0x7fffee3d7700) at pthread_create.c:308 #8 0x00007ffff73e83fd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112 #9 0x0000000000000000 in ?? ()
EDIT3:
Further experimentation has shown that it might just be because the voice is started out in the playing state... however, I'm having trouble getting the voice/mixer playing functions to affect the CPU usage in a positive way (notable, calling al_set_mixer_playing(mixer, false) causes the CPU to spike to 200%!)