diff --git a/sys/schedstatistics/schedstatistics.c b/sys/schedstatistics/schedstatistics.c index 0f5c78d0dd..92743ca6ba 100644 --- a/sys/schedstatistics/schedstatistics.c +++ b/sys/schedstatistics/schedstatistics.c @@ -31,15 +31,18 @@ void sched_statistics_cb(kernel_pid_t active_thread, kernel_pid_t next_thread) { uint32_t now = xtimer_now().ticks32; - /* Update active thread runtime, there is always an active thread since - first sched_run happens when main_trampoline gets scheduled */ - schedstat_t *active_stat = &sched_pidlist[active_thread]; - active_stat->runtime_ticks += now - active_stat->laststart; + /* Update active thread stats */ + if (active_thread != KERNEL_PID_UNDEF) { + schedstat_t *active_stat = &sched_pidlist[active_thread]; + active_stat->runtime_ticks += now - active_stat->laststart; + } /* Update next_thread stats */ - schedstat_t *next_stat = &sched_pidlist[next_thread]; - next_stat->laststart = now; - next_stat->schedules++; + if (next_thread != KERNEL_PID_UNDEF) { + schedstat_t *next_stat = &sched_pidlist[next_thread]; + next_stat->laststart = now; + next_stat->schedules++; + } } void init_schedstatistics(void)