Scheduler.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/ScopeGuard.h>
  7. #include <AK/Singleton.h>
  8. #include <AK/Time.h>
  9. #include <Kernel/Arch/x86/InterruptDisabler.h>
  10. #include <Kernel/Arch/x86/TrapFrame.h>
  11. #include <Kernel/Debug.h>
  12. #include <Kernel/Panic.h>
  13. #include <Kernel/PerformanceManager.h>
  14. #include <Kernel/Process.h>
  15. #include <Kernel/RTC.h>
  16. #include <Kernel/Scheduler.h>
  17. #include <Kernel/Sections.h>
  18. #include <Kernel/Time/TimeManagement.h>
  19. // Remove this once SMP is stable and can be enabled by default
  20. #define SCHEDULE_ON_ALL_PROCESSORS 0
  21. namespace Kernel {
  22. RecursiveSpinlock g_scheduler_lock;
  23. static u32 time_slice_for(const Thread& thread)
  24. {
  25. // One time slice unit == 4ms (assuming 250 ticks/second)
  26. if (thread.is_idle_thread())
  27. return 1;
  28. return 2;
  29. }
  30. READONLY_AFTER_INIT Thread* g_finalizer;
  31. READONLY_AFTER_INIT WaitQueue* g_finalizer_wait_queue;
  32. Atomic<bool> g_finalizer_has_work { false };
  33. READONLY_AFTER_INIT static Process* s_colonel_process;
  34. struct ThreadReadyQueue {
  35. IntrusiveList<&Thread::m_ready_queue_node> thread_list;
  36. };
  37. struct ThreadReadyQueues {
  38. u32 mask {};
  39. static constexpr size_t count = sizeof(mask) * 8;
  40. Array<ThreadReadyQueue, count> queues;
  41. };
  42. static Singleton<SpinlockProtected<ThreadReadyQueues>> g_ready_queues;
  43. static SpinlockProtected<TotalTimeScheduled> g_total_time_scheduled;
  44. // The Scheduler::current_time function provides a current time for scheduling purposes,
  45. // which may not necessarily relate to wall time
  46. u64 (*Scheduler::current_time)();
  47. static void dump_thread_list(bool = false);
  48. static inline u32 thread_priority_to_priority_index(u32 thread_priority)
  49. {
  50. // Converts the priority in the range of THREAD_PRIORITY_MIN...THREAD_PRIORITY_MAX
  51. // to a index into g_ready_queues where 0 is the highest priority bucket
  52. VERIFY(thread_priority >= THREAD_PRIORITY_MIN && thread_priority <= THREAD_PRIORITY_MAX);
  53. constexpr u32 thread_priority_count = THREAD_PRIORITY_MAX - THREAD_PRIORITY_MIN + 1;
  54. static_assert(thread_priority_count > 0);
  55. auto priority_bucket = ((thread_priority_count - (thread_priority - THREAD_PRIORITY_MIN)) / thread_priority_count) * (ThreadReadyQueues::count - 1);
  56. VERIFY(priority_bucket < ThreadReadyQueues::count);
  57. return priority_bucket;
  58. }
  59. Thread& Scheduler::pull_next_runnable_thread()
  60. {
  61. auto affinity_mask = 1u << Processor::current_id();
  62. return g_ready_queues->with([&](auto& ready_queues) -> Thread& {
  63. auto priority_mask = ready_queues.mask;
  64. while (priority_mask != 0) {
  65. auto priority = __builtin_ffsl(priority_mask);
  66. VERIFY(priority > 0);
  67. auto& ready_queue = ready_queues.queues[--priority];
  68. for (auto& thread : ready_queue.thread_list) {
  69. VERIFY(thread.m_runnable_priority == (int)priority);
  70. if (thread.is_active())
  71. continue;
  72. if (!(thread.affinity() & affinity_mask))
  73. continue;
  74. thread.m_runnable_priority = -1;
  75. ready_queue.thread_list.remove(thread);
  76. if (ready_queue.thread_list.is_empty())
  77. ready_queues.mask &= ~(1u << priority);
  78. // Mark it as active because we are using this thread. This is similar
  79. // to comparing it with Processor::current_thread, but when there are
  80. // multiple processors there's no easy way to check whether the thread
  81. // is actually still needed. This prevents accidental finalization when
  82. // a thread is no longer in Running state, but running on another core.
  83. // We need to mark it active here so that this thread won't be
  84. // scheduled on another core if it were to be queued before actually
  85. // switching to it.
  86. // FIXME: Figure out a better way maybe?
  87. thread.set_active(true);
  88. return thread;
  89. }
  90. priority_mask &= ~(1u << priority);
  91. }
  92. return *Processor::idle_thread();
  93. });
  94. }
  95. Thread* Scheduler::peek_next_runnable_thread()
  96. {
  97. auto affinity_mask = 1u << Processor::current_id();
  98. return g_ready_queues->with([&](auto& ready_queues) -> Thread* {
  99. auto priority_mask = ready_queues.mask;
  100. while (priority_mask != 0) {
  101. auto priority = __builtin_ffsl(priority_mask);
  102. VERIFY(priority > 0);
  103. auto& ready_queue = ready_queues.queues[--priority];
  104. for (auto& thread : ready_queue.thread_list) {
  105. VERIFY(thread.m_runnable_priority == (int)priority);
  106. if (thread.is_active())
  107. continue;
  108. if (!(thread.affinity() & affinity_mask))
  109. continue;
  110. return &thread;
  111. }
  112. priority_mask &= ~(1u << priority);
  113. }
  114. // Unlike in pull_next_runnable_thread() we don't want to fall back to
  115. // the idle thread. We just want to see if we have any other thread ready
  116. // to be scheduled.
  117. return nullptr;
  118. });
  119. }
  120. bool Scheduler::dequeue_runnable_thread(Thread& thread, bool check_affinity)
  121. {
  122. if (thread.is_idle_thread())
  123. return true;
  124. return g_ready_queues->with([&](auto& ready_queues) {
  125. auto priority = thread.m_runnable_priority;
  126. if (priority < 0) {
  127. VERIFY(!thread.m_ready_queue_node.is_in_list());
  128. return false;
  129. }
  130. if (check_affinity && !(thread.affinity() & (1 << Processor::current_id())))
  131. return false;
  132. VERIFY(ready_queues.mask & (1u << priority));
  133. auto& ready_queue = ready_queues.queues[priority];
  134. thread.m_runnable_priority = -1;
  135. ready_queue.thread_list.remove(thread);
  136. if (ready_queue.thread_list.is_empty())
  137. ready_queues.mask &= ~(1u << priority);
  138. return true;
  139. });
  140. }
  141. void Scheduler::enqueue_runnable_thread(Thread& thread)
  142. {
  143. VERIFY(g_scheduler_lock.is_locked_by_current_processor());
  144. if (thread.is_idle_thread())
  145. return;
  146. auto priority = thread_priority_to_priority_index(thread.priority());
  147. g_ready_queues->with([&](auto& ready_queues) {
  148. VERIFY(thread.m_runnable_priority < 0);
  149. thread.m_runnable_priority = (int)priority;
  150. VERIFY(!thread.m_ready_queue_node.is_in_list());
  151. auto& ready_queue = ready_queues.queues[priority];
  152. bool was_empty = ready_queue.thread_list.is_empty();
  153. ready_queue.thread_list.append(thread);
  154. if (was_empty)
  155. ready_queues.mask |= (1u << priority);
  156. });
  157. }
  158. UNMAP_AFTER_INIT void Scheduler::start()
  159. {
  160. VERIFY_INTERRUPTS_DISABLED();
  161. // We need to acquire our scheduler lock, which will be released
  162. // by the idle thread once control transferred there
  163. g_scheduler_lock.lock();
  164. auto& processor = Processor::current();
  165. VERIFY(processor.is_initialized());
  166. auto& idle_thread = *Processor::idle_thread();
  167. VERIFY(processor.current_thread() == &idle_thread);
  168. idle_thread.set_ticks_left(time_slice_for(idle_thread));
  169. idle_thread.did_schedule();
  170. idle_thread.set_initialized(true);
  171. processor.init_context(idle_thread, false);
  172. idle_thread.set_state(Thread::Running);
  173. VERIFY(idle_thread.affinity() == (1u << processor.id()));
  174. processor.initialize_context_switching(idle_thread);
  175. VERIFY_NOT_REACHED();
  176. }
  177. bool Scheduler::pick_next()
  178. {
  179. VERIFY_INTERRUPTS_DISABLED();
  180. // Set the in_scheduler flag before acquiring the spinlock. This
  181. // prevents a recursive call into Scheduler::invoke_async upon
  182. // leaving the scheduler lock.
  183. ScopedCritical critical;
  184. Processor::set_current_in_scheduler(true);
  185. ScopeGuard guard(
  186. []() {
  187. // We may be on a different processor after we got switched
  188. // back to this thread!
  189. VERIFY(Processor::current_in_scheduler());
  190. Processor::set_current_in_scheduler(false);
  191. });
  192. SpinlockLocker lock(g_scheduler_lock);
  193. if constexpr (SCHEDULER_RUNNABLE_DEBUG) {
  194. dump_thread_list();
  195. }
  196. auto& thread_to_schedule = pull_next_runnable_thread();
  197. if constexpr (SCHEDULER_DEBUG) {
  198. dbgln("Scheduler[{}]: Switch to {} @ {:#04x}:{:p}",
  199. Processor::current_id(),
  200. thread_to_schedule,
  201. thread_to_schedule.regs().cs, thread_to_schedule.regs().ip());
  202. }
  203. // We need to leave our first critical section before switching context,
  204. // but since we're still holding the scheduler lock we're still in a critical section
  205. critical.leave();
  206. thread_to_schedule.set_ticks_left(time_slice_for(thread_to_schedule));
  207. return context_switch(&thread_to_schedule);
  208. }
  209. bool Scheduler::yield()
  210. {
  211. InterruptDisabler disabler;
  212. auto current_thread = Thread::current();
  213. dbgln_if(SCHEDULER_DEBUG, "Scheduler[{}]: yielding thread {} in_irq={}", Processor::current_id(), *current_thread, Processor::current_in_irq());
  214. VERIFY(current_thread != nullptr);
  215. if (Processor::current_in_irq() || Processor::in_critical()) {
  216. // If we're handling an IRQ we can't switch context, or we're in
  217. // a critical section where we don't want to switch contexts, then
  218. // delay until exiting the trap or critical section
  219. Processor::current().invoke_scheduler_async();
  220. return false;
  221. }
  222. if (!Scheduler::pick_next())
  223. return false;
  224. if constexpr (SCHEDULER_DEBUG)
  225. dbgln("Scheduler[{}]: yield returns to thread {} in_irq={}", Processor::current_id(), *current_thread, Processor::current_in_irq());
  226. return true;
  227. }
  228. bool Scheduler::context_switch(Thread* thread)
  229. {
  230. if (Memory::s_mm_lock.is_locked_by_current_processor()) {
  231. PANIC("In context switch while holding Memory::s_mm_lock");
  232. }
  233. thread->did_schedule();
  234. auto from_thread = Thread::current();
  235. if (from_thread == thread)
  236. return false;
  237. if (from_thread) {
  238. // If the last process hasn't blocked (still marked as running),
  239. // mark it as runnable for the next round.
  240. if (from_thread->state() == Thread::Running)
  241. from_thread->set_state(Thread::Runnable);
  242. #ifdef LOG_EVERY_CONTEXT_SWITCH
  243. const auto msg = "Scheduler[{}]: {} -> {} [prio={}] {:#04x}:{:p}";
  244. dbgln(msg,
  245. Processor::current_id(), from_thread->tid().value(),
  246. thread->tid().value(), thread->priority(), thread->regs().cs, thread->regs().ip());
  247. #endif
  248. }
  249. auto& proc = Processor::current();
  250. if (!thread->is_initialized()) {
  251. proc.init_context(*thread, false);
  252. thread->set_initialized(true);
  253. }
  254. thread->set_state(Thread::Running);
  255. PerformanceManager::add_context_switch_perf_event(*from_thread, *thread);
  256. proc.switch_context(from_thread, thread);
  257. // NOTE: from_thread at this point reflects the thread we were
  258. // switched from, and thread reflects Thread::current()
  259. enter_current(*from_thread, false);
  260. VERIFY(thread == Thread::current());
  261. if (thread->process().is_user_process() && thread->previous_mode() != Thread::PreviousMode::KernelMode && thread->current_trap()) {
  262. auto& regs = thread->get_register_dump_from_stack();
  263. auto iopl = get_iopl_from_eflags(regs.flags());
  264. if (iopl != 0) {
  265. PANIC("Switched to thread {} with non-zero IOPL={}", Thread::current()->tid().value(), iopl);
  266. }
  267. }
  268. return true;
  269. }
  270. void Scheduler::enter_current(Thread& prev_thread, bool is_first)
  271. {
  272. VERIFY(g_scheduler_lock.is_locked_by_current_processor());
  273. // We already recorded the scheduled time when entering the trap, so this merely accounts for the kernel time since then
  274. auto scheduler_time = Scheduler::current_time();
  275. prev_thread.update_time_scheduled(scheduler_time, true, true);
  276. auto* current_thread = Thread::current();
  277. current_thread->update_time_scheduled(scheduler_time, true, false);
  278. prev_thread.set_active(false);
  279. if (prev_thread.state() == Thread::Dying) {
  280. // If the thread we switched from is marked as dying, then notify
  281. // the finalizer. Note that as soon as we leave the scheduler lock
  282. // the finalizer may free from_thread!
  283. notify_finalizer();
  284. } else if (!is_first) {
  285. // Check if we have any signals we should deliver (even if we don't
  286. // end up switching to another thread).
  287. if (!current_thread->is_in_block() && current_thread->previous_mode() != Thread::PreviousMode::KernelMode && current_thread->current_trap()) {
  288. SpinlockLocker lock(current_thread->get_lock());
  289. if (current_thread->state() == Thread::Running && current_thread->pending_signals_for_state()) {
  290. current_thread->dispatch_one_pending_signal();
  291. }
  292. }
  293. }
  294. }
  295. void Scheduler::leave_on_first_switch(u32 flags)
  296. {
  297. // This is called when a thread is switched into for the first time.
  298. // At this point, enter_current has already be called, but because
  299. // Scheduler::context_switch is not in the call stack we need to
  300. // clean up and release locks manually here
  301. g_scheduler_lock.unlock(flags);
  302. VERIFY(Processor::current_in_scheduler());
  303. Processor::set_current_in_scheduler(false);
  304. }
  305. void Scheduler::prepare_after_exec()
  306. {
  307. // This is called after exec() when doing a context "switch" into
  308. // the new process. This is called from Processor::assume_context
  309. VERIFY(g_scheduler_lock.is_locked_by_current_processor());
  310. VERIFY(!Processor::current_in_scheduler());
  311. Processor::set_current_in_scheduler(true);
  312. }
  313. void Scheduler::prepare_for_idle_loop()
  314. {
  315. // This is called when the CPU finished setting up the idle loop
  316. // and is about to run it. We need to acquire he scheduler lock
  317. VERIFY(!g_scheduler_lock.is_locked_by_current_processor());
  318. g_scheduler_lock.lock();
  319. VERIFY(!Processor::current_in_scheduler());
  320. Processor::set_current_in_scheduler(true);
  321. }
  322. Process* Scheduler::colonel()
  323. {
  324. VERIFY(s_colonel_process);
  325. return s_colonel_process;
  326. }
  327. static u64 current_time_tsc()
  328. {
  329. return read_tsc();
  330. }
  331. static u64 current_time_monotonic()
  332. {
  333. // We always need a precise timestamp here, we cannot rely on a coarse timestamp
  334. return (u64)TimeManagement::the().monotonic_time(TimePrecision::Precise).to_nanoseconds();
  335. }
  336. UNMAP_AFTER_INIT void Scheduler::initialize()
  337. {
  338. VERIFY(Processor::is_initialized()); // sanity check
  339. // Figure out a good scheduling time source
  340. if (Processor::current().has_feature(CPUFeature::TSC)) {
  341. // TODO: only use if TSC is running at a constant frequency?
  342. current_time = current_time_tsc;
  343. } else {
  344. // TODO: Using HPET is rather slow, can we use any other time source that may be faster?
  345. current_time = current_time_monotonic;
  346. }
  347. RefPtr<Thread> idle_thread;
  348. g_finalizer_wait_queue = new WaitQueue;
  349. g_finalizer_has_work.store(false, AK::MemoryOrder::memory_order_release);
  350. s_colonel_process = Process::create_kernel_process(idle_thread, KString::must_create("colonel"), idle_loop, nullptr, 1, Process::RegisterProcess::No).leak_ref();
  351. VERIFY(s_colonel_process);
  352. VERIFY(idle_thread);
  353. idle_thread->set_priority(THREAD_PRIORITY_MIN);
  354. idle_thread->set_name(KString::must_create("idle thread #0"));
  355. set_idle_thread(idle_thread);
  356. }
  357. UNMAP_AFTER_INIT void Scheduler::set_idle_thread(Thread* idle_thread)
  358. {
  359. idle_thread->set_idle_thread();
  360. Processor::current().set_idle_thread(*idle_thread);
  361. Processor::set_current_thread(*idle_thread);
  362. }
  363. UNMAP_AFTER_INIT Thread* Scheduler::create_ap_idle_thread(u32 cpu)
  364. {
  365. VERIFY(cpu != 0);
  366. // This function is called on the bsp, but creates an idle thread for another AP
  367. VERIFY(Processor::is_bootstrap_processor());
  368. VERIFY(s_colonel_process);
  369. Thread* idle_thread = s_colonel_process->create_kernel_thread(idle_loop, nullptr, THREAD_PRIORITY_MIN, KString::must_create(String::formatted("idle thread #{}", cpu)), 1 << cpu, false);
  370. VERIFY(idle_thread);
  371. return idle_thread;
  372. }
  373. void Scheduler::add_time_scheduled(u64 time_to_add, bool is_kernel)
  374. {
  375. g_total_time_scheduled.with([&](auto& total_time_scheduled) {
  376. total_time_scheduled.total += time_to_add;
  377. if (is_kernel)
  378. total_time_scheduled.total_kernel += time_to_add;
  379. });
  380. }
  381. void Scheduler::timer_tick(const RegisterState& regs)
  382. {
  383. VERIFY_INTERRUPTS_DISABLED();
  384. VERIFY(Processor::current_in_irq());
  385. auto current_thread = Processor::current_thread();
  386. if (!current_thread)
  387. return;
  388. // Sanity checks
  389. VERIFY(current_thread->current_trap());
  390. VERIFY(current_thread->current_trap()->regs == &regs);
  391. #if !SCHEDULE_ON_ALL_PROCESSORS
  392. if (!Processor::is_bootstrap_processor())
  393. return; // TODO: This prevents scheduling on other CPUs!
  394. #endif
  395. if (current_thread->process().is_kernel_process()) {
  396. // Because the previous mode when entering/exiting kernel threads never changes
  397. // we never update the time scheduled. So we need to update it manually on the
  398. // timer interrupt
  399. current_thread->update_time_scheduled(current_time(), true, false);
  400. }
  401. if (current_thread->previous_mode() == Thread::PreviousMode::UserMode && current_thread->should_die() && !current_thread->is_blocked()) {
  402. SpinlockLocker scheduler_lock(g_scheduler_lock);
  403. dbgln_if(SCHEDULER_DEBUG, "Scheduler[{}]: Terminating user mode thread {}", Processor::current_id(), *current_thread);
  404. current_thread->set_state(Thread::Dying);
  405. Processor::current().invoke_scheduler_async();
  406. return;
  407. }
  408. if (current_thread->tick())
  409. return;
  410. if (!current_thread->is_idle_thread() && !peek_next_runnable_thread()) {
  411. // If no other thread is ready to be scheduled we don't need to
  412. // switch to the idle thread. Just give the current thread another
  413. // time slice and let it run!
  414. current_thread->set_ticks_left(time_slice_for(*current_thread));
  415. current_thread->did_schedule();
  416. dbgln_if(SCHEDULER_DEBUG, "Scheduler[{}]: No other threads ready, give {} another timeslice", Processor::current_id(), *current_thread);
  417. return;
  418. }
  419. VERIFY_INTERRUPTS_DISABLED();
  420. VERIFY(Processor::current_in_irq());
  421. Processor::current().invoke_scheduler_async();
  422. }
  423. void Scheduler::invoke_async()
  424. {
  425. VERIFY_INTERRUPTS_DISABLED();
  426. VERIFY(!Processor::current_in_irq());
  427. // Since this function is called when leaving critical sections (such
  428. // as a Spinlock), we need to check if we're not already doing this
  429. // to prevent recursion
  430. if (!Processor::current_in_scheduler())
  431. pick_next();
  432. }
  433. void Scheduler::notify_finalizer()
  434. {
  435. if (g_finalizer_has_work.exchange(true, AK::MemoryOrder::memory_order_acq_rel) == false)
  436. g_finalizer_wait_queue->wake_all();
  437. }
  438. void Scheduler::idle_loop(void*)
  439. {
  440. auto& proc = Processor::current();
  441. dbgln("Scheduler[{}]: idle loop running", proc.id());
  442. VERIFY(are_interrupts_enabled());
  443. for (;;) {
  444. proc.idle_begin();
  445. asm("hlt");
  446. proc.idle_end();
  447. VERIFY_INTERRUPTS_ENABLED();
  448. #if SCHEDULE_ON_ALL_PROCESSORS
  449. yield();
  450. #else
  451. if (Processor::current_id() == 0)
  452. yield();
  453. #endif
  454. }
  455. }
  456. void Scheduler::dump_scheduler_state(bool with_stack_traces)
  457. {
  458. dump_thread_list(with_stack_traces);
  459. }
  460. bool Scheduler::is_initialized()
  461. {
  462. // The scheduler is initialized iff the idle thread exists
  463. return Processor::idle_thread() != nullptr;
  464. }
  465. TotalTimeScheduled Scheduler::get_total_time_scheduled()
  466. {
  467. return g_total_time_scheduled.with([&](auto& total_time_scheduled) { return total_time_scheduled; });
  468. }
  469. void dump_thread_list(bool with_stack_traces)
  470. {
  471. dbgln("Scheduler thread list for processor {}:", Processor::current_id());
  472. auto get_cs = [](Thread& thread) -> u16 {
  473. if (!thread.current_trap())
  474. return thread.regs().cs;
  475. return thread.get_register_dump_from_stack().cs;
  476. };
  477. auto get_eip = [](Thread& thread) -> u32 {
  478. if (!thread.current_trap())
  479. return thread.regs().ip();
  480. return thread.get_register_dump_from_stack().ip();
  481. };
  482. Thread::for_each([&](Thread& thread) {
  483. switch (thread.state()) {
  484. case Thread::Dying:
  485. dmesgln(" {:14} {:30} @ {:04x}:{:08x} Finalizable: {}, (nsched: {})",
  486. thread.state_string(),
  487. thread,
  488. get_cs(thread),
  489. get_eip(thread),
  490. thread.is_finalizable(),
  491. thread.times_scheduled());
  492. break;
  493. default:
  494. dmesgln(" {:14} Pr:{:2} {:30} @ {:04x}:{:08x} (nsched: {})",
  495. thread.state_string(),
  496. thread.priority(),
  497. thread,
  498. get_cs(thread),
  499. get_eip(thread),
  500. thread.times_scheduled());
  501. break;
  502. }
  503. if (with_stack_traces)
  504. dbgln("{}", thread.backtrace());
  505. return IterationDecision::Continue;
  506. });
  507. }
  508. }