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

drivers: intel_adsp: IPC driver uses D3 power state #56168

Merged
merged 4 commits into from
Jun 22, 2023

Conversation

aborisovich
Copy link
Collaborator

@aborisovich aborisovich commented Mar 24, 2023

This PR enables suspend/resume of the Intel ADSP IPC driver using Zephyr Power Manager Device API.
Options are enabled when CONFIG_PM_DEVICE=y.
New power control API performs hardware reinitialization after wake from D3 power state (PM_DEVICE_ACTION_SUSPEND):

  • enabled interrupts
  • resets register state to accept new messages
  • allows to register callbacks to Zephyr application that may perform additional actions

Consists of 4 commits (2 main commits and two dependent):

  1. Commit 2ea0d25 sets up Power Manager calls for IPC driver
  2. Commit fa839a9 adds returned error codes to IPC functions, returning -EBUSY when Device is during power transition.
  3. Commit fc367d4 allows system timer re-initialization - this commit is needed to resume system from low power state.
  4. Commit 8dcac84 allows to re-initialize memory window - this commit is also needed to complete IPC messages correctly after waking up from D3.

Blocked by bug:

Signed-off-by: Andrey Borisovich andrey.borisovich@intel.com

jxstelter
jxstelter previously approved these changes Mar 28, 2023
soc/xtensa/intel_adsp/ace/power.c Outdated Show resolved Hide resolved
soc/xtensa/intel_adsp/ace/power.c Outdated Show resolved Hide resolved
soc/xtensa/intel_adsp/common/include/intel_adsp_ipc.h Outdated Show resolved Hide resolved
mem_win_init(DEVICE_DT_GET(MEM_WINDOW_NODE(0)));
mem_win_init(DEVICE_DT_GET(MEM_WINDOW_NODE(1)));
mem_win_init(DEVICE_DT_GET(MEM_WINDOW_NODE(2)));
mem_win_init(DEVICE_DT_GET(MEM_WINDOW_NODE(3)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

0-1-2-3 From where come that numbers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From Devicetree instance API.
I've checked all .dtsi files from dts\xtensa\intel\ directory.
All boards have 4 memory_window instances.

@aborisovich
Copy link
Collaborator Author

@nashif, @ceolin please review

{
if (k_is_in_isr()) {
return -ESRCH;
}
Copy link
Member

Choose a reason for hiding this comment

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

Do you really need this ??

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, you started a subject on TOCTOU race and did not answer my question... Please read my comments above.

Copy link
Member

Choose a reason for hiding this comment

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

Nope, it does not solve it. If you have two threads that call pm_device_action_run() is possible that both threads pass the check pm_device_state_is_locked() and both ends up calling ipc_pm_action and in that case you don't know exactly what will happen. That is a problem that device_runtime solves, pm_device_state_lock() was not thought to be used this way (though there is nothing disallowing it). It was simply not thought.

My suggestion is to remove it for now (since is not really protecting) and ensure that you are calling it from a safe context. I will probably change pm_device_lock() to return a boolean and fails when the device state is already locked and you can use here it and that will probably be a solution.

Does it work for you ?

Copy link
Member

@ceolin ceolin left a comment

Choose a reason for hiding this comment

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

Look inline comments please.

@aborisovich
Copy link
Collaborator Author

aborisovich commented Jun 14, 2023

Addressed @ceolin issues except 1 where I am not sure how to proceed.
@ceolin can you please elaborate on TACTOU race you mentioned and my comments on ISR?
Tests are passing now, submitted full scope and waiting for results.

@ceolin
Copy link
Member

ceolin commented Jun 20, 2023

@aborisovich please fix the return error code information that I commented and if you agree just drop that check if it is from ISR (though I won't block this commit if you decided to keep that).

Once you fix that error code mismatch it is good to me.

@aborisovich
Copy link
Collaborator Author

Push update - addressed @ceolin issues found:

  • fixed return codes (-ESHUTDOWN is used where it should).
  • removed check k_is_in_isr() from the ipc_pm_action along with the documentation that the action is not supported in ISR.

@aborisovich aborisovich requested review from ceolin and tmleman and removed request for pjdobrowolski and tmleman June 20, 2023 09:53
@tmleman
Copy link
Collaborator

tmleman commented Jun 21, 2023

@aborisovich SOF CI looks good thesofproject/sof#7325. How did our internal full scope tests go?

Andrey Borisovich added 4 commits June 21, 2023 10:31
Generic header for system clock allows to define a sys_clock_idle_exit
function for the clock implementation.
Implemented the function in the intel_adsp_timer to reinitialize
device driver after the idle exit state.

Signed-off-by: Andrey Borisovich <andrey.borisovich@intel.com>
Exiting idle state requires to reinitialize all memory window
instances to flush the cached memory.
Added function that calls initialization of devices during runtime.

Signed-off-by: Andrey Borisovich <andrey.borisovich@intel.com>
When option CONFIG_PM_DEVICE is enabled, IPC driver is capable
of entering D3 power state described as PM_DEVICE_ACTION_SUSPEND
(and leaving that state - powering back to PM_DEVICE_ACTION_ACTIVE).
New power control callbacks 'ipc_power_control_api' are introduced for
use during power state transisions. They allow Zephyr application
specific code to be executed.

Signed-off-by: Andrey Borisovich <andrey.borisovich@intel.com>
When CONFIG_PM_DEVICE is enabled IPC Device may be during power transition
during a call to intel_adsp_ipc_send_message function.
Changed signatures of intel_adsp_ipc_send_message and its sync version
to return int and negative error codes on error.
On attempt to send IPC message during Device power transition
-ESHUTDOWN error code is returned, on busy state -EBUSY.
Updated all function references.

Signed-off-by: Andrey Borisovich <andrey.borisovich@intel.com>
@aborisovich
Copy link
Collaborator Author

aborisovich commented Jun 21, 2023

Rebased to newest Zephyr main.

@aborisovich SOF CI looks good thesofproject/sof#7325. How did our internal full scope tests go?

We have improvement of ~1.5% passrate.
New tests passing:
hda_codec_loopback_rtd3 ✔️
channel_remapping_mode_dynamic ✔️
mixers_max_inputs ✔️
cpa_toggle_without_fw_logs ✔️
Other D3 related tests are passing too.
There is regression in 1 test:
load_fw_stress_graceful_shutdown
I'll investigate on which iteration we have failures.
I'll restart full scope tests today with just done rebase.

@aborisovich
Copy link
Collaborator Author

aborisovich commented Jun 22, 2023

Last run after Zephyr main rebase gave us ~3% passrate improvement.
Comparing to previous run, new tests started to pass:
ace_generic_dmic ✔️
ace_raw_capture ✔️
kd_topology_dmic ✔️
Previously run test passed now:
load_fw_stress_graceful_shutdown ❌ -> ✔️
Unfortunately, some of the:
hda_codec_loopback_rtd3 tests failed with audio glitches after D3.
What keeps me wonder is why only the half of the tests in this group failed and second half passed...
Anyway, even if those are unstable for some reason, core D3 tests are passing so I would merge this and look for the causes later.

@nashif nashif merged commit 23b3cae into zephyrproject-rtos:main Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: IPM Inter-Processor Mailbox area: Logging area: Timer Timer platform: Intel ADSP Intel Audio platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.