mirror of https://github.com/ArduPilot/ardupilot
AP_Scheduler: add the fast loop to task statistics
This commit is contained in:
parent
530eb6d236
commit
af8d6c5fc9
|
@ -324,13 +324,16 @@ void AP_Scheduler::loop()
|
|||
const uint32_t loop_us = get_loop_period_us();
|
||||
uint32_t now = AP_HAL::micros();
|
||||
uint32_t time_available = 0;
|
||||
if (now - sample_time_us < loop_us) {
|
||||
const uint32_t loop_tick_us = now - sample_time_us;
|
||||
if (loop_tick_us < loop_us) {
|
||||
// get remaining time available for this loop
|
||||
time_available = loop_us - (now - sample_time_us);
|
||||
time_available = loop_us - loop_tick_us;
|
||||
}
|
||||
|
||||
// add in extra loop time determined by not achieving scheduler tasks
|
||||
time_available += extra_loop_us;
|
||||
// update the task info for the fast loop
|
||||
perf_info.update_task_info(_num_tasks, loop_tick_us, loop_tick_us > loop_us);
|
||||
|
||||
// run the tasks
|
||||
run(time_available);
|
||||
|
@ -432,15 +435,15 @@ size_t AP_Scheduler::task_info(char *buf, size_t bufsize)
|
|||
|
||||
// baseline the total time taken by all tasks
|
||||
float total_time = 1.0f;
|
||||
for (uint8_t i = 0; i < _num_tasks; i++) {
|
||||
for (uint8_t i = 0; i < _num_tasks + 1; i++) {
|
||||
const AP::PerfInfo::TaskInfo* ti = perf_info.get_task_info(i);
|
||||
if (ti->tick_count > 0) {
|
||||
total_time += ti->elapsed_time_us;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < _num_tasks; i++) {
|
||||
const AP_Scheduler::Task& task = (i < _num_unshared_tasks) ? _tasks[i] : _common_tasks[i - _num_unshared_tasks];
|
||||
for (uint8_t i = 0; i < _num_tasks + 1; i++) {
|
||||
const char* task_name = (i < _num_unshared_tasks) ? _tasks[i].name : i == _num_tasks ? "fast_loop" : _common_tasks[i - _num_unshared_tasks].name;
|
||||
const AP::PerfInfo::TaskInfo* ti = perf_info.get_task_info(i);
|
||||
|
||||
uint16_t avg = 0;
|
||||
|
@ -455,7 +458,7 @@ size_t AP_Scheduler::task_info(char *buf, size_t bufsize)
|
|||
#else
|
||||
const char* fmt = "%-32.32s MIN=%3u MAX=%3u AVG=%3u OVR=%3u SLP=%3u, TOT=%4.1f%%\n";
|
||||
#endif
|
||||
n = hal.util->snprintf(buf, bufsize, fmt, task.name,
|
||||
n = hal.util->snprintf(buf, bufsize, fmt, task_name,
|
||||
unsigned(MIN(ti->min_time_us, 999)), unsigned(MIN(ti->max_time_us, 999)), unsigned(avg),
|
||||
unsigned(MIN(ti->overrun_count, 999)), unsigned(MIN(ti->slip_count, 999)), pct);
|
||||
|
||||
|
|
|
@ -22,6 +22,9 @@ void AP::PerfInfo::reset()
|
|||
long_running = 0;
|
||||
sigma_time = 0;
|
||||
sigmasquared_time = 0;
|
||||
if (_task_info != nullptr) {
|
||||
memset(_task_info, 0, (_num_tasks + 1) * sizeof(TaskInfo));
|
||||
}
|
||||
}
|
||||
|
||||
// ignore_loop - ignore this loop from performance measurements (used to reduce false positive when arming)
|
||||
|
@ -33,7 +36,7 @@ void AP::PerfInfo::ignore_this_loop()
|
|||
// allocate the array of task statistics for use by @SYS/tasks.txt
|
||||
void AP::PerfInfo::allocate_task_info(uint8_t num_tasks)
|
||||
{
|
||||
_task_info = new TaskInfo[num_tasks];
|
||||
_task_info = new TaskInfo[num_tasks + 1]; // add an extra slot for the fast_loop
|
||||
if (_task_info == nullptr) {
|
||||
hal.console->printf("Unable to allocate scheduler TaskInfo\n");
|
||||
_num_tasks = 0;
|
||||
|
@ -56,7 +59,7 @@ void AP::PerfInfo::update_task_info(uint8_t task_index, uint16_t task_time_us, b
|
|||
return;
|
||||
}
|
||||
|
||||
if (task_index >= _num_tasks) {
|
||||
if (task_index > _num_tasks) {
|
||||
INTERNAL_ERROR(AP_InternalError::error_t::flow_of_control);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -43,13 +43,13 @@ public:
|
|||
bool has_task_info() { return _task_info != nullptr; }
|
||||
// return a task info
|
||||
const TaskInfo* get_task_info(uint8_t task_index) const {
|
||||
return (_task_info && task_index < _num_tasks) ? &_task_info[task_index] : nullptr;
|
||||
return (_task_info && task_index <= _num_tasks) ? &_task_info[task_index] : nullptr;
|
||||
}
|
||||
// called after each run of a task to update its statistics based on measurements taken by the scheduler
|
||||
void update_task_info(uint8_t task_index, uint16_t task_time_us, bool overrun);
|
||||
// record that a task slipped
|
||||
void task_slipped(uint8_t task_index) {
|
||||
if (_task_info && task_index < _num_tasks) {
|
||||
if (_task_info && task_index <= _num_tasks) {
|
||||
_task_info[task_index].overrun_count++;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue