Skip to content
Browse files

alsa: Fix excessive I/O causing higher CPU usage

"On GCW Zero jz4770 platform, I saw higher than usual CPU usage when
running a more recent kernel (4.xx series versus 3.xx). Upon
investigation, it was found that the ALSA pcm file was not blocking
as it should. This resulted in ~30-50,000 system calls a second that
were unnecesary.

After adjusting the order in which SDL requests its pcm blocking mode,
the number of syscalls a second has dropped to a much smaller figure,
< 1,000/sec if I recall correctly. CPU usage also dropped by ~5%."

(This patch was written by Daniel Silsby.)

Fixes Bugzilla #4941.
  • Loading branch information
icculus committed Mar 23, 2020
1 parent e87e1ac commit 5d44141223f7c5fac8a3220656517258ed2923d9
Showing with 4 additions and 3 deletions.
  1. +4 −3 src/audio/alsa/SDL_alsa_audio.c
@@ -496,6 +496,10 @@ static int ALSA_OpenAudio(_THIS, SDL_AudioSpec *spec)

/* Switch to blocking mode for playback */
/* Note: this must happen before hw/sw params are set. */
SDL_NAME(snd_pcm_nonblock)(pcm_handle, 0);

/* Figure out what the hardware is capable of */
status = SDL_NAME(snd_pcm_hw_params_any)(pcm_handle, hwparams);
@@ -628,9 +632,6 @@ static int ALSA_OpenAudio(_THIS, SDL_AudioSpec *spec)
SDL_memset(mixbuf, spec->silence, spec->size);

/* Switch to blocking mode for playback */
SDL_NAME(snd_pcm_nonblock)(pcm_handle, 0);

/* We're ready to rock and roll. :-) */

0 comments on commit 5d44141

Please sign in to comment.