Scheduler.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  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 constexpr u32 g_ready_queue_buckets = sizeof(g_ready_queues_mask) * 8;
  45. READONLY_AFTER_INIT static ThreadReadyQueue* g_ready_queues; // g_ready_queue_buckets entries
  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) * (g_ready_queue_buckets - 1);
  60. VERIFY(priority_bucket < g_ready_queue_buckets);
  61. return priority_bucket;
  62. }
  63. Thread& Scheduler::pull_next_runnable_thread()
  64. {
  65. auto affinity_mask = 1u << Processor::id();
  66. ScopedSpinLock lock(g_ready_queues_lock);
  67. auto priority_mask = g_ready_queues_mask;
  68. while (priority_mask != 0) {
  69. auto priority = __builtin_ffsl(priority_mask);
  70. VERIFY(priority > 0);
  71. auto& ready_queue = g_ready_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. g_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. Thread* Scheduler::peek_next_runnable_thread()
  99. {
  100. auto affinity_mask = 1u << Processor::id();
  101. ScopedSpinLock lock(g_ready_queues_lock);
  102. auto priority_mask = g_ready_queues_mask;
  103. while (priority_mask != 0) {
  104. auto priority = __builtin_ffsl(priority_mask);
  105. VERIFY(priority > 0);
  106. auto& ready_queue = g_ready_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. bool Scheduler::dequeue_runnable_thread(Thread& thread, bool check_affinity)
  123. {
  124. if (thread.is_idle_thread())
  125. return true;
  126. ScopedSpinLock lock(g_ready_queues_lock);
  127. auto priority = thread.m_runnable_priority;
  128. if (priority < 0) {
  129. VERIFY(!thread.m_ready_queue_node.is_in_list());
  130. return false;
  131. }
  132. if (check_affinity && !(thread.affinity() & (1 << Processor::id())))
  133. return false;
  134. VERIFY(g_ready_queues_mask & (1u << priority));
  135. auto& ready_queue = g_ready_queues[priority];
  136. thread.m_runnable_priority = -1;
  137. ready_queue.thread_list.remove(thread);
  138. if (ready_queue.thread_list.is_empty())
  139. g_ready_queues_mask &= ~(1u << priority);
  140. return true;
  141. }
  142. void Scheduler::queue_runnable_thread(Thread& thread)
  143. {
  144. VERIFY(g_scheduler_lock.own_lock());
  145. if (thread.is_idle_thread())
  146. return;
  147. auto priority = thread_priority_to_priority_index(thread.priority());
  148. ScopedSpinLock lock(g_ready_queues_lock);
  149. VERIFY(thread.m_runnable_priority < 0);
  150. thread.m_runnable_priority = (int)priority;
  151. VERIFY(!thread.m_ready_queue_node.is_in_list());
  152. auto& ready_queue = g_ready_queues[priority];
  153. bool was_empty = ready_queue.thread_list.is_empty();
  154. ready_queue.thread_list.append(thread);
  155. if (was_empty)
  156. g_ready_queues_mask |= (1u << priority);
  157. }
  158. UNMAP_AFTER_INIT void Scheduler::start()
  159. {
  160. VERIFY_INTERRUPTS_DISABLED();
  161. // We need to acquire our scheduler lock, which will be released
  162. // by the idle thread once control transferred there
  163. g_scheduler_lock.lock();
  164. auto& processor = Processor::current();
  165. processor.set_scheduler_data(*new SchedulerPerProcessorData());
  166. VERIFY(processor.is_initialized());
  167. auto& idle_thread = *Processor::idle_thread();
  168. VERIFY(processor.current_thread() == &idle_thread);
  169. idle_thread.set_ticks_left(time_slice_for(idle_thread));
  170. idle_thread.did_schedule();
  171. idle_thread.set_initialized(true);
  172. processor.init_context(idle_thread, false);
  173. idle_thread.set_state(Thread::Running);
  174. VERIFY(idle_thread.affinity() == (1u << processor.get_id()));
  175. processor.initialize_context_switching(idle_thread);
  176. VERIFY_NOT_REACHED();
  177. }
  178. bool Scheduler::pick_next()
  179. {
  180. VERIFY_INTERRUPTS_DISABLED();
  181. // Set the m_in_scheduler flag before acquiring the spinlock. This
  182. // prevents a recursive call into Scheduler::invoke_async upon
  183. // leaving the scheduler lock.
  184. ScopedCritical critical;
  185. auto& scheduler_data = Processor::current().get_scheduler_data();
  186. scheduler_data.m_in_scheduler = true;
  187. ScopeGuard guard(
  188. []() {
  189. // We may be on a different processor after we got switched
  190. // back to this thread!
  191. auto& scheduler_data = Processor::current().get_scheduler_data();
  192. VERIFY(scheduler_data.m_in_scheduler);
  193. scheduler_data.m_in_scheduler = false;
  194. });
  195. ScopedSpinLock lock(g_scheduler_lock);
  196. if constexpr (SCHEDULER_RUNNABLE_DEBUG) {
  197. dump_thread_list();
  198. }
  199. auto& thread_to_schedule = pull_next_runnable_thread();
  200. if constexpr (SCHEDULER_DEBUG) {
  201. dbgln("Scheduler[{}]: Switch to {} @ {:#04x}:{:p}",
  202. Processor::id(),
  203. thread_to_schedule,
  204. thread_to_schedule.regs().cs, thread_to_schedule.regs().ip());
  205. }
  206. // We need to leave our first critical section before switching context,
  207. // but since we're still holding the scheduler lock we're still in a critical section
  208. critical.leave();
  209. thread_to_schedule.set_ticks_left(time_slice_for(thread_to_schedule));
  210. return context_switch(&thread_to_schedule);
  211. }
  212. bool Scheduler::yield()
  213. {
  214. InterruptDisabler disabler;
  215. auto& proc = Processor::current();
  216. auto current_thread = Thread::current();
  217. dbgln_if(SCHEDULER_DEBUG, "Scheduler[{}]: yielding thread {} in_irq={}", proc.get_id(), *current_thread, proc.in_irq());
  218. VERIFY(current_thread != nullptr);
  219. if (proc.in_irq() || proc.in_critical()) {
  220. // If we're handling an IRQ we can't switch context, or we're in
  221. // a critical section where we don't want to switch contexts, then
  222. // delay until exiting the trap or critical section
  223. proc.invoke_scheduler_async();
  224. return false;
  225. }
  226. if (!Scheduler::pick_next())
  227. return false;
  228. if constexpr (SCHEDULER_DEBUG)
  229. dbgln("Scheduler[{}]: yield returns to thread {} in_irq={}", Processor::id(), *current_thread, Processor::current().in_irq());
  230. return true;
  231. }
  232. bool Scheduler::context_switch(Thread* thread)
  233. {
  234. if (s_mm_lock.own_lock()) {
  235. PANIC("In context switch while holding s_mm_lock");
  236. }
  237. thread->did_schedule();
  238. auto from_thread = Thread::current();
  239. if (from_thread == thread)
  240. return false;
  241. if (from_thread) {
  242. // If the last process hasn't blocked (still marked as running),
  243. // mark it as runnable for the next round.
  244. if (from_thread->state() == Thread::Running)
  245. from_thread->set_state(Thread::Runnable);
  246. #ifdef LOG_EVERY_CONTEXT_SWITCH
  247. const auto msg = "Scheduler[{}]: {} -> {} [prio={}] {:#04x}:{:p}";
  248. dbgln(msg,
  249. Processor::id(), from_thread->tid().value(),
  250. thread->tid().value(), thread->priority(), thread->regs().cs, thread->regs().ip());
  251. #endif
  252. }
  253. auto& proc = Processor::current();
  254. if (!thread->is_initialized()) {
  255. proc.init_context(*thread, false);
  256. thread->set_initialized(true);
  257. }
  258. thread->set_state(Thread::Running);
  259. PerformanceManager::add_context_switch_perf_event(*from_thread, *thread);
  260. proc.switch_context(from_thread, thread);
  261. // NOTE: from_thread at this point reflects the thread we were
  262. // switched from, and thread reflects Thread::current()
  263. enter_current(*from_thread, false);
  264. VERIFY(thread == Thread::current());
  265. if (thread->process().is_user_process()) {
  266. auto& regs = Thread::current()->get_register_dump_from_stack();
  267. auto iopl = get_iopl_from_eflags(regs.flags());
  268. if (iopl != 0) {
  269. PANIC("Switched to thread {} with non-zero IOPL={}", Thread::current()->tid().value(), iopl);
  270. }
  271. }
  272. return true;
  273. }
  274. void Scheduler::enter_current(Thread& prev_thread, bool is_first)
  275. {
  276. VERIFY(g_scheduler_lock.own_lock());
  277. // We already recorded the scheduled time when entering the trap, so this merely accounts for the kernel time since then
  278. auto scheduler_time = Scheduler::current_time();
  279. prev_thread.update_time_scheduled(scheduler_time, true, true);
  280. auto* current_thread = Thread::current();
  281. current_thread->update_time_scheduled(scheduler_time, true, false);
  282. prev_thread.set_active(false);
  283. if (prev_thread.state() == Thread::Dying) {
  284. // If the thread we switched from is marked as dying, then notify
  285. // the finalizer. Note that as soon as we leave the scheduler lock
  286. // the finalizer may free from_thread!
  287. notify_finalizer();
  288. } else if (!is_first) {
  289. // Check if we have any signals we should deliver (even if we don't
  290. // end up switching to another thread).
  291. if (!current_thread->is_in_block() && current_thread->previous_mode() != Thread::PreviousMode::KernelMode) {
  292. ScopedSpinLock lock(current_thread->get_lock());
  293. if (current_thread->state() == Thread::Running && current_thread->pending_signals_for_state()) {
  294. current_thread->dispatch_one_pending_signal();
  295. }
  296. }
  297. }
  298. }
  299. void Scheduler::leave_on_first_switch(u32 flags)
  300. {
  301. // This is called when a thread is switched into for the first time.
  302. // At this point, enter_current has already be called, but because
  303. // Scheduler::context_switch is not in the call stack we need to
  304. // clean up and release locks manually here
  305. g_scheduler_lock.unlock(flags);
  306. auto& scheduler_data = Processor::current().get_scheduler_data();
  307. VERIFY(scheduler_data.m_in_scheduler);
  308. scheduler_data.m_in_scheduler = false;
  309. }
  310. void Scheduler::prepare_after_exec()
  311. {
  312. // This is called after exec() when doing a context "switch" into
  313. // the new process. This is called from Processor::assume_context
  314. VERIFY(g_scheduler_lock.own_lock());
  315. auto& scheduler_data = Processor::current().get_scheduler_data();
  316. VERIFY(!scheduler_data.m_in_scheduler);
  317. scheduler_data.m_in_scheduler = true;
  318. }
  319. void Scheduler::prepare_for_idle_loop()
  320. {
  321. // This is called when the CPU finished setting up the idle loop
  322. // and is about to run it. We need to acquire he scheduler lock
  323. VERIFY(!g_scheduler_lock.own_lock());
  324. g_scheduler_lock.lock();
  325. auto& scheduler_data = Processor::current().get_scheduler_data();
  326. VERIFY(!scheduler_data.m_in_scheduler);
  327. scheduler_data.m_in_scheduler = true;
  328. }
  329. Process* Scheduler::colonel()
  330. {
  331. VERIFY(s_colonel_process);
  332. return s_colonel_process;
  333. }
  334. static u64 current_time_tsc()
  335. {
  336. return read_tsc();
  337. }
  338. static u64 current_time_monotonic()
  339. {
  340. // We always need a precise timestamp here, we cannot rely on a coarse timestamp
  341. return (u64)TimeManagement::the().monotonic_time(TimePrecision::Precise).to_nanoseconds();
  342. }
  343. UNMAP_AFTER_INIT void Scheduler::initialize()
  344. {
  345. VERIFY(Processor::is_initialized()); // sanity check
  346. // Figure out a good scheduling time source
  347. if (Processor::current().has_feature(CPUFeature::TSC)) {
  348. // TODO: only use if TSC is running at a constant frequency?
  349. current_time = current_time_tsc;
  350. } else {
  351. // TODO: Using HPET is rather slow, can we use any other time source that may be faster?
  352. current_time = current_time_monotonic;
  353. }
  354. RefPtr<Thread> idle_thread;
  355. g_finalizer_wait_queue = new WaitQueue;
  356. g_ready_queues = new ThreadReadyQueue[g_ready_queue_buckets];
  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(StringView("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, 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. ScopedSpinLock lock(g_total_time_scheduled_lock);
  384. g_total_time_scheduled.total += time_to_add;
  385. if (is_kernel)
  386. g_total_time_scheduled.total_kernel += time_to_add;
  387. }
  388. void Scheduler::timer_tick(const RegisterState& regs)
  389. {
  390. VERIFY_INTERRUPTS_DISABLED();
  391. VERIFY(Processor::current().in_irq());
  392. auto current_thread = Processor::current_thread();
  393. if (!current_thread)
  394. return;
  395. // Sanity checks
  396. VERIFY(current_thread->current_trap());
  397. VERIFY(current_thread->current_trap()->regs == &regs);
  398. #if !SCHEDULE_ON_ALL_PROCESSORS
  399. if (!Processor::is_bootstrap_processor())
  400. return; // TODO: This prevents scheduling on other CPUs!
  401. #endif
  402. if (current_thread->process().is_kernel_process()) {
  403. // Because the previous mode when entering/exiting kernel threads never changes
  404. // we never update the time scheduled. So we need to update it manually on the
  405. // timer interrupt
  406. current_thread->update_time_scheduled(current_time(), true, false);
  407. }
  408. if (current_thread->previous_mode() == Thread::PreviousMode::UserMode && current_thread->should_die() && !current_thread->is_blocked()) {
  409. ScopedSpinLock scheduler_lock(g_scheduler_lock);
  410. dbgln_if(SCHEDULER_DEBUG, "Scheduler[{}]: Terminating user mode thread {}", Processor::id(), *current_thread);
  411. current_thread->set_state(Thread::Dying);
  412. Processor::current().invoke_scheduler_async();
  413. return;
  414. }
  415. if (current_thread->tick())
  416. return;
  417. if (!current_thread->is_idle_thread() && !peek_next_runnable_thread()) {
  418. // If no other thread is ready to be scheduled we don't need to
  419. // switch to the idle thread. Just give the current thread another
  420. // time slice and let it run!
  421. current_thread->set_ticks_left(time_slice_for(*current_thread));
  422. current_thread->did_schedule();
  423. dbgln_if(SCHEDULER_DEBUG, "Scheduler[{}]: No other threads ready, give {} another timeslice", Processor::id(), *current_thread);
  424. return;
  425. }
  426. VERIFY_INTERRUPTS_DISABLED();
  427. VERIFY(Processor::current().in_irq());
  428. Processor::current().invoke_scheduler_async();
  429. }
  430. void Scheduler::invoke_async()
  431. {
  432. VERIFY_INTERRUPTS_DISABLED();
  433. auto& proc = Processor::current();
  434. VERIFY(!proc.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 (!proc.get_scheduler_data().m_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.get_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::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. ScopedSpinLock lock(g_total_time_scheduled_lock);
  476. return g_total_time_scheduled;
  477. }
  478. void dump_thread_list(bool with_stack_traces)
  479. {
  480. dbgln("Scheduler thread list for processor {}:", Processor::id());
  481. auto get_cs = [](Thread& thread) -> u16 {
  482. if (!thread.current_trap())
  483. return thread.regs().cs;
  484. return thread.get_register_dump_from_stack().cs;
  485. };
  486. auto get_eip = [](Thread& thread) -> u32 {
  487. if (!thread.current_trap())
  488. return thread.regs().ip();
  489. return thread.get_register_dump_from_stack().ip();
  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. }