From 569cceb059a70bbb6aabe4809f4c1d77509eb923 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Wed, 12 Oct 2016 08:43:25 +0200 Subject: [PATCH] Fix task load measurement in NuttX. Reported by @chungkim. Fixes #5645. --- src/modules/systemlib/cpuload.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/modules/systemlib/cpuload.c b/src/modules/systemlib/cpuload.c index 7f4c967196..9197a072c5 100644 --- a/src/modules/systemlib/cpuload.c +++ b/src/modules/systemlib/cpuload.c @@ -142,12 +142,14 @@ void sched_note_switch(FAR struct tcb_s *pFromTcb, FAR struct tcb_s *pToTcb) uint8_t both_found = 0; for (int i = 0; i < CONFIG_MAX_TASKS; i++) { + /* Check if task is initialized correctly */ + if (system_load.tasks[i].tcb == NULL) { + continue; + } + /* Task ending its current scheduling run */ if (system_load.tasks[i].tcb->pid == pFromTcb->pid) { - //if (system_load.tasks[i].curr_start_time != 0) - { - system_load.tasks[i].total_runtime += new_time - system_load.tasks[i].curr_start_time; - } + system_load.tasks[i].total_runtime += new_time - system_load.tasks[i].curr_start_time; both_found++; } else if (system_load.tasks[i].tcb->pid == pToTcb->pid) {