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<SpinLockProtectedValue<ThreadReadyQueues>> g_ready_queues;
  46. static TotalTimeScheduled g_total_time_scheduled;
  47. static SpinLock<u8> g_total_time_scheduled_lock;
  48. // The Scheduler::current_time function provides a current time for scheduling purposes,
  49. // which may not necessarily relate to wall time
  50. u64 (*Scheduler::current_time)();
  51. static void dump_thread_list(bool = false);
  52. static inline u32 thread_priority_to_priority_index(u32 thread_priority)
  53. {
  54. // Converts the priority in the range of THREAD_PRIORITY_MIN...THREAD_PRIORITY_MAX
  55. // to a index into g_ready_queues where 0 is the highest priority bucket
  56. VERIFY(thread_priority >= THREAD_PRIORITY_MIN && thread_priority <= THREAD_PRIORITY_MAX);
  57. constexpr u32 thread_priority_count = THREAD_PRIORITY_MAX - THREAD_PRIORITY_MIN + 1;
  58. static_assert(thread_priority_count > 0);
  59. auto priority_bucket = ((thread_priority_count - (thread_priority - THREAD_PRIORITY_MIN)) / thread_priority_count) * (ThreadReadyQueues::count - 1);
  60. VERIFY(priority_bucket < ThreadReadyQueues::count);
  61. return priority_bucket;
  62. }
  63. Thread& Scheduler::pull_next_runnable_thread()
  64. {
  65. auto affinity_mask = 1u << Processor::id();
  66. return g_ready_queues->with([&](auto& ready_queues) -> Thread& {
  67. auto priority_mask = ready_queues.mask;
  68. while (priority_mask != 0) {
  69. auto priority = __builtin_ffsl(priority_mask);
  70. VERIFY(priority > 0);
  71. auto& ready_queue = ready_queues.queues[--priority];
  72. for (auto& thread : ready_queue.thread_list) {
  73. VERIFY(thread.m_runnable_priority == (int)priority);
  74. if (thread.is_active())
  75. continue;
  76. if (!(thread.affinity() & affinity_mask))
  77. continue;
  78. thread.m_runnable_priority = -1;
  79. ready_queue.thread_list.remove(thread);
  80. if (ready_queue.thread_list.is_empty())
  81. ready_queues.mask &= ~(1u << priority);
  82. // Mark it as active because we are using this thread. This is similar
  83. // to comparing it with Processor::current_thread, but when there are
  84. // multiple processors there's no easy way to check whether the thread
  85. // is actually still needed. This prevents accidental finalization when
  86. // a thread is no longer in Running state, but running on another core.
  87. // We need to mark it active here so that this thread won't be
  88. // scheduled on another core if it were to be queued before actually
  89. // switching to it.
  90. // FIXME: Figure out a better way maybe?
  91. thread.set_active(true);
  92. return thread;
  93. }
  94. priority_mask &= ~(1u << priority);
  95. }
  96. return *Processor::idle_thread();
  97. });
  98. }
  99. Thread* Scheduler::peek_next_runnable_thread()
  100. {
  101. auto affinity_mask = 1u << Processor::id();
  102. return g_ready_queues->with([&](auto& ready_queues) -> Thread* {
  103. auto priority_mask = ready_queues.mask;
  104. while (priority_mask != 0) {
  105. auto priority = __builtin_ffsl(priority_mask);
  106. VERIFY(priority > 0);
  107. auto& ready_queue = ready_queues.queues[--priority];
  108. for (auto& thread : ready_queue.thread_list) {
  109. VERIFY(thread.m_runnable_priority == (int)priority);
  110. if (thread.is_active())
  111. continue;
  112. if (!(thread.affinity() & affinity_mask))
  113. continue;
  114. return &thread;
  115. }
  116. priority_mask &= ~(1u << priority);
  117. }
  118. // Unlike in pull_next_runnable_thread() we don't want to fall back to
  119. // the idle thread. We just want to see if we have any other thread ready
  120. // to be scheduled.
  121. return nullptr;
  122. });
  123. }
  124. bool Scheduler::dequeue_runnable_thread(Thread& thread, bool check_affinity)
  125. {
  126. if (thread.is_idle_thread())
  127. return true;
  128. return g_ready_queues->with([&](auto& ready_queues) {
  129. auto priority = thread.m_runnable_priority;
  130. if (priority < 0) {
  131. VERIFY(!thread.m_ready_queue_node.is_in_list());
  132. return false;
  133. }
  134. if (check_affinity && !(thread.affinity() & (1 << Processor::id())))
  135. return false;
  136. VERIFY(ready_queues.mask & (1u << priority));
  137. auto& ready_queue = ready_queues.queues[priority];
  138. thread.m_runnable_priority = -1;
  139. ready_queue.thread_list.remove(thread);
  140. if (ready_queue.thread_list.is_empty())
  141. ready_queues.mask &= ~(1u << priority);
  142. return true;
  143. });
  144. }
  145. void Scheduler::queue_runnable_thread(Thread& thread)
  146. {
  147. VERIFY(g_scheduler_lock.own_lock());
  148. if (thread.is_idle_thread())
  149. return;
  150. auto priority = thread_priority_to_priority_index(thread.priority());
  151. g_ready_queues->with([&](auto& ready_queues) {
  152. VERIFY(thread.m_runnable_priority < 0);
  153. thread.m_runnable_priority = (int)priority;
  154. VERIFY(!thread.m_ready_queue_node.is_in_list());
  155. auto& ready_queue = ready_queues.queues[priority];
  156. bool was_empty = ready_queue.thread_list.is_empty();
  157. ready_queue.thread_list.append(thread);
  158. if (was_empty)
  159. ready_queues.mask |= (1u << priority);
  160. });
  161. }
  162. UNMAP_AFTER_INIT void Scheduler::start()
  163. {
  164. VERIFY_INTERRUPTS_DISABLED();
  165. // We need to acquire our scheduler lock, which will be released
  166. // by the idle thread once control transferred there
  167. g_scheduler_lock.lock();
  168. auto& processor = Processor::current();
  169. ProcessorSpecific<SchedulerData>::initialize();
  170. VERIFY(processor.is_initialized());
  171. auto& idle_thread = *Processor::idle_thread();
  172. VERIFY(processor.current_thread() == &idle_thread);
  173. idle_thread.set_ticks_left(time_slice_for(idle_thread));
  174. idle_thread.did_schedule();
  175. idle_thread.set_initialized(true);
  176. processor.init_context(idle_thread, false);
  177. idle_thread.set_state(Thread::Running);
  178. VERIFY(idle_thread.affinity() == (1u << processor.get_id()));
  179. processor.initialize_context_switching(idle_thread);
  180. VERIFY_NOT_REACHED();
  181. }
  182. bool Scheduler::pick_next()
  183. {
  184. VERIFY_INTERRUPTS_DISABLED();
  185. // Set the in_scheduler flag before acquiring the spinlock. This
  186. // prevents a recursive call into Scheduler::invoke_async upon
  187. // leaving the scheduler lock.
  188. ScopedCritical critical;
  189. ProcessorSpecific<SchedulerData>::get().in_scheduler = true;
  190. ScopeGuard guard(
  191. []() {
  192. // We may be on a different processor after we got switched
  193. // back to this thread!
  194. auto& scheduler_data = ProcessorSpecific<SchedulerData>::get();
  195. VERIFY(scheduler_data.in_scheduler);
  196. scheduler_data.in_scheduler = false;
  197. });
  198. ScopedSpinLock lock(g_scheduler_lock);
  199. if constexpr (SCHEDULER_RUNNABLE_DEBUG) {
  200. dump_thread_list();
  201. }
  202. auto& thread_to_schedule = pull_next_runnable_thread();
  203. if constexpr (SCHEDULER_DEBUG) {
  204. dbgln("Scheduler[{}]: Switch to {} @ {:#04x}:{:p}",
  205. Processor::id(),
  206. thread_to_schedule,
  207. thread_to_schedule.regs().cs, thread_to_schedule.regs().ip());
  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 (Memory::s_mm_lock.own_lock()) {
  238. PANIC("In context switch while holding Memory::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. const auto msg = "Scheduler[{}]: {} -> {} [prio={}] {:#04x}:{:p}";
  251. dbgln(msg,
  252. Processor::id(), from_thread->tid().value(),
  253. thread->tid().value(), thread->priority(), thread->regs().cs, thread->regs().ip());
  254. #endif
  255. }
  256. auto& proc = Processor::current();
  257. if (!thread->is_initialized()) {
  258. proc.init_context(*thread, false);
  259. thread->set_initialized(true);
  260. }
  261. thread->set_state(Thread::Running);
  262. PerformanceManager::add_context_switch_perf_event(*from_thread, *thread);
  263. proc.switch_context(from_thread, thread);
  264. // NOTE: from_thread at this point reflects the thread we were
  265. // switched from, and thread reflects Thread::current()
  266. enter_current(*from_thread, false);
  267. VERIFY(thread == Thread::current());
  268. if (thread->process().is_user_process()) {
  269. auto& regs = Thread::current()->get_register_dump_from_stack();
  270. auto iopl = get_iopl_from_eflags(regs.flags());
  271. if (iopl != 0) {
  272. PANIC("Switched to thread {} with non-zero IOPL={}", Thread::current()->tid().value(), iopl);
  273. }
  274. }
  275. return true;
  276. }
  277. void Scheduler::enter_current(Thread& prev_thread, bool is_first)
  278. {
  279. VERIFY(g_scheduler_lock.own_lock());
  280. // We already recorded the scheduled time when entering the trap, so this merely accounts for the kernel time since then
  281. auto scheduler_time = Scheduler::current_time();
  282. prev_thread.update_time_scheduled(scheduler_time, true, true);
  283. auto* current_thread = Thread::current();
  284. current_thread->update_time_scheduled(scheduler_time, true, false);
  285. prev_thread.set_active(false);
  286. if (prev_thread.state() == Thread::Dying) {
  287. // If the thread we switched from is marked as dying, then notify
  288. // the finalizer. Note that as soon as we leave the scheduler lock
  289. // the finalizer may free from_thread!
  290. notify_finalizer();
  291. } else if (!is_first) {
  292. // Check if we have any signals we should deliver (even if we don't
  293. // end up switching to another thread).
  294. if (!current_thread->is_in_block() && current_thread->previous_mode() != Thread::PreviousMode::KernelMode) {
  295. ScopedSpinLock lock(current_thread->get_lock());
  296. if (current_thread->state() == Thread::Running && current_thread->pending_signals_for_state()) {
  297. current_thread->dispatch_one_pending_signal();
  298. }
  299. }
  300. }
  301. }
  302. void Scheduler::leave_on_first_switch(u32 flags)
  303. {
  304. // This is called when a thread is switched into for the first time.
  305. // At this point, enter_current has already be called, but because
  306. // Scheduler::context_switch is not in the call stack we need to
  307. // clean up and release locks manually here
  308. g_scheduler_lock.unlock(flags);
  309. auto& scheduler_data = ProcessorSpecific<SchedulerData>::get();
  310. VERIFY(scheduler_data.in_scheduler);
  311. scheduler_data.in_scheduler = false;
  312. }
  313. void Scheduler::prepare_after_exec()
  314. {
  315. // This is called after exec() when doing a context "switch" into
  316. // the new process. This is called from Processor::assume_context
  317. VERIFY(g_scheduler_lock.own_lock());
  318. auto& scheduler_data = ProcessorSpecific<SchedulerData>::get();
  319. VERIFY(!scheduler_data.in_scheduler);
  320. scheduler_data.in_scheduler = true;
  321. }
  322. void Scheduler::prepare_for_idle_loop()
  323. {
  324. // This is called when the CPU finished setting up the idle loop
  325. // and is about to run it. We need to acquire he scheduler lock
  326. VERIFY(!g_scheduler_lock.own_lock());
  327. g_scheduler_lock.lock();
  328. auto& scheduler_data = ProcessorSpecific<SchedulerData>::get();
  329. VERIFY(!scheduler_data.in_scheduler);
  330. scheduler_data.in_scheduler = true;
  331. }
  332. Process* Scheduler::colonel()
  333. {
  334. VERIFY(s_colonel_process);
  335. return s_colonel_process;
  336. }
  337. static u64 current_time_tsc()
  338. {
  339. return read_tsc();
  340. }
  341. static u64 current_time_monotonic()
  342. {
  343. // We always need a precise timestamp here, we cannot rely on a coarse timestamp
  344. return (u64)TimeManagement::the().monotonic_time(TimePrecision::Precise).to_nanoseconds();
  345. }
  346. UNMAP_AFTER_INIT void Scheduler::initialize()
  347. {
  348. VERIFY(Processor::is_initialized()); // sanity check
  349. // Figure out a good scheduling time source
  350. if (Processor::current().has_feature(CPUFeature::TSC)) {
  351. // TODO: only use if TSC is running at a constant frequency?
  352. current_time = current_time_tsc;
  353. } else {
  354. // TODO: Using HPET is rather slow, can we use any other time source that may be faster?
  355. current_time = current_time_monotonic;
  356. }
  357. RefPtr<Thread> idle_thread;
  358. g_finalizer_wait_queue = new WaitQueue;
  359. g_finalizer_has_work.store(false, AK::MemoryOrder::memory_order_release);
  360. s_colonel_process = Process::create_kernel_process(idle_thread, "colonel", idle_loop, nullptr, 1, Process::RegisterProcess::No).leak_ref();
  361. VERIFY(s_colonel_process);
  362. VERIFY(idle_thread);
  363. idle_thread->set_priority(THREAD_PRIORITY_MIN);
  364. idle_thread->set_name(KString::try_create("idle thread #0"));
  365. set_idle_thread(idle_thread);
  366. }
  367. UNMAP_AFTER_INIT void Scheduler::set_idle_thread(Thread* idle_thread)
  368. {
  369. idle_thread->set_idle_thread();
  370. Processor::current().set_idle_thread(*idle_thread);
  371. Processor::set_current_thread(*idle_thread);
  372. }
  373. UNMAP_AFTER_INIT Thread* Scheduler::create_ap_idle_thread(u32 cpu)
  374. {
  375. VERIFY(cpu != 0);
  376. // This function is called on the bsp, but creates an idle thread for another AP
  377. VERIFY(Processor::is_bootstrap_processor());
  378. VERIFY(s_colonel_process);
  379. 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);
  380. VERIFY(idle_thread);
  381. return idle_thread;
  382. }
  383. void Scheduler::add_time_scheduled(u64 time_to_add, bool is_kernel)
  384. {
  385. ScopedSpinLock lock(g_total_time_scheduled_lock);
  386. g_total_time_scheduled.total += time_to_add;
  387. if (is_kernel)
  388. g_total_time_scheduled.total_kernel += time_to_add;
  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. ScopedSpinLock 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. ScopedSpinLock lock(g_total_time_scheduled_lock);
  478. return g_total_time_scheduled;
  479. }
  480. void dump_thread_list(bool with_stack_traces)
  481. {
  482. dbgln("Scheduler thread list for processor {}:", Processor::id());
  483. auto get_cs = [](Thread& thread) -> u16 {
  484. if (!thread.current_trap())
  485. return thread.regs().cs;
  486. return thread.get_register_dump_from_stack().cs;
  487. };
  488. auto get_eip = [](Thread& thread) -> u32 {
  489. if (!thread.current_trap())
  490. return thread.regs().ip();
  491. return thread.get_register_dump_from_stack().ip();
  492. };
  493. Thread::for_each([&](Thread& thread) {
  494. switch (thread.state()) {
  495. case Thread::Dying:
  496. dmesgln(" {:14} {:30} @ {:04x}:{:08x} Finalizable: {}, (nsched: {})",
  497. thread.state_string(),
  498. thread,
  499. get_cs(thread),
  500. get_eip(thread),
  501. thread.is_finalizable(),
  502. thread.times_scheduled());
  503. break;
  504. default:
  505. dmesgln(" {:14} Pr:{:2} {:30} @ {:04x}:{:08x} (nsched: {})",
  506. thread.state_string(),
  507. thread.priority(),
  508. thread,
  509. get_cs(thread),
  510. get_eip(thread),
  511. thread.times_scheduled());
  512. break;
  513. }
  514. if (with_stack_traces)
  515. dbgln("{}", thread.backtrace());
  516. });
  517. }
  518. }