linux/sound/pci/echoaudio
Mark Hills a0b224b90b ALSA: echoaudio: Address bugs in the interrupt handling
Distorted audio appears occasionally, affecting either playback or
capture and requiring the affected substream to be closed by all
applications and re-opened.

The best way I have found to reproduce the bug is to use dmix in
combination with Chromium, which opens the audio device multiple times
in threads. Anecdotally, the problems appear to have increased with
faster CPUs. I ruled out 32-bit counter wrapping; it often happens
much earlier.

Since applying this patch I have not had problems, where previously
they would occur several times a day.

The patch targets the following issues:

* Check for progress using the counter from the hardware, not after it
  has been truncated to the buffer.

  This is a clean way to address a possible bug where if a whole
  ringbuffer advances between interrupts, it goes unnoticed.

* Move last_period state from chip to pipe

  This more logically belongs as part of pipe, and code is reasier to
  read if it is "counter position last time a period elapsed".

  Now the code has no references to period count. A period is just
  when the regular counter crosses a threshold. This increases
  readability and reduces scope for bugs.

* Treat period notification and buffer advance independently:

  This helps to clarify what is the responsibility of the interrupt
  handler, and what is pcm_pointer().

  Removing shared state between these operations means race conditions
  are fixed without introducing locks. Synchronisation is only around
  the read of pipe->dma_counter. There may be cache line contention
  around "struct audiopipe" but I did not have cause to profile this.

Pay attention to be robust where dma_counter wrapping is not a
multiple of period_size or buffer_size.

This is a revised patch based on feedback from Takashi and Giuliano.

Signed-off-by: Mark Hills <mark@xwax.org>
Link: https://lore.kernel.org/r/20200708101848.3457-5-mark@xwax.org
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-07-09 12:59:24 +02:00
..
darla20_dsp.c ALSA: echoaudio: Use standard C definitions of true and false 2015-08-10 14:27:16 +02:00
darla20.c ALSA: pci: Constify snd_pcm_hardware definitions 2020-01-03 09:23:47 +01:00
darla24_dsp.c ALSA: echoaudio: Use standard C definitions of true and false 2015-08-10 14:27:16 +02:00
darla24.c ALSA: pci: Constify snd_pcm_hardware definitions 2020-01-03 09:23:47 +01:00
echo3g_dsp.c ALSA: echoaudio: Use standard C definitions of true and false 2015-08-10 14:27:16 +02:00
echo3g.c ALSA: pci: Constify snd_pcm_hardware definitions 2020-01-03 09:23:47 +01:00
echoaudio_3g.c ALSA: echoaudio: Proper endian notations 2018-07-27 09:06:09 +02:00
echoaudio_dsp.c ALSA: echoaudio: Prevent some noise on unloading the module 2020-07-09 12:59:07 +02:00
echoaudio_dsp.h ALSA: echoaudio: Proper endian notations 2018-07-27 09:06:09 +02:00
echoaudio_gml.c ALSA: echoaudio: Proper endian notations 2018-07-27 09:06:09 +02:00
echoaudio.c ALSA: echoaudio: Address bugs in the interrupt handling 2020-07-09 12:59:24 +02:00
echoaudio.h ALSA: echoaudio: Address bugs in the interrupt handling 2020-07-09 12:59:24 +02:00
gina20_dsp.c ALSA: echoaudio: Use standard C definitions of true and false 2015-08-10 14:27:16 +02:00
gina20.c ALSA: pci: Constify snd_pcm_hardware definitions 2020-01-03 09:23:47 +01:00
gina24_dsp.c ALSA: echoaudio: Use standard C definitions of true and false 2015-08-10 14:27:16 +02:00
gina24.c ALSA: pci: Constify snd_pcm_hardware definitions 2020-01-03 09:23:47 +01:00
indigo_dsp.c ALSA: echoaudio: Use standard C definitions of true and false 2015-08-10 14:27:16 +02:00
indigo_express_dsp.c ALSA: echoaudio: remove all snd_printk 2014-11-03 14:07:25 +01:00
indigo.c ALSA: pci: Constify snd_pcm_hardware definitions 2020-01-03 09:23:47 +01:00
indigodj_dsp.c ALSA: echoaudio: Use standard C definitions of true and false 2015-08-10 14:27:16 +02:00
indigodj.c ALSA: pci: Constify snd_pcm_hardware definitions 2020-01-03 09:23:47 +01:00
indigodjx_dsp.c ALSA: echoaudio: Use standard C definitions of true and false 2015-08-10 14:27:16 +02:00
indigodjx.c ALSA: pci: Constify snd_pcm_hardware definitions 2020-01-03 09:23:47 +01:00
indigoio_dsp.c ALSA: echoaudio: Use standard C definitions of true and false 2015-08-10 14:27:16 +02:00
indigoio.c ALSA: pci: Constify snd_pcm_hardware definitions 2020-01-03 09:23:47 +01:00
indigoiox_dsp.c ALSA: echoaudio: Use standard C definitions of true and false 2015-08-10 14:27:16 +02:00
indigoiox.c ALSA: pci: Constify snd_pcm_hardware definitions 2020-01-03 09:23:47 +01:00
layla20_dsp.c ALSA: echoaudio: Use standard C definitions of true and false 2015-08-10 14:27:16 +02:00
layla20.c ALSA: pci: Constify snd_pcm_hardware definitions 2020-01-03 09:23:47 +01:00
layla24_dsp.c ALSA: echoaudio: Fix improper return value in function load_asic 2016-11-29 19:59:57 +01:00
layla24.c ALSA: pci: Constify snd_pcm_hardware definitions 2020-01-03 09:23:47 +01:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mia_dsp.c ALSA: echoaudio: Use standard C definitions of true and false 2015-08-10 14:27:16 +02:00
mia.c ALSA: pci: Constify snd_pcm_hardware definitions 2020-01-03 09:23:47 +01:00
midi.c ALSA: Convert timers to use timer_setup() 2017-10-26 14:44:59 +02:00
mona_dsp.c ALSA: echoaudio: Remove redundant check 2020-07-09 12:57:59 +02:00
mona.c ALSA: pci: Constify snd_pcm_hardware definitions 2020-01-03 09:23:47 +01:00