Scheduler.cpp 21 KB

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