mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/schedstatistics: handle if PIDs are KERNEL_PID_UNDEF
Previously, sched_statistics_cb() was always called with two valid PIDs. Now it is possible (when the idle thread is not used) that one of the two might be KERNEL_PID_UNDEF, as the callback might be called when descheduling the last thread, or scheduling the first.
This commit is contained in:
parent
0ff9e554eb
commit
baca419934
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user