pm: policy: return a reference to the next state
Return a constant reference to the next state instead of a copy of struct pm_state_info. When the next state should be active, just return NULL. Struct copying should be in general avoided, specially in code paths executed frequently as is this one. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
e5df3a8cc4
commit
696caa0524
7 changed files with 27 additions and 17 deletions
|
@ -23,7 +23,7 @@ static void tdata_dump_callback(const struct k_thread *thread, void *user_data)
|
|||
}
|
||||
|
||||
/* Our PM policy handler */
|
||||
struct pm_state_info pm_policy_next_state(uint8_t cpu, int32_t ticks)
|
||||
const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks)
|
||||
{
|
||||
static bool test_flag;
|
||||
|
||||
|
@ -37,7 +37,7 @@ struct pm_state_info pm_policy_next_state(uint8_t cpu, int32_t ticks)
|
|||
test_flag = true;
|
||||
}
|
||||
|
||||
return (struct pm_state_info){PM_STATE_ACTIVE, 0, 0};
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*work handler*/
|
||||
|
|
|
@ -57,16 +57,20 @@ void pm_power_state_exit_post_ops(struct pm_state_info info)
|
|||
irq_unlock(0);
|
||||
}
|
||||
|
||||
struct pm_state_info pm_policy_next_state(uint8_t cpu, int32_t ticks)
|
||||
const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks)
|
||||
{
|
||||
static const struct pm_state_info state = {
|
||||
.state = PM_STATE_SUSPEND_TO_RAM
|
||||
};
|
||||
|
||||
ARG_UNUSED(cpu);
|
||||
|
||||
while (sleep_count < 3) {
|
||||
sleep_count++;
|
||||
return (struct pm_state_info){PM_STATE_SUSPEND_TO_RAM, 0, 0, 0};
|
||||
return &state;
|
||||
}
|
||||
|
||||
return (struct pm_state_info){PM_STATE_ACTIVE, 0, 0, 0};
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void test_wakeup_device_api(void)
|
||||
|
|
|
@ -198,9 +198,9 @@ void pm_power_state_exit_post_ops(struct pm_state_info info)
|
|||
}
|
||||
|
||||
/* Our PM policy handler */
|
||||
struct pm_state_info pm_policy_next_state(uint8_t cpu, int ticks)
|
||||
const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks)
|
||||
{
|
||||
struct pm_state_info info = {};
|
||||
static struct pm_state_info info;
|
||||
|
||||
ARG_UNUSED(cpu);
|
||||
|
||||
|
@ -219,7 +219,7 @@ struct pm_state_info pm_policy_next_state(uint8_t cpu, int ticks)
|
|||
*/
|
||||
info.state = PM_STATE_ACTIVE;
|
||||
}
|
||||
return info;
|
||||
return &info;
|
||||
}
|
||||
|
||||
/* implement in application, called by idle thread */
|
||||
|
|
|
@ -60,9 +60,9 @@ void pm_power_state_exit_post_ops(struct pm_state_info info)
|
|||
irq_unlock(0);
|
||||
}
|
||||
|
||||
struct pm_state_info pm_policy_next_state(uint8_t cpu, int ticks)
|
||||
const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int ticks)
|
||||
{
|
||||
struct pm_state_info info = {};
|
||||
static struct pm_state_info info = {};
|
||||
int32_t msecs = k_ticks_to_ms_floor64(ticks);
|
||||
|
||||
if (msecs < ACTIVE_MSEC) {
|
||||
|
@ -81,7 +81,7 @@ struct pm_state_info pm_policy_next_state(uint8_t cpu, int ticks)
|
|||
|
||||
state_testing[_current_cpu->id] = info.state;
|
||||
|
||||
return info;
|
||||
return &info;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue