mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
Make cpuload correct and more efficient for all configurations of NuttX
Currently cpuload assumes there are only 2 static threads - idle and init, this is true only for "basic" config of NuttX, as there can be 3 more static threads: paging, work0 and work1 - depending on config. In such cases cpuload would mistake one of them for init (which in fact is always last), giving incorrect results to "top" Signed-off-by: Freddie Chopin <freddie.chopin@gmail.com>
This commit is contained in:
parent
3de3b58505
commit
e5c7ae4706
@ -77,8 +77,6 @@ extern FAR _TCB *sched_gettcb(pid_t pid);
|
||||
|
||||
void cpuload_initialize_once()
|
||||
{
|
||||
// if (!system_load.initialized)
|
||||
// {
|
||||
system_load.start_time = hrt_absolute_time();
|
||||
int i;
|
||||
|
||||
@ -86,27 +84,29 @@ void cpuload_initialize_once()
|
||||
system_load.tasks[i].valid = false;
|
||||
}
|
||||
|
||||
system_load.total_count = 0;
|
||||
|
||||
uint64_t now = hrt_absolute_time();
|
||||
|
||||
/* initialize idle thread statically */
|
||||
system_load.tasks[0].start_time = now;
|
||||
system_load.tasks[0].total_runtime = 0;
|
||||
system_load.tasks[0].curr_start_time = 0;
|
||||
system_load.tasks[0].tcb = sched_gettcb(0);
|
||||
system_load.tasks[0].valid = true;
|
||||
system_load.total_count++;
|
||||
int static_tasks_count = 2; // there are at least 2 threads that should be initialized statically - "idle" and "init"
|
||||
|
||||
/* initialize init thread statically */
|
||||
system_load.tasks[1].start_time = now;
|
||||
system_load.tasks[1].total_runtime = 0;
|
||||
system_load.tasks[1].curr_start_time = 0;
|
||||
system_load.tasks[1].tcb = sched_gettcb(1);
|
||||
system_load.tasks[1].valid = true;
|
||||
/* count init thread */
|
||||
system_load.total_count++;
|
||||
// }
|
||||
#ifdef CONFIG_PAGING
|
||||
static_tasks_count++; // include paging thread in initialization
|
||||
#endif /* CONFIG_PAGING */
|
||||
#if CONFIG_SCHED_WORKQUEUE
|
||||
static_tasks_count++; // include high priority work0 thread in initialization
|
||||
#endif /* CONFIG_SCHED_WORKQUEUE */
|
||||
#if CONFIG_SCHED_LPWORK
|
||||
static_tasks_count++; // include low priority work1 thread in initialization
|
||||
#endif /* CONFIG_SCHED_WORKQUEUE */
|
||||
|
||||
// perform static initialization of "system" threads
|
||||
for (system_load.total_count = 0; system_load.total_count < static_tasks_count; system_load.total_count++)
|
||||
{
|
||||
system_load.tasks[system_load.total_count].start_time = now;
|
||||
system_load.tasks[system_load.total_count].total_runtime = 0;
|
||||
system_load.tasks[system_load.total_count].curr_start_time = 0;
|
||||
system_load.tasks[system_load.total_count].tcb = sched_gettcb(system_load.total_count); // it is assumed that these static threads have consecutive PIDs
|
||||
system_load.tasks[system_load.total_count].valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
void sched_note_start(FAR _TCB *tcb)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user