Scheduler.cpp 21 KB

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