ASoC: SOF: Race condition in ipc.c

noman pouigt variksla at gmail.com
Tue Jun 21 04:46:23 CEST 2022


Folks,

I have borrowed part of SOF architecture for my own DSP
framework development as the memory on the DSP is
extremely small and wouldn't be able to support SOF.

Currently I am running into a race condition as below:

CPU                                            DSP
PCM_TRIGGER_START
sof_ipc_send_msg ---->

                                      <------Immediate ACK
ipc3_wait_tx_done
(wait_event_timeout)
                                      <------ POSITION update

snd_pcm_period_elapsed


As you can see TRIGGER_START didn't even finish
and waiting for it to complete in ipc3_wait_tx_done
function. However, before it could complete the position
interrupt was issued which results in calling period_elapsed
function.

In order to fix this I assume below is called in SOF framework:
schedule_work(&spcm->stream[substream->stream].period_elapsed_work);

How is this design working? If the interrupt is coming too fast
from the DSP than the associated function with this schedule_work
will not get called as the scheduler will not get time to schedule the
workqueue and elapsed function will not be called thereby not increasing
the hw_ptr. How is the flow control for data transfer achieved?

I am facing the above problem in my design.

I am wondering if I can simply add one more IPC command(don't call
wait_event_interruptible for this) after TRIGGER_START to start the
streaming.This way schedule_work for updating period_elapsed function
can be avoided and it can be called in an interrupt context.

Thanks,
Variksla


More information about the Alsa-devel mailing list