Skip to content

Commit

Permalink
kernel: idle: clock switch refactor
Browse files Browse the repository at this point in the history
This patch cleans-up and refactoring correct implementation of clock
switching in idle thread.

Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
  • Loading branch information
tmleman committed Oct 16, 2023
1 parent c48d98d commit 4537cc5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
17 changes: 7 additions & 10 deletions kernel/idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <zephyr/drivers/timer/system_timer.h>
#include <zephyr/wait_q.h>
#include <zephyr/pm/pm.h>
#include <zephyr/pm/policy.h>
#include <stdbool.h>
#include <zephyr/logging/log.h>
#include <ksched.h>
Expand Down Expand Up @@ -65,12 +66,6 @@ void idle(void *unused1, void *unused2, void *unused3)

#ifdef CONFIG_PM
_kernel.idle = z_get_next_timeout_expiry();
#if CONFIG_SOC_SERIES_INTEL_ACE
(void)atomic_inc(&_cpus_idleing);
if (_cpus_idleing == _cpus_active)
adsp_clock_idle_entry();
#endif

/*
* Call the suspend hook function of the soc interface
* to allow entry into a low power state. The function
Expand All @@ -87,14 +82,16 @@ void idle(void *unused1, void *unused2, void *unused3)
* logic.
*/
if (k_is_pre_kernel() || !pm_system_suspend(_kernel.idle)) {
#if CONFIG_SOC_SERIES_INTEL_ACE
pm_policy_state_lock_put(PM_STATE_ACTIVE, 1);
adsp_clock_idle_entry();
#endif
k_cpu_idle();
}
#if CONFIG_SOC_SERIES_INTEL_ACE
if (_cpus_idleing == _cpus_active)
pm_policy_state_lock_get(PM_STATE_ACTIVE, 1);
adsp_clock_idle_exit();

(void)atomic_dec(&_cpus_idleing);
#endif
}
#else
k_cpu_idle();
#endif
Expand Down
3 changes: 0 additions & 3 deletions kernel/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ struct z_kernel _kernel;
__pinned_bss
atomic_t _cpus_active;

__pinned_bss
atomic_t _cpus_idleing;

/* init/main and idle threads */
K_THREAD_PINNED_STACK_DEFINE(z_main_stack, CONFIG_MAIN_STACK_SIZE);
struct k_thread z_main_thread;
Expand Down
2 changes: 0 additions & 2 deletions soc/xtensa/intel_adsp/ace/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ void pm_state_set(enum pm_state state, uint8_t substate_id)
/* save interrupt state and turn off all interrupts */
core_desc[cpu].intenable = XTENSA_RSR("INTENABLE");
z_xt_ints_off(0xffffffff);
(void)atomic_dec(&_cpus_idleing);

if (state == PM_STATE_SOFT_OFF) {
core_desc[cpu].bctl = DSPCS.bootctl[cpu].bctl;
Expand Down Expand Up @@ -369,7 +368,6 @@ void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
__ASSERT(false, "invalid argument - unsupported power state");
}

(void)atomic_inc(&_cpus_idleing);
z_xt_ints_on(core_desc[cpu].intenable);
}

Expand Down

0 comments on commit 4537cc5

Please sign in to comment.