ZXFoundation™ 26h2
Loading...
Searching...
No Matches
core.cxxm
Go to the documentation of this file.
1/// SPDX-License-Identifier: Apache-2.0
2/// @file zxfoundation/sched/core.cxxm
3/// @brief Scheduler core — schedule(), tick, init, work-stealing, softirq, nohz.
4
5export module zxfoundation.sched.core;
6import zxfoundation.sched.policy;
7import zxfoundation.dgp.domain.types;
8import zxfoundation.base.types;
9import zxfoundation.sys.timer.types;
10import zxfoundation.sched.rq.types;
11import arch.s390x.cpu.irq;
12import lib.error;
13import std;
14
15using zxfoundation::dgp::domain::domain;
16using zxfoundation::dgp::domain::strand;
17using zxfoundation::sched::rq::run_queue;
18
19export {
20
21namespace zxfoundation::sched {
22
23 [[nodiscard]] auto cpu_timer(u16 cpu_id) noexcept -> zxfoundation::sys::timer::kernel_timer&;
24 [[nodiscard]] auto cpu_rq(u16 cpu_id) noexcept -> run_queue&;
25 [[nodiscard]] auto this_rq() noexcept -> run_queue&;
26
27 declscope(C) auto __switch_to_asm(
28 strand* prev,
29 strand* next
30 ) noexcept -> domain*;
31
32 auto enqueue_strand(strand* s) noexcept -> void;
33 auto dequeue_strand(strand* s) noexcept -> void;
34 auto enqueue_domain(domain* d) noexcept -> void;
35 auto dequeue_domain(domain* d) noexcept -> void;
36
37 /// @brief Admit a scheduler policy for a strand before run-queue insertion.
38 /// @param[in,out] s Strand receiving the policy metadata.
39 /// @param[in] policy Requested scheduler policy.
40 /// @return Admission record on success, or kernel_error when DGP/class policy denies the request.
41 [[nodiscard]] auto strand_admit_policy(
42 strand& s,
43 const zxfoundation::sched::sched_policy& policy
44 ) noexcept -> std::expected<zxfoundation::sched::sched_admission_result, lib::kernel_error>;
45
46 /// @brief Create and optionally enqueue a secondary strand for a DGP domain.
47 /// @param[in] request Executor-style creation request selecting one of
48 /// three strand kinds (kernel-thread, user-process, bare).
49 /// See @c zxfoundation::dgp::domain::strand_create_request
50 /// for the full duality documentation.
51 /// @return Pointer to the created strand, or kernel_error if validation,
52 /// allocation, or admission fails.
53 [[nodiscard]] auto strand_spawn(
54 const zxfoundation::dgp::domain::strand_create_request& request
55 ) noexcept -> std::expected<zxfoundation::dgp::domain::strand*, lib::kernel_error>;
56
57 /// @brief Quiesce every strand owned by a domain before identity teardown.
58 /// @param[in] d Domain entering the dying state.
59 /// @return Success when no strand is running and all runnable strands are removed.
60 [[nodiscard]] auto quiesce_domain(domain& d) noexcept
61 -> std::expected<void, lib::kernel_error>;
62
63 auto schedule() noexcept -> void;
64 [[noreturn]] auto strand_trampoline_exit() noexcept -> void;
65
66 /// @brief CPU timer quantum enforcement — fires when a strand's quantum expires.
67 auto cpu_timer_tick() noexcept -> void;
68
69 /// @brief CPU timer IRQ handler — dispatches vector EXT_IRQ_CPU_TIMER.
70 auto irq_handler_cpu_timer(
71 u16 irq,
72 arch::s390x::cpu::irq::irq_frame* frame,
73 void* data
74 ) noexcept -> void;
75
76 /// @brief Periodic scheduler tick
77 auto scheduler_tick() noexcept -> void;
78
79 [[nodiscard]] auto need_resched() noexcept -> bool;
80
81 /// @brief Mark the currently executing domain as needing rescheduling.
82 auto sched_resched_current() noexcept -> void;
83
84 auto preempt_schedule() noexcept -> void;
85
86 [[nodiscard]] auto sched_active() noexcept -> bool;
87
88 auto sched_init() noexcept -> void;
89 auto sched_init_ap(u16 cpu_id) noexcept -> void;
90
91 [[noreturn]] auto idle_enter() noexcept -> void;
92
93 /// @brief Notify the scheduler that a CPU has come online.
94 [[nodiscard]] auto cpu_up(u16 cpu_id) noexcept -> ::std::expected<void, ::lib::kernel_error>;
95
96 /// @brief Notify the scheduler that a CPU is going offline.
97 /// @param[in] cpu_id Logical CPU ID going offline.
98 /// @return Success or kernel_error.
99 [[nodiscard]] auto cpu_down(u16 cpu_id) noexcept -> ::std::expected<void, ::lib::kernel_error>;
100
101} // namespace zxfoundation::sched
102
103} // end export