Scheduler.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  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::current_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::current_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::current_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.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::current_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 current_thread = Thread::current();
  218. dbgln_if(SCHEDULER_DEBUG, "Scheduler[{}]: yielding thread {} in_irq={}", Processor::current_id(), *current_thread, Processor::current_in_irq());
  219. VERIFY(current_thread != nullptr);
  220. if (Processor::current_in_irq() || Processor::in_critical()) {
  221. // If we're handling an IRQ we can't switch context, or we're in
  222. // a critical section where we don't want to switch contexts, then
  223. // delay until exiting the trap or critical section
  224. Processor::current().invoke_scheduler_async();
  225. return false;
  226. }
  227. if (!Scheduler::pick_next())
  228. return false;
  229. if constexpr (SCHEDULER_DEBUG)
  230. dbgln("Scheduler[{}]: yield returns to thread {} in_irq={}", Processor::current_id(), *current_thread, Processor::current_in_irq());
  231. return true;
  232. }
  233. bool Scheduler::context_switch(Thread* thread)
  234. {
  235. if (Memory::s_mm_lock.own_lock()) {
  236. PANIC("In context switch while holding Memory::s_mm_lock");
  237. }
  238. thread->did_schedule();
  239. auto from_thread = Thread::current();
  240. if (from_thread == thread)
  241. return false;
  242. if (from_thread) {
  243. // If the last process hasn't blocked (still marked as running),
  244. // mark it as runnable for the next round.
  245. if (from_thread->state() == Thread::Running)
  246. from_thread->set_state(Thread::Runnable);
  247. #ifdef LOG_EVERY_CONTEXT_SWITCH
  248. const auto msg = "Scheduler[{}]: {} -> {} [prio={}] {:#04x}:{:p}";
  249. dbgln(msg,
  250. Processor::current_id(), from_thread->tid().value(),
  251. thread->tid().value(), thread->priority(), thread->regs().cs, thread->regs().ip());
  252. #endif
  253. }
  254. auto& proc = Processor::current();
  255. if (!thread->is_initialized()) {
  256. proc.init_context(*thread, false);
  257. thread->set_initialized(true);
  258. }
  259. thread->set_state(Thread::Running);
  260. PerformanceManager::add_context_switch_perf_event(*from_thread, *thread);
  261. proc.switch_context(from_thread, thread);
  262. // NOTE: from_thread at this point reflects the thread we were
  263. // switched from, and thread reflects Thread::current()
  264. enter_current(*from_thread, false);
  265. VERIFY(thread == Thread::current());
  266. if (thread->process().is_user_process() && thread->previous_mode() != Thread::PreviousMode::KernelMode && thread->current_trap()) {
  267. auto& regs = thread->get_register_dump_from_stack();
  268. auto iopl = get_iopl_from_eflags(regs.flags());
  269. if (iopl != 0) {
  270. PANIC("Switched to thread {} with non-zero IOPL={}", Thread::current()->tid().value(), iopl);
  271. }
  272. }
  273. return true;
  274. }
  275. void Scheduler::enter_current(Thread& prev_thread, bool is_first)
  276. {
  277. VERIFY(g_scheduler_lock.own_lock());
  278. // We already recorded the scheduled time when entering the trap, so this merely accounts for the kernel time since then
  279. auto scheduler_time = Scheduler::current_time();
  280. prev_thread.update_time_scheduled(scheduler_time, true, true);
  281. auto* current_thread = Thread::current();
  282. current_thread->update_time_scheduled(scheduler_time, true, false);
  283. prev_thread.set_active(false);
  284. if (prev_thread.state() == Thread::Dying) {
  285. // If the thread we switched from is marked as dying, then notify
  286. // the finalizer. Note that as soon as we leave the scheduler lock
  287. // the finalizer may free from_thread!
  288. notify_finalizer();
  289. } else if (!is_first) {
  290. // Check if we have any signals we should deliver (even if we don't
  291. // end up switching to another thread).
  292. if (!current_thread->is_in_block() && current_thread->previous_mode() != Thread::PreviousMode::KernelMode && current_thread->current_trap()) {
  293. SpinlockLocker lock(current_thread->get_lock());
  294. if (current_thread->state() == Thread::Running && current_thread->pending_signals_for_state()) {
  295. current_thread->dispatch_one_pending_signal();
  296. }
  297. }
  298. }
  299. }
  300. void Scheduler::leave_on_first_switch(u32 flags)
  301. {
  302. // This is called when a thread is switched into for the first time.
  303. // At this point, enter_current has already be called, but because
  304. // Scheduler::context_switch is not in the call stack we need to
  305. // clean up and release locks manually here
  306. g_scheduler_lock.unlock(flags);
  307. auto& scheduler_data = ProcessorSpecific<SchedulerData>::get();
  308. VERIFY(scheduler_data.in_scheduler);
  309. scheduler_data.in_scheduler = false;
  310. }
  311. void Scheduler::prepare_after_exec()
  312. {
  313. // This is called after exec() when doing a context "switch" into
  314. // the new process. This is called from Processor::assume_context
  315. VERIFY(g_scheduler_lock.own_lock());
  316. auto& scheduler_data = ProcessorSpecific<SchedulerData>::get();
  317. VERIFY(!scheduler_data.in_scheduler);
  318. scheduler_data.in_scheduler = true;
  319. }
  320. void Scheduler::prepare_for_idle_loop()
  321. {
  322. // This is called when the CPU finished setting up the idle loop
  323. // and is about to run it. We need to acquire he scheduler lock
  324. VERIFY(!g_scheduler_lock.own_lock());
  325. g_scheduler_lock.lock();
  326. auto& scheduler_data = ProcessorSpecific<SchedulerData>::get();
  327. VERIFY(!scheduler_data.in_scheduler);
  328. scheduler_data.in_scheduler = true;
  329. }
  330. Process* Scheduler::colonel()
  331. {
  332. VERIFY(s_colonel_process);
  333. return s_colonel_process;
  334. }
  335. static u64 current_time_tsc()
  336. {
  337. return read_tsc();
  338. }
  339. static u64 current_time_monotonic()
  340. {
  341. // We always need a precise timestamp here, we cannot rely on a coarse timestamp
  342. return (u64)TimeManagement::the().monotonic_time(TimePrecision::Precise).to_nanoseconds();
  343. }
  344. UNMAP_AFTER_INIT void Scheduler::initialize()
  345. {
  346. VERIFY(Processor::is_initialized()); // sanity check
  347. // Figure out a good scheduling time source
  348. if (Processor::current().has_feature(CPUFeature::TSC)) {
  349. // TODO: only use if TSC is running at a constant frequency?
  350. current_time = current_time_tsc;
  351. } else {
  352. // TODO: Using HPET is rather slow, can we use any other time source that may be faster?
  353. current_time = current_time_monotonic;
  354. }
  355. RefPtr<Thread> idle_thread;
  356. g_finalizer_wait_queue = new WaitQueue;
  357. g_finalizer_has_work.store(false, AK::MemoryOrder::memory_order_release);
  358. s_colonel_process = Process::create_kernel_process(idle_thread, "colonel", idle_loop, nullptr, 1, Process::RegisterProcess::No).leak_ref();
  359. VERIFY(s_colonel_process);
  360. VERIFY(idle_thread);
  361. idle_thread->set_priority(THREAD_PRIORITY_MIN);
  362. idle_thread->set_name(KString::try_create("idle thread #0"));
  363. set_idle_thread(idle_thread);
  364. }
  365. UNMAP_AFTER_INIT void Scheduler::set_idle_thread(Thread* idle_thread)
  366. {
  367. idle_thread->set_idle_thread();
  368. Processor::current().set_idle_thread(*idle_thread);
  369. Processor::set_current_thread(*idle_thread);
  370. }
  371. UNMAP_AFTER_INIT Thread* Scheduler::create_ap_idle_thread(u32 cpu)
  372. {
  373. VERIFY(cpu != 0);
  374. // This function is called on the bsp, but creates an idle thread for another AP
  375. VERIFY(Processor::is_bootstrap_processor());
  376. VERIFY(s_colonel_process);
  377. 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);
  378. VERIFY(idle_thread);
  379. return idle_thread;
  380. }
  381. void Scheduler::add_time_scheduled(u64 time_to_add, bool is_kernel)
  382. {
  383. g_total_time_scheduled.with([&](auto& total_time_scheduled) {
  384. total_time_scheduled.total += time_to_add;
  385. if (is_kernel)
  386. total_time_scheduled.total_kernel += time_to_add;
  387. });
  388. }
  389. void Scheduler::timer_tick(const RegisterState& regs)
  390. {
  391. VERIFY_INTERRUPTS_DISABLED();
  392. VERIFY(Processor::current_in_irq());
  393. auto current_thread = Processor::current_thread();
  394. if (!current_thread)
  395. return;
  396. // Sanity checks
  397. VERIFY(current_thread->current_trap());
  398. VERIFY(current_thread->current_trap()->regs == &regs);
  399. #if !SCHEDULE_ON_ALL_PROCESSORS
  400. if (!Processor::is_bootstrap_processor())
  401. return; // TODO: This prevents scheduling on other CPUs!
  402. #endif
  403. if (current_thread->process().is_kernel_process()) {
  404. // Because the previous mode when entering/exiting kernel threads never changes
  405. // we never update the time scheduled. So we need to update it manually on the
  406. // timer interrupt
  407. current_thread->update_time_scheduled(current_time(), true, false);
  408. }
  409. if (current_thread->previous_mode() == Thread::PreviousMode::UserMode && current_thread->should_die() && !current_thread->is_blocked()) {
  410. SpinlockLocker scheduler_lock(g_scheduler_lock);
  411. dbgln_if(SCHEDULER_DEBUG, "Scheduler[{}]: Terminating user mode thread {}", Processor::current_id(), *current_thread);
  412. current_thread->set_state(Thread::Dying);
  413. Processor::current().invoke_scheduler_async();
  414. return;
  415. }
  416. if (current_thread->tick())
  417. return;
  418. if (!current_thread->is_idle_thread() && !peek_next_runnable_thread()) {
  419. // If no other thread is ready to be scheduled we don't need to
  420. // switch to the idle thread. Just give the current thread another
  421. // time slice and let it run!
  422. current_thread->set_ticks_left(time_slice_for(*current_thread));
  423. current_thread->did_schedule();
  424. dbgln_if(SCHEDULER_DEBUG, "Scheduler[{}]: No other threads ready, give {} another timeslice", Processor::current_id(), *current_thread);
  425. return;
  426. }
  427. VERIFY_INTERRUPTS_DISABLED();
  428. VERIFY(Processor::current_in_irq());
  429. Processor::current().invoke_scheduler_async();
  430. }
  431. void Scheduler::invoke_async()
  432. {
  433. VERIFY_INTERRUPTS_DISABLED();
  434. VERIFY(!Processor::current_in_irq());
  435. // Since this function is called when leaving critical sections (such
  436. // as a Spinlock), we need to check if we're not already doing this
  437. // to prevent recursion
  438. if (!ProcessorSpecific<SchedulerData>::get().in_scheduler)
  439. pick_next();
  440. }
  441. void Scheduler::notify_finalizer()
  442. {
  443. if (g_finalizer_has_work.exchange(true, AK::MemoryOrder::memory_order_acq_rel) == false)
  444. g_finalizer_wait_queue->wake_all();
  445. }
  446. void Scheduler::idle_loop(void*)
  447. {
  448. auto& proc = Processor::current();
  449. dbgln("Scheduler[{}]: idle loop running", proc.id());
  450. VERIFY(are_interrupts_enabled());
  451. for (;;) {
  452. proc.idle_begin();
  453. asm("hlt");
  454. proc.idle_end();
  455. VERIFY_INTERRUPTS_ENABLED();
  456. #if SCHEDULE_ON_ALL_PROCESSORS
  457. yield();
  458. #else
  459. if (Processor::current_id() == 0)
  460. yield();
  461. #endif
  462. }
  463. }
  464. void Scheduler::dump_scheduler_state(bool with_stack_traces)
  465. {
  466. dump_thread_list(with_stack_traces);
  467. }
  468. bool Scheduler::is_initialized()
  469. {
  470. // The scheduler is initialized iff the idle thread exists
  471. return Processor::idle_thread() != nullptr;
  472. }
  473. TotalTimeScheduled Scheduler::get_total_time_scheduled()
  474. {
  475. return g_total_time_scheduled.with([&](auto& total_time_scheduled) { return total_time_scheduled; });
  476. }
  477. void dump_thread_list(bool with_stack_traces)
  478. {
  479. dbgln("Scheduler thread list for processor {}:", Processor::current_id());
  480. auto get_cs = [](Thread& thread) -> u16 {
  481. if (!thread.current_trap())
  482. return thread.regs().cs;
  483. return thread.get_register_dump_from_stack().cs;
  484. };
  485. auto get_eip = [](Thread& thread) -> u32 {
  486. if (!thread.current_trap())
  487. return thread.regs().ip();
  488. return thread.get_register_dump_from_stack().ip();
  489. };
  490. Thread::for_each([&](Thread& thread) {
  491. switch (thread.state()) {
  492. case Thread::Dying:
  493. dmesgln(" {:14} {:30} @ {:04x}:{:08x} Finalizable: {}, (nsched: {})",
  494. thread.state_string(),
  495. thread,
  496. get_cs(thread),
  497. get_eip(thread),
  498. thread.is_finalizable(),
  499. thread.times_scheduled());
  500. break;
  501. default:
  502. dmesgln(" {:14} Pr:{:2} {:30} @ {:04x}:{:08x} (nsched: {})",
  503. thread.state_string(),
  504. thread.priority(),
  505. thread,
  506. get_cs(thread),
  507. get_eip(thread),
  508. thread.times_scheduled());
  509. break;
  510. }
  511. if (with_stack_traces)
  512. dbgln("{}", thread.backtrace());
  513. return IterationDecision::Continue;
  514. });
  515. }
  516. }