Fix cpuload.cpp with NuttX 10.3+

This commit is contained in:
Peter van der Perk
2022-09-10 21:24:39 +02:00
parent d20336045b
commit 9c9902b7c5
70 changed files with 118 additions and 0 deletions
@@ -143,5 +143,53 @@ void sched_note_stop(FAR struct tcb_s *tcb)
}
}
void sched_note_suspend(FAR struct tcb_s *tcb)
{
if (system_load.initialized) {
if (tcb->pid == 0) {
system_load.tasks[0].total_runtime += hrt_elapsed_time(&system_load.tasks[0].curr_start_time);
return;
} else {
if (cpuload_monitor_all_count.load() == 0) {
return;
}
}
for (auto &task : system_load.tasks) {
// Task ending its current scheduling run
if (task.valid && (task.curr_start_time > 0)
&& task.tcb && task.tcb->pid == tcb->pid) {
task.total_runtime += hrt_elapsed_time(&task.curr_start_time);
break;
}
}
}
}
void sched_note_resume(FAR struct tcb_s *tcb)
{
if (system_load.initialized) {
if (tcb->pid == 0) {
hrt_store_absolute_time(&system_load.tasks[0].curr_start_time);
return;
} else {
if (cpuload_monitor_all_count.load() == 0) {
return;
}
}
for (auto &task : system_load.tasks) {
if (task.valid && task.tcb && task.tcb->pid == tcb->pid) {
// curr_start_time is accessed from an IRQ handler (in logger), so we need
// to make the update atomic
hrt_store_absolute_time(&task.curr_start_time);
break;
}
}
}
}
__END_DECLS
#endif // PX4_NUTTX && CONFIG_SCHED_INSTRUMENTATION