Skip to content

Commit

Permalink
Add WiFi tear-down debug printing. (#1801)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperl authored Sep 12, 2023
1 parent efb2bba commit 56ec6e2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/resources/wifi_esp32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,42 @@ class WifiResourceGroup : public ResourceGroup {
}

~WifiResourceGroup() {
#if CONFIG_WPA_DEBUG_PRINT
printf("[wifi] ~WifiResourceGroup()\n");
printf("[wifi] esp_wifi_deinit()\n");
#endif
esp_err_t err = esp_wifi_deinit();
#if CONFIG_WPA_DEBUG_PRINT
printf("[wifi] esp_wifi_deinit() -> done\n");
#endif
if (err == ESP_ERR_WIFI_NOT_STOPPED) {
#if CONFIG_WPA_DEBUG_PRINT
printf("[wifi] esp_wifi_stop()\n");
#endif
FATAL_IF_NOT_ESP_OK(esp_wifi_stop());
#if CONFIG_WPA_DEBUG_PRINT
printf("[wifi] esp_wifi_stop() -> done\n");
printf("[wifi] esp_wifi_deinit()\n");
#endif
FATAL_IF_NOT_ESP_OK(esp_wifi_deinit());
#if CONFIG_WPA_DEBUG_PRINT
printf("[wifi] esp_wifi_deinit() -> done\n");
#endif
} else {
FATAL_IF_NOT_ESP_OK(err);
}

#if CONFIG_WPA_DEBUG_PRINT
printf("[wifi] esp_netif_destroy_default_wifi()\n");
#endif
esp_netif_destroy_default_wifi(netif_);
#if CONFIG_WPA_DEBUG_PRINT
printf("[wifi] esp_netif_destroy_default_wifi() -> done\n");
#endif
wifi_pool.put(id_);
#if CONFIG_WPA_DEBUG_PRINT
printf("[wifi] ~WifiResourceGroup() -> done\n");
#endif
}

uint32_t on_event(Resource* resource, word data, uint32_t state) override;
Expand Down
29 changes: 29 additions & 0 deletions src/scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ Scheduler::ExitState Scheduler::launch_program(Locker& locker, Process* process)
}
}

#if CONFIG_WPA_DEBUG_PRINT
printf("[scheduler] exit - reason=%d\n", exit_state_.reason);
#endif

if (!has_exit_reason()) {
exit_state_.reason = EXIT_DONE;
}
Expand All @@ -182,6 +186,10 @@ Scheduler::ExitState Scheduler::launch_program(Locker& locker, Process* process)
delete thread;
}

#if CONFIG_WPA_DEBUG_PRINT
printf("[scheduler] exit - threads deleted\n");
#endif

for (int i = 0; i < NUMBER_OF_READY_QUEUES; i++) {
ProcessListFromScheduler& ready_queue = ready_queue_[i];
while (ready_queue.remove_first()) {
Expand All @@ -200,6 +208,10 @@ Scheduler::ExitState Scheduler::launch_program(Locker& locker, Process* process)
delete group;
}

#if CONFIG_WPA_DEBUG_PRINT
printf("[scheduler] exit - processes deleted\n");
#endif

return exit_state_;
}

Expand Down Expand Up @@ -405,6 +417,11 @@ void Scheduler::run(SchedulerThread* scheduler_thread) {
run_process(locker, process, scheduler_thread);
}

#ifdef CONFIG_WPA_DEBUG_PRINT
printf("[scheduler] stopping scheduler thread (threads=%d->%d)\n",
num_threads_, num_threads_ - 1);
#endif

// Notify potential other thread, that no more processes are left.
OS::signal(has_processes_);

Expand Down Expand Up @@ -722,6 +739,10 @@ void Scheduler::run_process(Locker& locker, Process* process, SchedulerThread* s
}

case Interpreter::Result::DEEP_SLEEP: {
#if CONFIG_WPA_DEBUG_PRINT
printf("[scheduler] process requested deep sleep (processes=%d, threads=%d)\n",
num_processes_, num_threads_);
#endif
ExitState exit(EXIT_DEEP_SLEEP, result.value());
terminate_execution(locker, exit);
break;
Expand Down Expand Up @@ -871,13 +892,21 @@ void Scheduler::terminate_execution(Locker& locker, ExitState exit) {
exit_state_ = exit;
}

#if CONFIG_WPA_DEBUG_PRINT
printf("[scheduler] terminating - reason=%d\n", exit_state_.reason);
#endif

for (SchedulerThread* thread : threads_) {
Process* process = thread->interpreter()->process();
if (process != null) {
process->signal(Process::KILL);
}
}

#if CONFIG_WPA_DEBUG_PRINT
printf("[scheduler] terminating - processes signalled\n");
#endif

OS::signal(has_processes_);
}

Expand Down

0 comments on commit 56ec6e2

Please sign in to comment.