Skip to content

Commit

Permalink
logger watchdog: avoid using printf from IRQ context
Browse files Browse the repository at this point in the history
PX4_ERR calls printf, which calls lib_sem_initialize, which calls sem_wait
  • Loading branch information
bkueng authored and LorenzMeier committed May 18, 2018
1 parent b8a94bf commit 9b5df10
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/modules/logger/watchdog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ bool watchdog_update(watchdog_data_t &watchdog_data)
watchdog_data.last_state = current_state;

#if 0 // for debugging
// test code that prints the maximum time in ready state
// test code that prints the maximum time in ready state.
// Note: we are in IRQ context, and thus are strictly speaking not allowed to use PX4_ERR -
// we do it anyway since it's only used for debugging.
static uint64_t max_time = 0;

if (now - watchdog_data.ready_to_run_timestamp > max_time) {
Expand All @@ -95,26 +97,18 @@ bool watchdog_update(watchdog_data_t &watchdog_data)
#endif

if (now - watchdog_data.ready_to_run_timestamp > 1_s) {
PX4_ERR("watchdog triggered!"); // this will most likely not be logged due to dropouts

// boost the priority to make sure the logger continues to write to the log
// boost the priority to make sure the logger continues to write to the log.
// Note that we never restore the priority, to keep the logic simple and because it is
// an event that must not occur under normal circumstances (if it does, there's a bug
// somewhere)
sched_param param{};
param.sched_priority = SCHED_PRIORITY_MAX;
int ret;

if (system_load.tasks[watchdog_data.logger_main_task_index].valid) {
ret = sched_setparam(system_load.tasks[watchdog_data.logger_main_task_index].tcb->pid, &param);

if (ret < 0) {
PX4_ERR("sched_reprioritize failed (%i)", ret);
}
sched_setparam(system_load.tasks[watchdog_data.logger_main_task_index].tcb->pid, &param);
}

ret = sched_setparam(log_writer_task.tcb->pid, &param);

if (ret < 0) {
PX4_ERR("sched_reprioritize failed (%i)", ret);
}
sched_setparam(log_writer_task.tcb->pid, &param);

// make sure we won't trigger again
watchdog_data.logger_main_task_index = -1;
Expand Down

0 comments on commit 9b5df10

Please sign in to comment.