1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 09:54:59 +00:00

Everywhere: Replace a bundle of dbg with dbgln.

These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.

This commit touches some dbg() calls which are enclosed in macros. This
should be fine because with the new constexpr stuff, we ensure that the
stuff actually compiles.
This commit is contained in:
asynts 2021-01-12 22:30:52 +01:00 committed by Andreas Kling
parent adbb8d62d1
commit 94bb544c33
6 changed files with 154 additions and 103 deletions

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/Debug.h>
#include <AK/QuickSort.h>
#include <AK/ScopeGuard.h>
#include <AK/TemporaryChange.h>
@ -131,28 +132,46 @@ bool Scheduler::pick_next()
// no longer want to schedule this thread. We can't wait until
// Scheduler::enter_current because we don't want to allow it to
// transition back to user mode.
#ifdef SCHEDULER_DEBUG
dbg() << "Scheduler[" << Processor::current().id() << "]: Thread " << *current_thread << " is dying";
#endif
if constexpr (debug_scheduler)
dbgln("Scheduler[{}]: Thread {} is dying", Processor::current().id(), *current_thread);
current_thread->set_state(Thread::Dying);
}
#ifdef SCHEDULER_RUNNABLE_DEBUG
dbg() << "Scheduler[" << Processor::current().id() << "]: Non-runnables:";
Scheduler::for_each_nonrunnable([&](Thread& thread) -> IterationDecision {
if (thread.state() == Thread::Dying)
dbg() << " " << String::format("%-12s", thread.state_string()) << " " << thread << " @ " << String::formatted("{:04x}:{:08x}", thread.tss().cs, thread.tss().eip) << " Finalizable: " << thread.is_finalizable();
else
dbg() << " " << String::format("%-12s", thread.state_string()) << " " << thread << " @ " << String::formatted("{:04x}:{:08x}", thread.tss().cs, thread.tss().eip);
return IterationDecision::Continue;
});
if constexpr (debug_scheduler_runnable) {
dbgln("Scheduler[{}j]: Non-runnables:", Processor::current().id());
Scheduler::for_each_nonrunnable([&](Thread& thread) -> IterationDecision {
if (thread.state() == Thread::Dying) {
dbgln(" {:12} {} @ {:04x}:{:08x} Finalizable: {}",
thread.state_string(),
thread,
thread.tss().cs,
thread.tss().eip,
thread.is_finalizable());
} else {
dbgln(" {:12} {} @ {:04x}:{:08x}",
thread.state_string(),
thread,
thread.tss().cs,
thread.tss().eip);
}
dbg() << "Scheduler[" << Processor::current().id() << "]: Runnables:";
Scheduler::for_each_runnable([](Thread& thread) -> IterationDecision {
dbg() << " " << String::format("%3u", thread.effective_priority()) << "/" << String::format("%2u", thread.priority()) << " " << String::format("%-12s", thread.state_string()) << " " << thread << " @ " << String::formatted("{:04x}:{:08x}", thread.tss().cs, thread.tss().eip);
return IterationDecision::Continue;
});
#endif
return IterationDecision::Continue;
});
dbgln("Scheduler[{}j]: Runnables:", Processor::current().id());
Scheduler::for_each_runnable([](Thread& thread) -> IterationDecision {
dbgln(" {:3}/{:2} {:12} @ {:04x}:{:08x}",
thread.effective_priority(),
thread.priority(),
thread.state_string(),
thread.tss().cs,
thread.tss().eip);
return IterationDecision::Continue;
});
}
Thread* thread_to_schedule = nullptr;
@ -181,9 +200,7 @@ bool Scheduler::pick_next()
// but since we're still holding the scheduler lock we're still in a critical section
critical.leave();
#ifdef SCHEDULER_DEBUG
dbg() << "Processing pending donate to " << *thread_to_schedule << " reason=" << reason;
#endif
dbgln<debug_scheduler>("Processing pending donate to {} reason={}", *thread_to_schedule, reason);
return donate_to_and_switch(thread_to_schedule, reason);
}
@ -211,9 +228,12 @@ bool Scheduler::pick_next()
if (!thread_to_schedule)
thread_to_schedule = Processor::current().idle_thread();
#ifdef SCHEDULER_DEBUG
dbg() << "Scheduler[" << Processor::current().id() << "]: Switch to " << *thread_to_schedule << " @ " << String::format("%04x:%08x", thread_to_schedule->tss().cs, thread_to_schedule->tss().eip);
#endif
if constexpr (debug_scheduler) {
dbgln("Scheduler[{}]: Switch to {} @ {:04x}:{:08x}",
Processor::current().id(),
*thread_to_schedule,
thread_to_schedule->tss().cs, thread_to_schedule->tss().eip);
}
// We need to leave our first critical section before switching context,
// but since we're still holding the scheduler lock we're still in a critical section
@ -234,9 +254,7 @@ bool Scheduler::yield()
scheduler_data.m_pending_donate_reason = nullptr;
auto current_thread = Thread::current();
#ifdef SCHEDULER_DEBUG
dbg() << "Scheduler[" << proc.id() << "]: yielding thread " << *current_thread << " in_irq: " << proc.in_irq();
#endif
dbgln<debug_scheduler>("Scheduler[{}]: yielding thread {} in_irq={}", proc.id(), *current_thread, proc.in_irq());
ASSERT(current_thread != nullptr);
if (proc.in_irq() || proc.in_critical()) {
// If we're handling an IRQ we can't switch context, or we're in
@ -248,9 +266,9 @@ bool Scheduler::yield()
if (!Scheduler::pick_next())
return false;
#ifdef SCHEDULER_DEBUG
dbg() << "Scheduler[" << Processor::current().id() << "]: yield returns to thread " << *current_thread << " in_irq: " << Processor::current().in_irq();
#endif
if constexpr (debug_scheduler)
dbgln("Scheduler[{}]: yield returns to thread {} in_irq={}", Processor::current().id(), *current_thread, Processor::current().in_irq());
return true;
}
@ -266,9 +284,7 @@ bool Scheduler::donate_to_and_switch(Thread* beneficiary, [[maybe_unused]] const
return Scheduler::yield();
unsigned ticks_to_donate = min(ticks_left - 1, time_slice_for(*beneficiary));
#ifdef SCHEDULER_DEBUG
dbg() << "Scheduler[" << proc.id() << "]: Donating " << ticks_to_donate << " ticks to " << *beneficiary << ", reason=" << reason;
#endif
dbgln<debug_scheduler>("Scheduler[{}]: Donating {} ticks to {}, reason={}", proc.id(), ticks_to_donate, *beneficiary, reason);
beneficiary->set_ticks_left(ticks_to_donate);
return Scheduler::context_switch(beneficiary);