load_mon: NuttX cpuload use system times for calculation

- this is to minimize the impact of any load_mon scheduling jitter in the sampled load percentage
This commit is contained in:
Daniel Agar 2022-10-05 14:21:38 -04:00 committed by GitHub
parent 29b031c862
commit 8cc39096cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2012-2020 PX4 Development Team. All rights reserved.
* Copyright (c) 2012-2022 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -140,17 +140,23 @@ void LoadMon::cpuload()
#elif defined(__PX4_NUTTX)
if (_last_idle_time == 0) {
irqstate_t irqstate = enter_critical_section();
// Just get the time in the first iteration */
_last_idle_time = system_load.tasks[0].total_runtime;
_last_idle_time_sample = hrt_absolute_time();
_last_idle_time_sample = system_load.tasks[0].curr_start_time;
leave_critical_section(irqstate);
return;
}
irqstate_t irqstate = enter_critical_section();
const hrt_abstime now = hrt_absolute_time();
const hrt_abstime now = system_load.tasks[0].curr_start_time;
const hrt_abstime total_runtime = system_load.tasks[0].total_runtime;
leave_critical_section(irqstate);
if ((now == _last_idle_time_sample) || (total_runtime == _last_idle_time)) {
return;
}
// compute system load
const float interval = now - _last_idle_time_sample;
const float interval_idletime = total_runtime - _last_idle_time;

View File

@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2012-2020 PX4 Development Team. All rights reserved.
* Copyright (c) 2012-2022 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions