Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intel_adsp: Fix interruption locks in power management code #67863

Merged
merged 2 commits into from
Jan 30, 2024

Conversation

ceolin
Copy link
Member

@ceolin ceolin commented Jan 20, 2024

Interruptions must be locked until pm_state_exit_post_ops.

dcpleung
dcpleung previously approved these changes Jan 22, 2024
@ceolin ceolin added the DNM This PR should not be merged (Do Not Merge) label Jan 23, 2024
@ceolin
Copy link
Member Author

ceolin commented Jan 23, 2024

Putting DNM label because I found issues in save/restore context path (not caused by this pr) that makes the atomic idle does not work.

@ceolin ceolin removed the DNM This PR should not be merged (Do Not Merge) label Jan 23, 2024
@ceolin
Copy link
Member Author

ceolin commented Jan 23, 2024

DNM removed :)

@tmleman can you take a look please ?

softwarecki
softwarecki previously approved these changes Jan 23, 2024
@@ -144,6 +144,7 @@ static ALWAYS_INLINE void _restore_core_context(void)
XTENSA_WSR("EXCSAVE2", core_desc[core_id].excsave2);
XTENSA_WSR("EXCSAVE3", core_desc[core_id].excsave3);
XTENSA_WUR("THREADPTR", core_desc[core_id].thread_ptr);
__asm__ volatile("wsr.intenable %0" : : "r"(0x00000000));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This step is redundant; the register is cleared in the cpu_early_init procedure.

Copy link
Member Author

Choose a reason for hiding this comment

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

yep. Thanks for pointing it.

@@ -173,7 +174,6 @@ void power_gate_entry(uint32_t core_id)
soc_cpus_active[core_id] = false;
sys_cache_data_flush_range(soc_cpus_active, sizeof(soc_cpus_active));
k_cpu_idle();
z_xt_ints_off(0xffffffff);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's true that after power gating, we are not going back here, but we can't guarantee that power gating will happen. If it's not causing any problems, I would recommend keeping it.

Copy link
Member Author

Choose a reason for hiding this comment

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

why can't we guarantee ? I am asking because I thought this was deterministic, if it is not I will check the workflow with this possibility in mind (obviously just keeping it here is ok ...)

Copy link
Collaborator

Choose a reason for hiding this comment

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

The idea of disabling interrupts as a step after WAITI is taken from the reference code. There is no detailed explanation of what exactly can prevent power gating in that case. I think the apprehension about this arises from the fact that firmware does not have full control over all hardware prevents. For example, the HOST can prevent the DSP HP domain from its side without any interaction with firmware.

Comment on lines +410 to +414

/* We don't have the key used to lock interruptions here.
* Just set PS.INTLEVEL to 0.
*/
__asm__ volatile ("rsil a2, 0");
Copy link
Collaborator

Choose a reason for hiding this comment

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

This commit should be part of the previous one. Without restoring the PS value, PS.INTLEVEL == 0

Copy link
Member Author

Choose a reason for hiding this comment

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

I can squash them.

Flavio Ceolin added 2 commits January 23, 2024 21:40
We are arbitrarily setting a value to PS after power gates and
losing valid information like OWB, CALLINC and INTLEVEL.

We need to properly save/restore them to avoid possible wrong behavior.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
In pm_state_set we can't just call k_cpu_idle() because
this will clear out PS.INTLEVEL. Use k_cpu_atomic_idle instead
since Zephyr's expect interruptions to be locked after pm_state_set.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
@tmleman
Copy link
Collaborator

tmleman commented Jan 24, 2024

@RanderWang can you take a look at the changes for CAVS?

Copy link
Contributor

@RanderWang RanderWang left a comment

Choose a reason for hiding this comment

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

LGTM. Tested on TGL

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.

Tested on Intel ACE ADSP, without this patch I get a Zephyr panic on system resume, fixed by this PR.

@MaureenHelm MaureenHelm merged commit 3e5a593 into zephyrproject-rtos:main Jan 30, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: Intel ADSP Intel Audio platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants