Scheduler.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Assertions.h>
  8. #include <AK/Function.h>
  9. #include <AK/IntrusiveList.h>
  10. #include <AK/Types.h>
  11. #include <Kernel/Forward.h>
  12. #include <Kernel/Locking/Spinlock.h>
  13. #include <Kernel/Time/TimeManagement.h>
  14. #include <Kernel/UnixTypes.h>
  15. namespace Kernel {
  16. struct RegisterState;
  17. extern Thread* g_finalizer;
  18. extern WaitQueue* g_finalizer_wait_queue;
  19. extern Atomic<bool> g_finalizer_has_work;
  20. extern RecursiveSpinlock g_scheduler_lock;
  21. struct TotalTimeScheduled {
  22. u64 total { 0 };
  23. u64 total_kernel { 0 };
  24. };
  25. class Scheduler {
  26. public:
  27. static void initialize();
  28. static Thread* create_ap_idle_thread(u32 cpu);
  29. static void set_idle_thread(Thread* idle_thread);
  30. static void timer_tick(const RegisterState&);
  31. [[noreturn]] static void start();
  32. static bool pick_next();
  33. static bool yield();
  34. static bool context_switch(Thread*);
  35. static void enter_current(Thread& prev_thread, bool is_first);
  36. static void leave_on_first_switch(u32 flags);
  37. static void prepare_after_exec();
  38. static void prepare_for_idle_loop();
  39. static Process* colonel();
  40. static void idle_loop(void*);
  41. static void invoke_async();
  42. static void notify_finalizer();
  43. static Thread& pull_next_runnable_thread();
  44. static Thread* peek_next_runnable_thread();
  45. static bool dequeue_runnable_thread(Thread&, bool = false);
  46. static void enqueue_runnable_thread(Thread&);
  47. static void dump_scheduler_state(bool = false);
  48. static bool is_initialized();
  49. static TotalTimeScheduled get_total_time_scheduled();
  50. static void add_time_scheduled(u64, bool);
  51. static u64 (*current_time)();
  52. };
  53. }