Skip to content

ASoC: SOF: Add support for on-demand DSP boot for LNL+#5427

Merged
ujfalusi merged 7 commits intothesofproject:topic/sof-devfrom
ujfalusi:peter/sof/pr/on-demand-dsp-boot-01
Jun 10, 2025
Merged

ASoC: SOF: Add support for on-demand DSP boot for LNL+#5427
ujfalusi merged 7 commits intothesofproject:topic/sof-devfrom
ujfalusi:peter/sof/pr/on-demand-dsp-boot-01

Conversation

@ujfalusi
Copy link
Collaborator

@ujfalusi ujfalusi commented May 23, 2025

On system suspend / resume we always power up the DSP and boot the
firmware, which is not strictly needed as right after the firmware booted
up we power the DSP down again on suspend and we also power it down after
resume after some inactivity.

Out of caution, add a new platform descriptor flag to enable on-demand
DSP boot since this might not work without changes to platform code on
certain platforms.

With the on-demand dsp boot enabled we will not boot the DSP and firmware
up on system or rpm resume, just enable audio subsystem since audio IPs,
like HDA and SoundWire might be needed (codecs suspend/resume operation).
Only boot up the DSP during the first hw_params() call when the DSP is
really going to be needed.

In this way we can handle the audio related use cases:
normal audio use (rpm suspend/resume)
system suspend/resume without active audio
system suspend/resume with active audio
system suspend/resume without active audio, and audio start before the rpm
suspend timeout

Suspend resume is tested on LNL laptop with pm-graph/sleepgraph.py -rtcwake 15 -m freeze
Baseline (w/o active audio):
sof-audio-pci-intel-lnl @ 0000:00:1f.3 {sof-audio-pci-intel-lnl} (Total Suspend: 106.434 ms Total Resume: 157.955 ms)

With this PR, without active audio:
sof-audio-pci-intel-lnl @ 0000:00:1f.3 {sof-audio-pci-intel-lnl} (Total Suspend: 18.351 ms Total Resume: 31.468 ms)

With this PR, with active audio:
sof-audio-pci-intel-lnl @ 0000:00:1f.3 {sof-audio-pci-intel-lnl} (Total Suspend: 116.535 ms Total Resume: 32.763 ms)

@ujfalusi ujfalusi force-pushed the peter/sof/pr/on-demand-dsp-boot-01 branch from 5e7ebe3 to 5349348 Compare May 23, 2025 13:45
@ujfalusi
Copy link
Collaborator Author

Changes since v1:

  • no need to check the on demand flag in hw_parms(), we have state check for that

  • sof-probe client now works with on-demand DSP boot

  • IPC message injector is not yet, neither compressed

@ujfalusi ujfalusi force-pushed the peter/sof/pr/on-demand-dsp-boot-01 branch from 5349348 to f66c08e Compare May 26, 2025 06:26
@ujfalusi
Copy link
Collaborator Author

Changes since v2:

  • do a put module if the dsp boot returns with error in sof_client_core_module_get()

@ujfalusi ujfalusi force-pushed the peter/sof/pr/on-demand-dsp-boot-01 branch from f66c08e to 08107a4 Compare May 26, 2025 10:44
@ujfalusi ujfalusi changed the title [RFC] [DNM] ASoC: SOF: Add support for on-demand DSP boot for MTL+ ASoC: SOF: Add support for on-demand DSP boot for MTL+ May 26, 2025
@ujfalusi
Copy link
Collaborator Author

Changes since v3:

  • Cover corner case users to handle on-demand DSP boot mode: compressed, debug, ipc3-dtrace, client drivers.
  • Ready for review.

@ujfalusi ujfalusi marked this pull request as ready for review May 26, 2025 10:46
Copy link
Collaborator

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good, lot of helpful explanations in commit messages. There are a few sentences in commits had hard language to follow. No blockers on my side, but given the magnitude of change, I wonder if we should do a partial deployment of this change (made the same comment inline)?

@@ -323,6 +323,9 @@ static int mtl_dsp_post_fw_run(struct snd_sof_dev *sdev)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit is a bit hard to follow " must be enabled since ... they are only enabled" ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, what it is trying to say is that the interrupts on MTL are enabled as in step 4 of mtl_dsp_cl_init(), which is part of the firmware booting, but we need interrupts to be enabled for SDW/HDA to work, and since we don't boot the firmware, we need to do it on post fw run time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we inline comment this need to enable IRQs so its easier to follow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will drop the MTL support for now.

@dbaluta
Copy link
Collaborator

dbaluta commented May 26, 2025

@lgirdwood out of curiosity I wonder why this booting the firmware at system boot was needed. Beside a some sort of self-check at boot.

@ujfalusi
Copy link
Collaborator Author

@lgirdwood out of curiosity I wonder why this booting the firmware at system boot was needed. Beside a some sort of self-check at boot.

for self check, to be sure that the fw has the right key, to grab information about the booted firmware configuration and we are also placing it to IMR for faster bootup on consequent power ons.

Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re BRA - this should only be used for active codec use cases. i.e. we are streaming audio.

@shumingfan @charleskeepax do we always need to load codec FW for jack detect use cases ?

We should only need to power up codec and load codec FW when we have real streaming use cases otherwise at system resume we usually power up codec, load codec FW then after a few seconds enter RTD3 and power audio codec and DSP off again. i.e. a wasted effort transition if audio is inactive.

@@ -323,6 +323,9 @@ static int mtl_dsp_post_fw_run(struct snd_sof_dev *sdev)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we inline comment this need to enable IRQs so its easier to follow.

dev_warn(sdev->dev,
"warning: failed to init trace after resume %d\n",
ret);
dev_warn(sdev->dev, "%s: failed to resume trace%d\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a space is missing

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, will fix.

ret = tplg_ops->set_up_all_pipelines(sdev, false);
if (ret < 0) {
dev_err(sdev->dev, "Failed to restore pipeline after resume %d\n", ret);
dev_err(sdev->dev, "%s: failed to restore pipeline%d\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

* Make sure that the DSP is booted up, which might not be the
* case if the on-demand DSP boot is used
*/
ret = snd_sof_dsp_power_up(sdev, true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand it correctly, that currently powering up the DSP is a part of the (runtime) PM flow? I.e. is performed on some .resume() paths? And this commit makes additional locations like this one, which previously relied on the PM to bring up the DSP, do it explicitly now? Wouldn't it be possible and a better approach to keep the call as a part of the PM flow but just add a check in .resume() whether the DSP has to be booted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lyakh, currently we are powering up the audio subsystem and booting up the DSP firmware, they are hard-linked.

With this PR we can detach the DSP firmware boot from the audio subsystem power up.

I have already reworked this API, I will have snd_sof_boot_dsp_firmware(sdev); only as a function, in pm.c it is:

	if (sdev->pdata->desc->on_demand_dsp_boot) {
		/* Only change the fw_state to PREPARE but skip booting */
		sof_set_fw_state(sdev, SOF_FW_BOOT_PREPARE);
		return 0;
	}

	return snd_sof_boot_dsp_firmware(sdev);

for the resume.

@ujfalusi ujfalusi force-pushed the peter/sof/pr/on-demand-dsp-boot-01 branch from 08107a4 to 32dab67 Compare May 27, 2025 08:54
@ujfalusi
Copy link
Collaborator Author

Changes since v4:

  • Change the API from snd_sof_dsp_power_up(sdev, true); to snd_sof_boot_dsp_firmware(sdev);
  • Add protection for the DSP firmware boot to avoid possible races
  • Do not enable on-demand DSP boot for MTL (Only for LNL+)
  • Handle BRA also
  • Typos fixed

kv2019i
kv2019i previously approved these changes May 27, 2025
Copy link
Collaborator

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@kv2019i
Copy link
Collaborator

kv2019i commented May 27, 2025

@ujfalusi One export is missing though in the new BRA patch:
ERROR: modpost: "snd_sof_boot_dsp_firmware" [sound/soc/sof/intel/snd-sof-intel-hda-sdw-bpt.ko] undefined!

ujfalusi added 5 commits May 27, 2025 14:36
…_library

The initial library loading is happening during topology loading, which is
already protected with pm_runtime_resume_and_get() via pcm.c

The redundant rpm code can be dropped from sof_ipc4_load_library()

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
…nted

Test earlier for the existence of ext_volatile_get callback and if it is
missing, skip the rpm calls to avoid needles DSP power on.

No change in functionality, we just skip the DSP power on in the unlikely
case when the ext_volatile _get is not supported and yet the topology adds
such control.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
On system suspend / resume we always power up the DSP and boot the
firmware, which is not strictly needed as right after the firmware booted
up we power the DSP down again on suspend and we also power it down after
resume after some inactivity.

Out of caution, add a new platform descriptor flag to enable on-demand
DSP boot since this might not work without changes to platform code on
certain platforms.

With the on-demand dsp boot enabled we will not boot the DSP and firmware
up on system or rpm resume, just enable audio subsystem since audio IPs,
like HDA and SoundWire might be needed (codecs suspend/resume operation).
Only boot up the DSP during the first hw_params() call when the DSP is
really going to be needed.

In this way we can handle the audio related use cases:
normal audio use (rpm suspend/resume)
system suspend/resume without active audio
system suspend/resume with active audio
system suspend/resume without active audio, and audio start before the rpm
suspend timeout

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
With the introduction of on-demand DSP boot the rpm status not necessary
tells that the DSP firmware is booted up.

Introduce the sof_client_boot_dsp() which can be used to make sure that
the DSP is booted and it can handle IPCs.

Update the client drivers to use the new function where it is expected that
the DSP is booted up.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
If on-demand DSP boot is used we need to make sure that the DSP is booted
up - which might not be the case - since we need ChainDMA in normal, non
DSPless mode for the BRA to work.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
ujfalusi added 2 commits May 27, 2025 14:36
LNL can be used with on-demand DSP booting, set the flag to enable it.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
PTL and WCL can be used with on-demand DSP booting, set the flag to
enable it.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
@ujfalusi ujfalusi force-pushed the peter/sof/pr/on-demand-dsp-boot-01 branch from 32dab67 to e355d8a Compare May 27, 2025 11:37
@ujfalusi
Copy link
Collaborator Author

Changes since v5:

  • add missed EXPORT_SYMBOL

@ujfalusi ujfalusi changed the title ASoC: SOF: Add support for on-demand DSP boot for MTL+ ASoC: SOF: Add support for on-demand DSP boot for LNL+ May 27, 2025
Copy link
Collaborator

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@ranj063
Copy link
Collaborator

ranj063 commented May 28, 2025

@ujfalusi this PR is OK for now but I have a suggestion to make this a bit more elegant. How about we create a new auxiliary device for the DSP and use the runtime PM get/put functions to do the DSP boot or transition to D3 in those? That way instead of forcing the DSP to boot up, we can call the get/put to make sure that the DSP is booted when we need it in the params calls

@lgirdwood
Copy link
Member

@ujfalusi this PR is OK for now but I have a suggestion to make this a bit more elegant. How about we create a new auxiliary device for the DSP and use the runtime PM get/put functions to do the DSP boot or transition to D3 in those? That way instead of forcing the DSP to boot up, we can call the get/put to make sure that the DSP is booted when we need it in the params calls

We do have time here, so if aligned and this request can be done easily then pls proceed.

@ujfalusi
Copy link
Collaborator Author

@ujfalusi this PR is OK for now but I have a suggestion to make this a bit more elegant. How about we create a new auxiliary device for the DSP and use the runtime PM get/put functions to do the DSP boot or transition to D3 in those? That way instead of forcing the DSP to boot up, we can call the get/put to make sure that the DSP is booted when we need it in the params calls

The problem is that it will look even more hackish as we have an aux device which does nothing, but to traverse back to use sdev and the audio device to boot up the DSP and then to turn it off.

What would be the clean solution is to have the audio device as it is now, create the aux devices for DSP and the interfaces, give them the resources t hat they need in order to be operational and use these devices instead of the audio device.
So, if the DSP is requested to be on then we would boot it up, if sdw is needed, we enable it, etc.

This also means that the topology will not be loaded using the main sdev, but the auxdev of the DSP, this would traverse down to machine drivers, sdw stack, and other places as the device is no longer the audio device, but an auxdevice.

I'm not sure if hacking an auxdevice to hook back to the main device is cleaner than an API which does this.
It would be useful of the auxdev is used for the component and rely on ASoC to keep what's needed to be powered, but that would mean that we boot the DSP on resume likely.

While I think it would be great to do this, I honestly think that it will take a better part of the rest of the year to get it somehow right and then we have not even considered the vendors using SOF...

@lgirdwood
Copy link
Member

While I think it would be great to do this, I honestly think that it will take a better part of the rest of the year to get it somehow right and then we have not even considered the vendors using SOF...

ok, if this is big then lets keep backport effort low.

@ujfalusi
Copy link
Collaborator Author

While I think it would be great to do this, I honestly think that it will take a better part of the rest of the year to get it somehow right and then we have not even considered the vendors using SOF...

ok, if this is big then lets keep backport effort low.

I think it is rather big, but I still think it worth a look in the medium to long run.

@ujfalusi
Copy link
Collaborator Author

Let's merge this for now to give broader testing

@ujfalusi ujfalusi merged commit 80c0814 into thesofproject:topic/sof-dev Jun 10, 2025
8 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants