@ -71,8 +71,7 @@ const AP_Param::GroupInfo AP_Scheduler::var_info[] = {
@@ -71,8 +71,7 @@ const AP_Param::GroupInfo AP_Scheduler::var_info[] = {
} ;
// constructor
AP_Scheduler : : AP_Scheduler ( scheduler_fastloop_fn_t fastloop_fn ) :
_fastloop_fn ( fastloop_fn )
AP_Scheduler : : AP_Scheduler ( )
{
if ( _singleton ) {
# if CONFIG_HAL_BOARD == HAL_BOARD_SITL
@ -213,33 +212,37 @@ void AP_Scheduler::run(uint32_t time_available)
@@ -213,33 +212,37 @@ void AP_Scheduler::run(uint32_t time_available)
common_tasks_offset + + ;
}
const uint16_t dt = _tick_counter - _last_run [ i ] ;
// we allow 0 to mean loop rate
uint32_t interval_ticks = ( is_zero ( task . rate_hz ) ? 1 : _loop_rate_hz / task . rate_hz ) ;
if ( interval_ticks < 1 ) {
interval_ticks = 1 ;
}
if ( dt < interval_ticks ) {
// this task is not yet scheduled to run again
continue ;
}
// this task is due to run. Do we have enough time to run it?
_task_time_allowed = task . max_time_micros ;
if ( task . priority > MAX_FAST_TASK_PRIORITIES ) {
const uint16_t dt = _tick_counter - _last_run [ i ] ;
// we allow 0 to mean loop rate
uint32_t interval_ticks = ( is_zero ( task . rate_hz ) ? 1 : _loop_rate_hz / task . rate_hz ) ;
if ( interval_ticks < 1 ) {
interval_ticks = 1 ;
}
if ( dt < interval_ticks ) {
// this task is not yet scheduled to run again
continue ;
}
// this task is due to run. Do we have enough time to run it?
_task_time_allowed = task . max_time_micros ;
if ( dt > = interval_ticks * 2 ) {
perf_info . task_slipped ( i ) ;
}
if ( dt > = interval_ticks * 2 ) {
perf_info . task_slipped ( i ) ;
}
if ( dt > = interval_ticks * max_task_slowdown ) {
// we are going beyond the maximum slowdown factor for a
// task. This will trigger increasing the time budget
task_not_achieved + + ;
}
if ( dt > = interval_ticks * max_task_slowdown ) {
// we are going beyond the maximum slowdown factor for a
// task. This will trigger increasing the time budget
task_not_achieved + + ;
}
if ( _task_time_allowed > time_available ) {
// not enough time to run this task. Continue loop -
// maybe another task will fit into time remaining
continue ;
if ( _task_time_allowed > time_available ) {
// not enough time to run this task. Continue loop -
// maybe another task will fit into time remaining
continue ;
}
} else {
_task_time_allowed = get_loop_period_us ( ) ;
}
// run it
@ -331,14 +334,6 @@ void AP_Scheduler::loop()
@@ -331,14 +334,6 @@ void AP_Scheduler::loop()
_last_loop_time_s = ( sample_time_us - _loop_timer_start_us ) * 1.0e-6 ;
}
// Execute the fast loop
// ---------------------
if ( _fastloop_fn ) {
hal . util - > persistent_data . scheduler_task = - 2 ;
_fastloop_fn ( ) ;
hal . util - > persistent_data . scheduler_task = - 1 ;
}
# if CONFIG_HAL_BOARD == HAL_BOARD_SITL
{
/*
@ -369,8 +364,6 @@ void AP_Scheduler::loop()
@@ -369,8 +364,6 @@ void AP_Scheduler::loop()
// 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 ) ;
@ -477,67 +470,41 @@ void AP_Scheduler::task_info(ExpandingString &str)
@@ -477,67 +470,41 @@ void AP_Scheduler::task_info(ExpandingString &str)
uint8_t vehicle_tasks_offset = 0 ;
uint8_t common_tasks_offset = 0 ;
for ( uint8_t i = 0 ; i < _num_tasks + 1 ; i + + ) {
const AP : : PerfInfo : : TaskInfo * ti ;
for ( uint8_t i = 0 ; i < _num_tasks ; i + + ) {
const AP : : PerfInfo : : TaskInfo * ti = perf_info . get_task_info ( i ) ;
const char * task_name ;
if ( i = = 0 ) {
// put the fast-loop entry at the top of the list - it's the last task in perf_info
ti = perf_info . get_task_info ( _num_tasks ) ;
task_name = " fast_loop " ;
} else {
ti = perf_info . get_task_info ( i - 1 ) ;
// now find the task name:
// determine which of the common task / vehicle task to run
bool run_vehicle_task = false ;
if ( vehicle_tasks_offset < _num_vehicle_tasks & &
common_tasks_offset < _num_common_tasks ) {
// still have entries on both lists; compare the
// priorities. In case of a tie the vehicle-specific
// entry wins.
const Task & vehicle_task = _vehicle_tasks [ vehicle_tasks_offset ] ;
const Task & common_task = _common_tasks [ common_tasks_offset ] ;
if ( vehicle_task . priority < = common_task . priority ) {
run_vehicle_task = true ;
}
} else if ( vehicle_tasks_offset < _num_vehicle_tasks ) {
// out of common tasks to run
run_vehicle_task = true ;
} else if ( common_tasks_offset < _num_common_tasks ) {
// out of vehicle tasks to run
run_vehicle_task = false ;
} else {
// this is an error; the outside loop should have terminated
INTERNAL_ERROR ( AP_InternalError : : error_t : : flow_of_control ) ;
return ;
}
if ( run_vehicle_task ) {
task_name = _vehicle_tasks [ vehicle_tasks_offset + + ] . name ;
} else {
task_name = _common_tasks [ common_tasks_offset + + ] . name ;
// determine which of the common task / vehicle task to run
bool run_vehicle_task = false ;
if ( vehicle_tasks_offset < _num_vehicle_tasks & &
common_tasks_offset < _num_common_tasks ) {
// still have entries on both lists; compare the
// priorities. In case of a tie the vehicle-specific
// entry wins.
const Task & vehicle_task = _vehicle_tasks [ vehicle_tasks_offset ] ;
const Task & common_task = _common_tasks [ common_tasks_offset ] ;
if ( vehicle_task . priority < = common_task . priority ) {
run_vehicle_task = true ;
}
// the loop counter i is adjusted here because we emit the
// fast-loop entry first but it appears last in the
// perf_info list
} else if ( vehicle_tasks_offset < _num_vehicle_tasks ) {
// out of common tasks to run
run_vehicle_task = true ;
} else if ( common_tasks_offset < _num_common_tasks ) {
// out of vehicle tasks to run
run_vehicle_task = false ;
} else {
// this is an error; the outside loop should have terminated
INTERNAL_ERROR ( AP_InternalError : : error_t : : flow_of_control ) ;
return ;
}
uint16_t avg = 0 ;
float pct = 0.0f ;
if ( ti ! = nullptr & & ti - > tick_count > 0 ) {
pct = ti - > elapsed_time_us * 100.0f / total_time ;
avg = MIN ( uint16_t ( ti - > elapsed_time_us / ti - > tick_count ) , 9999 ) ;
if ( run_vehicle_task ) {
task_name = _vehicle_tasks [ vehicle_tasks_offset + + ] . name ;
} else {
task_name = _common_tasks [ common_tasks_offset + + ] . name ;
}
# if HAL_MINIMIZE_FEATURES
const char * fmt = " %-16.16s MIN=%4u MAX=%4u AVG=%4u OVR=%3u SLP=%3u, TOT=%4.1f%% \n " ;
# else
const char * fmt = " %-32.32s MIN=%4u MAX=%4u AVG=%4u OVR=%3u SLP=%3u, TOT=%4.1f%% \n " ;
# endif
str . printf ( fmt , task_name ,
unsigned ( MIN ( ti - > min_time_us , 9999 ) ) , unsigned ( MIN ( ti - > max_time_us , 9999 ) ) , unsigned ( avg ) ,
unsigned ( MIN ( ti - > overrun_count , 999 ) ) , unsigned ( MIN ( ti - > slip_count , 999 ) ) , pct ) ;
ti - > print ( task_name , total_time , str ) ;
}
}