diff --git a/sched/sched/sched_critmonitor.c b/sched/sched/sched_critmonitor.c index 39acb6948eb..948e1dac875 100644 --- a/sched/sched/sched_critmonitor.c +++ b/sched/sched/sched_critmonitor.c @@ -118,6 +118,59 @@ static clock_t g_crit_start[CONFIG_SMP_NCPUS]; clock_t g_premp_max[CONFIG_SMP_NCPUS]; clock_t g_crit_max[CONFIG_SMP_NCPUS]; +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxsched_critmon_cpuload + * + * Description: + * Update the running time of all running threads when switching threads + * + * Input Parameters: + * tcb - The task that we are performing the load operations on. + * current - The current time + * tick - The ticks that we process in this cpuload. + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef CONFIG_SCHED_CPULOAD_CRITMONITOR +static void nxsched_critmon_cpuload(FAR struct tcb_s *tcb, clock_t current, + clock_t tick) +{ + int i; + UNUSED(i); + + /* Update the cpuload of the thread ready to be suspended */ + + nxsched_process_taskload_ticks(tcb, tick); + + /* Update the cpuload of threads running on other CPUs */ + +# ifdef CONFIG_SMP + for (i = 0; i < CONFIG_SMP_NCPUS; i++) + { + FAR struct tcb_s *rtcb = current_task(i); + + if (tcb->cpu == rtcb->cpu) + { + continue; + } + + nxsched_process_taskload_ticks(rtcb, tick); + + /* Update start time, avoid repeated statistics when the next call */ + + rtcb->run_start = current; + } +# endif +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -302,7 +355,7 @@ void nxsched_suspend_critmon(FAR struct tcb_s *tcb) #ifdef CONFIG_SCHED_CPULOAD_CRITMONITOR clock_t tick = elapsed * CLOCKS_PER_SEC / perf_getfreq(); - nxsched_process_taskload_ticks(tcb, tick); + nxsched_critmon_cpuload(tcb, current, tick); #endif tcb->run_time += elapsed;