Skip to contentSkip to conversation

Locking/mutex for snd_pcm_update_hw_ptr0() call

DISCUSSION Alan Young 2 participants 4 messages Nov 7, 2016

lore
Share & tools
lore

Alan Young

author
#0 lore raw

As far as I can see, snd_pcm_update_hw_ptr0() is a critical section of code that is protected by some form of mutex in all its call paths:

snd_pcm_period_elapsed() - snd_pcm_stream_lock_irqsave()

snd_pcm_update_hw_ptr()

snd_pcm_lib_ioctl_reset() - snd_pcm_stream_lock_irqsave()

snd_pcm_lib_write1() - snd_pcm_stream_lock_irq()

snd_pcm_lib_read1() - snd_pcm_stream_lock_irq()

snd_pcm_status() - snd_pcm_stream_lock_irq()

snd_pcm_do_pause - I think via the locking in snd_pcm_action()

snd_pcm_playback_rewind() - snd_pcm_stream_lock_irq()

snd_pcm_capture_rewind() - snd_pcm_stream_lock_irq()

snd_pcm_playback_forward() - snd_pcm_stream_lock_irq()

snd_pcm_capture_forward() - snd_pcm_stream_lock_irq()

snd_pcm_hwsync() - snd_pcm_stream_lock_irq()

snd_pcm_delay() - snd_pcm_stream_lock_irq()

However, I am not familiar with how kernel locking mechanisms work. It is possible that the DMA interrupt handler (snd_pcm_period_elapsed()), could call snd_pcm_update_hw_ptr0() while it is part way through a call from snd_pcm_status(), or vice versa?

Alan.

#1 lore raw
Quoted 3 lines · Alan Young

It is possible that the DMA interrupt handler could call snd_pcm_update_hw_ptr0() while it is part way through a call from snd_pcm_status(), or vice versa?

The *lock_irq* functions disable interrupts on the current CPU.

Regards,
Clemens

author
#2 lore raw
Quoted 7 lines · Clemens Ladisch
Quoted 3 lines · Alan Young

It is possible that the DMA interrupt handler could call snd_pcm_update_hw_ptr0() while it is part way through a call from snd_pcm_status(), or vice versa?

The *lock_irq* functions disable interrupts on the current CPU.

But only on the current CPU? So that would imply that multiple threads could execute snd_pcm_update_hw_ptr0() simultaneously on multi-CPU systems.

Even on a single-CPU system, I presume that the interrupt handler cannot be pre-empted by a user-space call such as snd_pcm_status(). Is that correct?

Alan.

#3 lore raw
Quoted 11 lines · Alan Young
Quoted 6 lines · Clemens Ladisch
Quoted 3 lines · Alan Young

It is possible that the DMA interrupt handler could call snd_pcm_update_hw_ptr0() while it is part way through a call from snd_pcm_status(), or vice versa?

The *lock_irq* functions disable interrupts on the current CPU.

But only on the current CPU? So that would imply that multiple threads could execute snd_pcm_update_hw_ptr0() simultaneously on multi-CPU systems.

That's what the lock is for.

Quoted 2 lines

I presume that the interrupt handler cannot be pre-empted by a user- space call such as snd_pcm_status().

During execution of an interrupt handler, interrupts also are disabled.

Regards,
Clemens