Skip to content

ASoC: SOF: sof-pci-dev: use snd_sof_suspend in shutdown callback - #2768

Merged
plbossart merged 5 commits into
thesofproject:topic/sof-devfrom
libinyang:shutdown
Mar 12, 2021
Merged

plbossart merged 5 commits into
thesofproject:topic/sof-devfrom
libinyang:shutdown

Conversation

@libinyang

Copy link
Copy Markdown

According to hardware spec and PMC FW requirment, the DSP must be
in D3 state before entering S5. use sof_suspend as shutdown callback
here to make sure DSP is in D3 state

Signed-off-by: Pan Xiuli xiuli.pan@linux.intel.com
Signed-off-by: Libin Yang libin.yang@intel.com

@libinyang

Copy link
Copy Markdown
Author

This is the patch I refined based on the latest kernel. The patch, we gave IoTG, just called snd_sof_suspend(&pci->dev);
It seems better to set sdev->system_suspend_target in the latest kernel?

And maybe we still need to refine this patch to call ops->shutdown() of platforms as the platforms requirement of shutdown is different.

Comment thread sound/soc/sof/sof-pci-dev.c Outdated

/* audio need to enter D3 before shutdown */
sdev->system_suspend_target = SOF_SUSPEND_S3;
snd_sof_suspend(&pci->dev);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this has to be platform-specific. We cant apply this blanket rule for all platforms. What platforms have this requirement btw?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

and also the commit message and the target state are inconsistent. You talk about S5 in commit message and set the target to S3? Out of curiosity, why isnt hda_dsp_remove() like what we do in the shutdown callback for TGL not enough?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

hda_dsp_remove() is not enough based on IoTG's dump. Generally, they asked all devices are in the D3 state when the system state is in S5. From the the debug, they found there are still some registers not meeting the requirement. Maybe we can simply the sequence if customers complain the latency is too long.

@lyakh

lyakh commented Feb 26, 2021

Copy link
Copy Markdown
Collaborator

travis caught a typo in the commit message :-)

Comment thread sound/soc/sof/sof-pci-dev.c Outdated

/* audio need to enter D3 before shutdown */
sdev->system_suspend_target = SOF_SUSPEND_S3;
snd_sof_suspend(&pci->dev);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

NAK, we added a platform-specific callback that you removed, so you just killed what @keyonjie added in January.
You guys are in the same timezone, can you please talk with each other?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

NAK, we added a platform-specific callback that you removed, so you just killed what @keyonjie added in January.
You guys are in the same timezone, can you please talk with each other?

Yes, @libinyang if we decide to change this to a generic solution for all platforms, we need to remove the platform specific ones, let's have a talk about this.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

NAK, we added a platform-specific callback that you removed, so you just killed what @keyonjie added in January.
You guys are in the same timezone, can you please talk with each other?

Yes, @libinyang if we decide to change this to a generic solution for all platforms, we need to remove the platform specific ones, let's have a talk about this.

@plbossart @keyonjie OK. I will talk with @keyonjie what to make the patch more reasonable and acceptable.

@libinyang

Copy link
Copy Markdown
Author

travis caught a typo in the commit message :-)

@lyakh Thanks for reminder. Will fix it in next version.

@libinyang

Copy link
Copy Markdown
Author

Patch is updated to define the shutdown process in the specific platform driver.

@kv2019i kv2019i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we should apply the shutdown change to all Intel HDA platforms. The second patch looks good.

Comment thread sound/soc/sof/intel/tgl.c Outdated
.probe = hda_dsp_probe,
.remove = hda_dsp_remove,
.shutdown = hda_dsp_remove,
.shutdown = tgl_shutdown,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

While this may not cause problems on all HDA platforms, I think we should apply this logic to all HDA platforms and define this as hda_dsp_shutdown. snd-hda-intel calls stop_chip() on all generations in its shutdown() (essentially puts the controller to D3-like state)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

agree with Kai, this makes no sense to me, this should be common to all platforms, and we need to check what happens if the probe failed in the first place.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@libinyang have you tested it on the TGL chrome device wth WoV enabled? Is D0i3 -> D3 a valid transition in our state machine?

@plbossart plbossart Mar 4, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it is absolutely not valid, we have to go back to D0 before going to D3

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@libinyang I get the feeling that calling suspend() in shutdown is not the right thing to do here. We cannot guarantee the state machine transition will be valid in all cases.

I asked this previously too. We need to figure out what is missing in hda_dsp_remove() compared to hda_suspend(). Maybe it is something as simple as the controller reset and add it to hda_dsp_remove(). Can you please check?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@plbossart Why release of PCI resources? See my point above, I don't think this is a S5 requirement.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@kv2019i well, it's either the same as suspend or same as remove. it seems we can't figure out what the actual requirement is...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@plbossart :) well that's exactly what I tried to clarify above. The spec only states S5 should be same as S4, so this is all about suspend and no linkage to remove. Unless anyone can point me to a spec, I'll be sticking to this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@kv2019i you may be right at the spec level, I don't see in the Linux code any reference to the parent-child model that's used for suspend. In theory if we followed the suspend model we would call .shutdown on the children before moving up the parents, but I don't see that code. When we used the aux bus for SoundWire, the use of .shutdown led to a device getting stuck, and we could never figure out why. So there is still some voodoo logic that we haven't understood somewhere in the kernel.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@plbossart dsp_remove() is used in module removal. It's a software conception. We need to release pci resource in module remove. This is because we may reload the kernel modules without reboot. In this case, we must make sure these resource are not occupied. But for shutdown, we don't need to release these resource, because after reboot all the resource will automatically released. I think it may be OK to add the PCI resource release. But this action is not required from HW. HW team only requires driver to enter D3. I'm not sure PCI level's action when we release PCI resource. If PCI make some PCI clock or power switching when PCI resource release, this may be not acceptable by HW.

Comment thread sound/soc/sof/intel/pci-tgl.c Resolved
Comment thread sound/soc/sof/intel/pci-tgl.c Resolved
Comment thread sound/soc/sof/intel/tgl.c Outdated
.probe = hda_dsp_probe,
.remove = hda_dsp_remove,
.shutdown = hda_dsp_remove,
.shutdown = tgl_shutdown,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

agree with Kai, this makes no sense to me, this should be common to all platforms, and we need to check what happens if the probe failed in the first place.

lyakh
lyakh previously approved these changes Mar 10, 2021
keyonjie
keyonjie previously approved these changes Mar 10, 2021

@keyonjie keyonjie left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good to me.

@kv2019i kv2019i changed the title [RFC] ASoC: SOF: sof-pci-dev: use snd_sof_suspend in shutdown callback ASoC: SOF: sof-pci-dev: use snd_sof_suspend in shutdown callback Mar 10, 2021

@kv2019i kv2019i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, looks good @libinyang I removed the "RFC" from PR title so people understand this is intended to be merged.

Could you add the fixes tag to the commit fixing tgl_ops for EHL? Otherwise this is good to go.

Comment thread sound/soc/sof/intel/cnl.c Resolved
Comment thread sound/soc/sof/intel/pci-tgl.c Resolved
Comment thread sound/soc/sof/intel/tgl.c Resolved
Comment thread sound/soc/sof/intel/pci-tgl.c Resolved
Comment thread sound/soc/sof/intel/pci-tgl.c Resolved
@libinyang

Copy link
Copy Markdown
Author

Thanks, looks good @libinyang I removed the "RFC" from PR title so people understand this is intended to be merged.

Could you add the fixes tag to the commit fixing tgl_ops for EHL? Otherwise this is good to go.

@kv2019i Thanks! @plbossart mentioned the fixes tag and I misunderstood the fixes tag. I will this fixes tag in my updated patches.
btw: I found some fixes tags in SOF patches are using 13 characters of the SHA-1 ID. Based on the kernel document submitting-patches, it requires 12 characters.

ranj063
ranj063 previously approved these changes Mar 11, 2021

@ranj063 ranj063 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM now. Thanks @libinyang

@plbossart plbossart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good but minor changes needed to make it cleaner for upstream

Comment thread sound/soc/sof/intel/tgl.c Resolved
According to hardware spec and PMC FW requirement, the DSP must be
in D3 state before entering S5. Define the shutdown function to use
snd_sof_suspend as shutdown callback to make sure DSP is in D3 state.

Fixes: 44a4cfa ("ASoC: SOF: Intel: tgl: do thorough remove at .shutdown() callback")
Signed-off-by: Pan Xiuli <xiuli.pan@linux.intel.com>
Signed-off-by: Libin Yang <libin.yang@intel.com>
According to hardware spec and PMC FW requirement, the DSP must be
in D3 state before entering S5. Set shutdown call to hda_dsp_shutdown.

Signed-off-by: Libin Yang <libin.yang@intel.com>
According to hardware spec and PMC FW requirement, the DSP must be
in D3 state before entering S5. Set shutdown call to hda_dsp_shutdown.

Signed-off-by: Libin Yang <libin.yang@intel.com>
According to hardware spec and PMC FW requirement, the DSP must be
in D3 state before entering S5. Set shutdown call to hda_dsp_shutdown.

Signed-off-by: Libin Yang <libin.yang@intel.com>
EHL is derived from TGL, not CNL, so we shall use the TGL ops.

Fixes: 8d4ba1b ("ASoC: SOF: pci: split PCI into different drivers")
Signed-off-by: Libin Yang <libin.yang@intel.com>
@plbossart

Copy link
Copy Markdown
Member

@kv2019i 's comments were addressed so let's merge to see if the results improve our daily tests.

@plbossart
plbossart merged commit 578778f into thesofproject:topic/sof-dev Mar 12, 2021
@kv2019i

kv2019i commented Mar 12, 2021

Copy link
Copy Markdown
Collaborator

Thanks @libinyang , looks good!

oder-chiou pushed a commit to oder-chiou/linux-soundwire that referenced this pull request May 5, 2026
Verifier log avoids printing the same source code line multiple times
when a consecutive block of BPF assembly instructions are covered by the
same original (C) source code line. This greatly improves verifier log
legibility.

Unfortunately, this check is imperfect and in production applications it
quite often happens that verifier log will have multiple duplicated
source lines emitted, for no apparently good reason. E.g., this is
excerpt from a real-world BPF application (with register states omitted
for clarity):

BEFORE
======
; for (int i = 0; i < STROBE_MAX_MAP_ENTRIES; ++i) { @ strobemeta_probe.bpf.c:394
5369: (07) r8 += 2                    ;
5370: (07) r7 += 16                   ;
; for (int i = 0; i < STROBE_MAX_MAP_ENTRIES; ++i) { @ strobemeta_probe.bpf.c:394
5371: (07) r9 += 1                    ;
5372: (79) r4 = *(u64 *)(r10 -32)     ;
; for (int i = 0; i < STROBE_MAX_MAP_ENTRIES; ++i) { @ strobemeta_probe.bpf.c:394
5373: (55) if r9 != 0xf goto pc+2
; if (i >= map->cnt) @ strobemeta_probe.bpf.c:396
5376: (79) r1 = *(u64 *)(r10 -40)     ;
5377: (79) r1 = *(u64 *)(r1 +8)       ;
; if (i >= map->cnt) @ strobemeta_probe.bpf.c:396
5378: (dd) if r1 s<= r9 goto pc-5     ;
; descr->key_lens[i] = 0; @ strobemeta_probe.bpf.c:398
5379: (b4) w1 = 0                     ;
5380: (6b) *(u16 *)(r8 -30) = r1      ;
; task, data, off, STROBE_MAX_STR_LEN, map->entries[i].key); @ strobemeta_probe.bpf.c:400
5381: (79) r3 = *(u64 *)(r7 -8)       ;
5382: (7b) *(u64 *)(r10 -24) = r6     ;
; task, data, off, STROBE_MAX_STR_LEN, map->entries[i].key); @ strobemeta_probe.bpf.c:400
5383: (bc) w6 = w6                    ;
; barrier_var(payload_off); @ strobemeta_probe.bpf.c:280
5384: (bf) r2 = r6                    ;
5385: (bf) r1 = r4                    ;

As can be seen, line 394 is emitted thrice, 396 is emitted twice, and
line 400 is duplicated as well. Note that there are no intermingling
other lines of source code in between these duplicates, so the issue is
not compiler reordering assembly instruction such that multiple original
source code lines are in effect.

It becomes more obvious what's going on if we look at *full* original line info
information (using btfdump for this, [0]):

  thesofproject#2764: line: insn thesofproject#5363 --> 394:3 @ ./././strobemeta_probe.bpf.c
            for (int i = 0; i < STROBE_MAX_MAP_ENTRIES; ++i) {
  thesofproject#2765: line: insn thesofproject#5373 --> 394:21 @ ./././strobemeta_probe.bpf.c
            for (int i = 0; i < STROBE_MAX_MAP_ENTRIES; ++i) {
  thesofproject#2766: line: insn thesofproject#5375 --> 394:47 @ ./././strobemeta_probe.bpf.c
            for (int i = 0; i < STROBE_MAX_MAP_ENTRIES; ++i) {
  thesofproject#2767: line: insn thesofproject#5377 --> 394:3 @ ./././strobemeta_probe.bpf.c
            for (int i = 0; i < STROBE_MAX_MAP_ENTRIES; ++i) {
  thesofproject#2768: line: insn thesofproject#5378 --> 414:10 @ ./././strobemeta_probe.bpf.c
            return off;

We can see that there are four line info records covering
instructions thesofproject#5363 through thesofproject#5377 (instruction indices are shifted due to
subprog instruction being appended to main program), all of them are
pointing to the same C source code line thesofproject#394. But each of them points to
a different part of that line, which is denoted by differing column
numbers (3, 21, 47, 3).

But verifier log doesn't distinguish between parts of the same source code line
and doesn't emit this column number information, so for end user it's just a
repetitive visual noise. So let's improve the detection of repeated source code
line and avoid this.

With the changes in this patch, we get this output for the same piece of BPF
program log:

AFTER
=====
; for (int i = 0; i < STROBE_MAX_MAP_ENTRIES; ++i) { @ strobemeta_probe.bpf.c:394
5369: (07) r8 += 2                    ;
5370: (07) r7 += 16                   ;
5371: (07) r9 += 1                    ;
5372: (79) r4 = *(u64 *)(r10 -32)     ;
5373: (55) if r9 != 0xf goto pc+2
; if (i >= map->cnt) @ strobemeta_probe.bpf.c:396
5376: (79) r1 = *(u64 *)(r10 -40)     ;
5377: (79) r1 = *(u64 *)(r1 +8)       ;
5378: (dd) if r1 s<= r9 goto pc-5     ;
; descr->key_lens[i] = 0; @ strobemeta_probe.bpf.c:398
5379: (b4) w1 = 0                     ;
5380: (6b) *(u16 *)(r8 -30) = r1      ;
; task, data, off, STROBE_MAX_STR_LEN, map->entries[i].key); @ strobemeta_probe.bpf.c:400
5381: (79) r3 = *(u64 *)(r7 -8)       ;
5382: (7b) *(u64 *)(r10 -24) = r6     ;
5383: (bc) w6 = w6                    ;
; barrier_var(payload_off); @ strobemeta_probe.bpf.c:280
5384: (bf) r2 = r6                    ;
5385: (bf) r1 = r4                    ;

All the duplication is gone and the log is cleaner and less distracting.

  [0] https://github.com/anakryiko/btfdump

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20240214174100.2847419-1-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
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.

6 participants