sched:sched_cpuload_period: add time compensate for idle task

Signed-off-by: zhuyanlin <zhuyanlin1@xiaomi.com>
This commit is contained in:
zhuyanlin 2022-04-22 17:11:27 +08:00 committed by Xiang Xiao
parent c75f4b62e0
commit de3bb757d2

View File

@ -99,6 +99,8 @@ struct sched_period_s
#ifdef CONFIG_PM
FAR struct timer_lowerhalf_s *lower;
struct pm_callback_s pm_cb;
clock_t idle_start;
clock_t idle_ticks;
#endif
};
#endif
@ -198,11 +200,24 @@ static void nxsched_period_pmnotify(FAR struct pm_callback_s *cb, int domain,
{
if (pmstate == PM_RESTORE)
{
g_sched_period.idle_ticks +=
clock_systime_ticks() - g_sched_period.idle_start;
if (g_sched_period.idle_ticks >= CPULOAD_PERIOD_NOMINAL)
{
nxsched_process_cpuload_ticks(
g_sched_period.idle_ticks / CPULOAD_PERIOD_NOMINAL);
g_sched_period.idle_ticks %= CPULOAD_PERIOD_NOMINAL;
}
g_sched_period.lower->ops->start(g_sched_period.lower);
}
else
{
g_sched_period.lower->ops->stop(g_sched_period.lower);
g_sched_period.idle_start = clock_systime_ticks();
}
}
}