Skip to contentSkip to conversation

ASoC: SOF: Use high-priority workqueue for PCM period elapsed

PATCH In review Peter Ujfalusi 3 participants 7 messages Jul 30 – Aug 3

Subsystems (3)
lore
Share & tools
lore

Peter Ujfalusi

author maintainer
#0 lore raw

PATCH 1/1 ASoC: SOF: Use high-priority workqueue for PCM period elapsed

From: Yu-Hsuan Hsu <[email protected]>

The snd_sof_pcm_period_elapsed function currently schedules work on the system-wide workqueue. This can lead to potential delays or jitter in audio processing if the system workqueue is busy with other tasks.

To improve real-time performance and ensure timely processing of PCM periods, we can use the system_highpri_wq instead of the default work queue.

In performance testing, this change significantly reduced the observed scheduling delays. For instance, under load(stressapptest -M 15000 -m 60), the maximum delay dropped from 9ms on the system workqueue to 5ms on the dedicated high-priority workqueue.

---
 sound/soc/sof/pcm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/sof/pcm.c +1 -1
index b2071edeaea6..f748d072109a 100644
@@ -62,7 +62,7 @@ void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream)
 	 * To avoid sending IPC before the previous IPC is handled, we
 	 * schedule delayed work here to call the snd_pcm_period_elapsed().
 	 */
-	schedule_work(&spcm->stream[substream->stream].period_elapsed_work);
+	queue_work(system_highpri_wq, &spcm->stream[substream->stream].period_elapsed_work);
 }
 EXPORT_SYMBOL(snd_sof_pcm_period_elapsed);
 
Signature · 1 line
2.55.0
#1 lore raw
Quoted 15 lines · Peter Ujfalusi

From: Yu-Hsuan Hsu <[email protected]>

The snd_sof_pcm_period_elapsed function currently schedules work on the system-wide workqueue. This can lead to potential delays or jitter in audio processing if the system workqueue is busy with other tasks.

To improve real-time performance and ensure timely processing of PCM periods, we can use the system_highpri_wq instead of the default work queue.

In performance testing, this change significantly reduced the observed scheduling delays. For instance, under load(stressapptest -M 15000 -m 60), the maximum delay dropped from 9ms on the system workqueue to 5ms on the dedicated high-priority workqueue.

Quoted 6 lines

Sounds good but should this higher priority queue be used for other things as well?

e.g.

period-elapsed for compressed streams:
schedule_work(&spcm->stream[cstream->direction].period_elapsed_work);

and the SoundWire interrupt handling with additional workqueues:
schedule_work(&amd_manager->amd_sdw_irq_thread); schedule_work(&amd_manager->amd_sdw_work); schedule_work(&cdns->work);

Not sure what the rules are to define what's high-priority and what's not... It could be that different systems have different requirements...

Quoted 17 lines
---
 sound/soc/sof/pcm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/sof/pcm.c +1 -1
index b2071edeaea6..f748d072109a 100644
@@ -62,7 +62,7 @@ void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream)
 	 * To avoid sending IPC before the previous IPC is handled, we
 	 * schedule delayed work here to call the snd_pcm_period_elapsed().
 	 */
-	schedule_work(&spcm->stream[substream->stream].period_elapsed_work);
+	queue_work(system_highpri_wq, &spcm->stream[substream->stream].period_elapsed_work);
 }
 EXPORT_SYMBOL(snd_sof_pcm_period_elapsed);
 
author maintainer
#2 lore raw
Quoted 28 lines · Pierre-Louis Bossart
Quoted 15 lines · Peter Ujfalusi

From: Yu-Hsuan Hsu <[email protected]>

The snd_sof_pcm_period_elapsed function currently schedules work on the system-wide workqueue. This can lead to potential delays or jitter in audio processing if the system workqueue is busy with other tasks.

To improve real-time performance and ensure timely processing of PCM periods, we can use the system_highpri_wq instead of the default work queue.

In performance testing, this change significantly reduced the observed scheduling delays. For instance, under load(stressapptest -M 15000 -m 60), the maximum delay dropped from 9ms on the system workqueue to 5ms on the dedicated high-priority workqueue.

Quoted 6 lines

Sounds good but should this higher priority queue be used for other things as well?

e.g.

Quoted 7 lines

period-elapsed for compressed streams:
schedule_work(&spcm->stream[cstream->direction].period_elapsed_work);

and the SoundWire interrupt handling with additional workqueues:
schedule_work(&amd_manager->amd_sdw_irq_thread); schedule_work(&amd_manager->amd_sdw_work); schedule_work(&cdns->work);

we also have:

sound/soc/sof/core.c:           schedule_work(&sdev->probe_work);
sound/soc/sof/intel/ptl.c:      schedule_work(&hdev->mic_privacy.work);
Quoted 2 lines

Not sure what the rules are to define what's high-priority and what's not... It could be that different systems have different requirements...

I think the 'rule' is that what is time critical and what can tolerate a bit of a delay. The PCM period is time critical while the others are not that much, that includes the compress elapsed, it is not that real-time as the PCM.

But fair point, I will check if anything else would needs to be higher priority than what they are.

Quoted 19 lines
Quoted 18 lines
---
 sound/soc/sof/pcm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/sof/pcm.c +1 -1
index b2071edeaea6..f748d072109a 100644
@@ -62,7 +62,7 @@ void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream)
 	 * To avoid sending IPC before the previous IPC is handled, we
 	 * schedule delayed work here to call the snd_pcm_period_elapsed().
 	 */
-	schedule_work(&spcm->stream[substream->stream].period_elapsed_work);
+	queue_work(system_highpri_wq, &spcm->stream[substream->stream].period_elapsed_work);
 }
 EXPORT_SYMBOL(snd_sof_pcm_period_elapsed);
 
Signature · 1 line
Péter
#3 lore raw
Quoted 46 lines · Péter Ujfalusi
Quoted 28 lines · Pierre-Louis Bossart
Quoted 15 lines · Peter Ujfalusi

From: Yu-Hsuan Hsu <[email protected]>

The snd_sof_pcm_period_elapsed function currently schedules work on the system-wide workqueue. This can lead to potential delays or jitter in audio processing if the system workqueue is busy with other tasks.

To improve real-time performance and ensure timely processing of PCM periods, we can use the system_highpri_wq instead of the default work queue.

In performance testing, this change significantly reduced the observed scheduling delays. For instance, under load(stressapptest -M 15000 -m 60), the maximum delay dropped from 9ms on the system workqueue to 5ms on the dedicated high-priority workqueue.

Quoted 6 lines

Sounds good but should this higher priority queue be used for other things as well?

e.g.

Quoted 7 lines

period-elapsed for compressed streams:
schedule_work(&spcm->stream[cstream->direction].period_elapsed_work);

and the SoundWire interrupt handling with additional workqueues:
schedule_work(&amd_manager->amd_sdw_irq_thread); schedule_work(&amd_manager->amd_sdw_work); schedule_work(&cdns->work);

we also have:

sound/soc/sof/core.c:           schedule_work(&sdev->probe_work);
sound/soc/sof/intel/ptl.c:      schedule_work(&hdev->mic_privacy.work);
Quoted 2 lines

Not sure what the rules are to define what's high-priority and what's not... It could be that different systems have different requirements...

Quoted 7 lines

I think the 'rule' is that what is time critical and what can tolerate a bit of a delay. The PCM period is time critical while the others are not that much, that includes the compress elapsed, it is not that real-time as the PCM.

But fair point, I will check if anything else would needs to be higher priority than what they are.

My point is that this change isn't bad in itself, but maybe some systems don't care and have other subsystems (graphics, networking, etc) that should be given preferred access to the high-priority queue.

Same for the SoundWire workqueues, one could argue that the command protocol overhead is significant for all the device initialization and firmware download. Using the higher priority queue could reduce the initial 'cold latency' for interactive sounds in a busy system.

Going back to the PCM stuff, the period_elapsed stuff is also not that relevant with timer-based scheduling which relies on snd_pcm_delay().

Could it be that the level of priority should be configurable (Kconfig, sysfs, kernel parameter) to let distros pick what they need?

author maintainer
#4 lore raw
Quoted 20 lines · Pierre-Louis Bossart
Quoted 20 lines
Quoted 7 lines

period-elapsed for compressed streams:
schedule_work(&spcm->stream[cstream->direction].period_elapsed_work);

and the SoundWire interrupt handling with additional workqueues:
schedule_work(&amd_manager->amd_sdw_irq_thread); schedule_work(&amd_manager->amd_sdw_work); schedule_work(&cdns->work);

we also have:

sound/soc/sof/core.c:           schedule_work(&sdev->probe_work);
sound/soc/sof/intel/ptl.c:      schedule_work(&hdev->mic_privacy.work);
Quoted 2 lines

Not sure what the rules are to define what's high-priority and what's not... It could be that different systems have different requirements...

I think the 'rule' is that what is time critical and what can tolerate a bit of a delay. The PCM period is time critical while the others are not that much, that includes the compress elapsed, it is not that real-time as the PCM.

Quoted 6 lines
Quoted 2 lines

But fair point, I will check if anything else would needs to be higher priority than what they are.

My point is that this change isn't bad in itself, but maybe some systems don't care and have other subsystems (graphics, networking, etc) that should be given preferred access to the high-priority queue.

That is possible, but on the other hand if that is the case then likely the kernel have been already modified to tailor for one way or the other.A device where network latency is the priority is likely have no audio needs.

Quoted 4 lines

Same for the SoundWire workqueues, one could argue that the command protocol overhead is significant for all the device initialization and firmware download. Using the higher priority queue could reduce the initial 'cold latency' for interactive sounds in a busy system.

I think this is true for every single device and software, everything is better if it can be faster but everything cannot be at the same time.

Quoted 2 lines

Going back to the PCM stuff, the period_elapsed stuff is also not that relevant with timer-based scheduling which relies on snd_pcm_delay().

In case of NO_PERIOD_WAKEUP the elapsed is not used, this helps in case when the period elapsed is used and user space uses that.

Quoted 2 lines

Could it be that the level of priority should be configurable (Kconfig, sysfs, kernel parameter) to let distros pick what they need?

I guess, it could, but what about the graphic, network, touchscreen, etc? Should they all have the same way to select?

I think audio is a bit special among devices, if there is a slight scheduling delay it will be noticeable.

Not saying that we should not look for other cases where it would make noticeable difference, but using high_pri workqueue is not uncommon among audio drivers where the period elapsed must be handled by a work for a reason.

Signature · 1 line
Péter
#5 lore raw
Quoted 7 lines
Quoted 3 lines

Could it be that the level of priority should be configurable (Kconfig, sysfs, kernel parameter) to let distros pick what they need?

I guess, it could, but what about the graphic, network, touchscreen, etc? Should they all have the same way to select?

Quoted 7 lines

I think audio is a bit special among devices, if there is a slight scheduling delay it will be noticeable.

Not saying that we should not look for other cases where it would make noticeable difference, but using high_pri workqueue is not uncommon among audio drivers where the period elapsed must be handled by a work for a reason.

if you do a search this workqueue is actually used only 10 times in the entire sound/ directory

https://github.com/search?q=repo%3Athesofproject%2Flinux+path%3Asound%2F+system_highpri_wq&type=code

Again I am not disagreeing that audio is 'special', just that there's no real precedent for this move and that deciding unilaterally what's high priority without looking at the rest of the system is a bit problematic.

Anyways, case closed since the patch is merged...

maintainer
#6 lore raw
In reply to Peter Ujfalusi
Quoted 1 line · Peter Ujfalusi

ASoC: SOF: Use high-priority workqueue for PCM period elapsed

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.3

Thanks!

[1/1] ASoC: SOF: Use high-priority workqueue for PCM period elapsed

      https://git.kernel.org/broonie/sound/c/ea1224da5d61

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark