cpuload: add nxsched_update_critmon() to handle thread busyloop

Signed-off-by: ligd <liguiding1@xiaomi.com>
Signed-off-by: lipengfei28 <lipengfei28@xiaomi.com>
This commit is contained in:
ligd
2023-12-28 23:10:43 +08:00
committed by GUIDINGLI
parent 5b14fb75bc
commit f0e12a983d
3 changed files with 31 additions and 0 deletions
+1
View File
@@ -415,6 +415,7 @@ void nxsched_process_cpuload_ticks(clock_t ticks);
#ifdef CONFIG_SCHED_CRITMONITOR
void nxsched_resume_critmon(FAR struct tcb_s *tcb);
void nxsched_suspend_critmon(FAR struct tcb_s *tcb);
void nxsched_update_critmon(FAR struct tcb_s *tcb);
#endif
#if CONFIG_SCHED_CRITMONITOR_MAXTIME_PREEMPTION >= 0
+6
View File
@@ -224,6 +224,12 @@ int clock_cpuload(int pid, FAR struct cpuload_s *cpuload)
DEBUGASSERT(cpuload);
#ifdef CONFIG_SCHED_CPULOAD_CRITMONITOR
/* Update critmon in case of the target thread busyloop */
nxsched_update_critmon(nxsched_get_tcb(pid));
#endif
/* Momentarily disable interrupts. We need (1) the task to stay valid
* while we are doing these operations and (2) the tick counts to be
* synchronized when read.
+24
View File
@@ -445,3 +445,27 @@ void nxsched_suspend_critmon(FAR struct tcb_s *tcb)
}
#endif /* CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION */
}
void nxsched_update_critmon(FAR struct tcb_s *tcb)
{
clock_t current = perf_gettime();
clock_t elapsed = current - tcb->run_start;
if (tcb->task_state != TSTATE_TASK_RUNNING)
{
return;
}
#ifdef CONFIG_SCHED_CPULOAD_CRITMONITOR
clock_t tick = elapsed * CLOCKS_PER_SEC / perf_getfreq();
nxsched_process_taskload_ticks(tcb, tick);
#endif
tcb->run_start = current;
tcb->run_time += elapsed;
if (elapsed > tcb->run_max)
{
tcb->run_max = elapsed;
CHECK_THREAD(tcb->pid, elapsed);
}
}