pm: policy: Add cpu information in the API
On multicore environments the policy may need to know which CPU is
idle.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
diff --git a/include/pm/policy.h b/include/pm/policy.h
index 59cb02b..86c5ef0 100644
--- a/include/pm/policy.h
+++ b/include/pm/policy.h
@@ -22,11 +22,12 @@
* idle and returns the most appropriate state based on the number of
* ticks to the next event.
*
+ * @param cpu CPU index.
* @param ticks The number of ticks to the next scheduled event.
*
- * @return The power state the system should use.
+ * @return The power state the system should use for the given cpu.
*/
-struct pm_state_info pm_policy_next_state(int32_t ticks);
+struct pm_state_info pm_policy_next_state(uint8_t cpu, int32_t ticks);
/** @endcond */
diff --git a/subsys/pm/policy/policy_dummy.c b/subsys/pm/policy/policy_dummy.c
index f9d6e65..8d2b7af 100644
--- a/subsys/pm/policy/policy_dummy.c
+++ b/subsys/pm/policy/policy_dummy.c
@@ -18,12 +18,14 @@
static const struct pm_state_info pm_dummy_states[] =
PM_STATE_INFO_DT_ITEMS_LIST(DT_NODELABEL(cpu0));
-struct pm_state_info pm_policy_next_state(int32_t ticks)
+struct pm_state_info pm_policy_next_state(uint8_t cpu, int32_t ticks)
{
static struct pm_state_info cur_pm_state_info;
int i = (int)cur_pm_state_info.state;
uint8_t states_len = ARRAY_SIZE(pm_dummy_states);
+ ARG_UNUSED(cpu);
+
if (states_len == 0) {
/* No power states to go through. */
return STATE_ACTIVE;
diff --git a/subsys/pm/policy/policy_residency.c b/subsys/pm/policy/policy_residency.c
index d200fb3..b4083f8 100644
--- a/subsys/pm/policy/policy_residency.c
+++ b/subsys/pm/policy/policy_residency.c
@@ -16,10 +16,12 @@
static const struct pm_state_info pm_min_residency[] =
PM_STATE_INFO_DT_ITEMS_LIST(DT_NODELABEL(cpu0));
-struct pm_state_info pm_policy_next_state(int32_t ticks)
+struct pm_state_info pm_policy_next_state(uint8_t cpu, int32_t ticks)
{
int i;
+ ARG_UNUSED(cpu);
+
for (i = ARRAY_SIZE(pm_min_residency) - 1; i >= 0; i--) {
uint32_t min_residency, exit_latency;
diff --git a/subsys/pm/power.c b/subsys/pm/power.c
index e07b556..cb9fbf9 100644
--- a/subsys/pm/power.c
+++ b/subsys/pm/power.c
@@ -272,7 +272,7 @@
uint8_t id = _current_cpu->id;
SYS_PORT_TRACING_FUNC_ENTER(pm, system_suspend, ticks);
- z_power_states[id] = pm_policy_next_state(ticks);
+ z_power_states[id] = pm_policy_next_state(id, ticks);
if (z_power_states[id].state == PM_STATE_ACTIVE) {
LOG_DBG("No PM operations done.");
SYS_PORT_TRACING_FUNC_EXIT(pm, system_suspend, ticks,
diff --git a/tests/kernel/profiling/profiling_api/src/main.c b/tests/kernel/profiling/profiling_api/src/main.c
index 0d5ed8c..b82d425 100644
--- a/tests/kernel/profiling/profiling_api/src/main.c
+++ b/tests/kernel/profiling/profiling_api/src/main.c
@@ -23,10 +23,12 @@
}
/* Our PM policy handler */
-struct pm_state_info pm_policy_next_state(int32_t ticks)
+struct pm_state_info pm_policy_next_state(uint8_t cpu, int32_t ticks)
{
static bool test_flag;
+ ARG_UNUSED(cpu);
+
/* Call k_thread_foreach only once otherwise it will
* flood the console with stack dumps.
*/
diff --git a/tests/subsys/pm/device_wakeup_api/src/main.c b/tests/subsys/pm/device_wakeup_api/src/main.c
index ff96c9b..54e4348 100644
--- a/tests/subsys/pm/device_wakeup_api/src/main.c
+++ b/tests/subsys/pm/device_wakeup_api/src/main.c
@@ -57,8 +57,10 @@
irq_unlock(0);
}
-struct pm_state_info pm_policy_next_state(int32_t ticks)
+struct pm_state_info pm_policy_next_state(uint8_t cpu, int32_t ticks)
{
+ ARG_UNUSED(cpu);
+
while (sleep_count < 3) {
sleep_count++;
return (struct pm_state_info){PM_STATE_SUSPEND_TO_RAM, 0, 0, 0};
diff --git a/tests/subsys/pm/power_mgmt/src/main.c b/tests/subsys/pm/power_mgmt/src/main.c
index 5282c79..6bc6799 100644
--- a/tests/subsys/pm/power_mgmt/src/main.c
+++ b/tests/subsys/pm/power_mgmt/src/main.c
@@ -57,10 +57,12 @@
}
/* Our PM policy handler */
-struct pm_state_info pm_policy_next_state(int ticks)
+struct pm_state_info pm_policy_next_state(uint8_t cpu, int ticks)
{
struct pm_state_info info = {};
+ ARG_UNUSED(cpu);
+
/* make sure this is idle thread */
zassert_true(z_is_idle_thread_object(_current), NULL);
zassert_true(ticks == _kernel.idle, NULL);