You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/05/10 13:21:31 UTC

[incubator-nuttx] 05/07: sched:sched_cpuload_period: add time compensate for idle task

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit de3bb757d2d77a01dd3ca438261180d74cdc7154
Author: zhuyanlin <zh...@xiaomi.com>
AuthorDate: Fri Apr 22 17:11:27 2022 +0800

    sched:sched_cpuload_period: add time compensate for idle task
    
    Signed-off-by: zhuyanlin <zh...@xiaomi.com>
---
 sched/sched/sched_cpuload_period.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/sched/sched/sched_cpuload_period.c b/sched/sched/sched_cpuload_period.c
index d5284abdc9..045b5935d6 100644
--- a/sched/sched/sched_cpuload_period.c
+++ b/sched/sched/sched_cpuload_period.c
@@ -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();
         }
     }
 }