Scheduler.cpp 20 KB

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