Skip to content

Commit

Permalink
alsa: Fix excessive I/O causing higher CPU usage
Browse files Browse the repository at this point in the history
"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 5d44141
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/audio/alsa/SDL_alsa_audio.c
Expand Up @@ -496,6 +496,10 @@ static int ALSA_OpenAudio(_THIS, SDL_AudioSpec *spec)
return(-1);
}

/* 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 */
snd_pcm_hw_params_alloca(&hwparams);
status = SDL_NAME(snd_pcm_hw_params_any)(pcm_handle, hwparams);
Expand Down Expand Up @@ -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. :-) */
return(0);
}

0 comments on commit 5d44141

Please sign in to comment.