casaroli commented on code in PR #21424:
URL: https://github.com/apache/nuttx/pull/21424#discussion_r4541104038
##########
sched/sched/sched_critmonitor.c:
##########
@@ -370,30 +370,27 @@ void nxsched_critmon_busywait(bool state, FAR void
*caller)
void nxsched_switch_critmon(FAR struct tcb_s *from, FAR struct tcb_s *to)
{
- clock_t current = perf_gettime();
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_THREAD >= 0
- clock_t elapsed = current - from->run_start;
-#else
- clock_t elapsed = 0;
-
- UNUSED(current);
- UNUSED(elapsed);
-#endif
+ irqstate_t flags = write_seqlock_irqsave(&g_thread_lock);
+ clock_t current = perf_gettime();
+ clock_t elapsed = nxsched_critmon_account(from, this_cpu(), current);
-#ifdef CONFIG_SCHED_CPULOAD_CRITMONITOR
- clock_t tick = elapsed * CLK_TCK / perf_getfreq();
+ g_thread_tcb[this_cpu()] = to;
+ write_sequnlock_irqrestore(&g_thread_lock, flags);
- nxsched_critmon_cpuload(from, current, tick);
-#endif
+ /* Check run_max after the unlock: a panic reads the CPU load */
-#if CONFIG_SCHED_CRITMONITOR_MAXTIME_THREAD >= 0
- from->run_time += elapsed;
- to->run_start = current;
if (elapsed > from->run_max)
{
from->run_max = elapsed;
CHECK_THREAD(from->pid, elapsed);
}
+#else
+ clock_t current = perf_gettime();
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]