aboutsummaryrefslogtreecommitdiff
path: root/apps/systemlib/cpuload.c
diff options
context:
space:
mode:
authorFreddie Chopin <freddie.chopin@gmail.com>2012-11-30 11:04:35 +0100
committerFreddie Chopin <freddie.chopin@gmail.com>2012-11-30 11:04:35 +0100
commite5c7ae470640ea20fe372b8da8185abf72123dbe (patch)
tree8f7143c883bf60d49626b2454400209477738459 /apps/systemlib/cpuload.c
parent3de3b585054d4df81ebe55f5ce4efd334ae9f1a2 (diff)
downloadpx4-firmware-e5c7ae470640ea20fe372b8da8185abf72123dbe.tar.gz
px4-firmware-e5c7ae470640ea20fe372b8da8185abf72123dbe.tar.bz2
px4-firmware-e5c7ae470640ea20fe372b8da8185abf72123dbe.zip
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>
Diffstat (limited to 'apps/systemlib/cpuload.c')
-rw-r--r--apps/systemlib/cpuload.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/apps/systemlib/cpuload.c b/apps/systemlib/cpuload.c
index 20b711fa6..e35bc56c5 100644
--- a/apps/systemlib/cpuload.c
+++ b/apps/systemlib/cpuload.c
@@ -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++;
-
- /* 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++;
- // }
+ int static_tasks_count = 2; // there are at least 2 threads that should be initialized statically - "idle" and "init"
+
+#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)