ZXFoundation™ 26h2
Loading...
Searching...
No Matches
core.cxx File Reference

Scheduler core — schedule(), tick, init, work-stealing, softirq, nohz. More...

import drivers.watchdog.core;
import lib.cpumask;
import lib.softirq.core;
import lib.error;
import arch.s390x.cpu.cputimer;
import zxfoundation.base.typestate;
import zxfoundation.base.types;
import zxfoundation.dgp.gate.core;
import zxfoundation.dgp.domain.types;
import zxfoundation.dgp.isolation;
import zxfoundation.sys.irq.core;
import arch.s390x.cpu.lowcore;
import zxfoundation.sched.cpupri.core;
import zxfoundation.sched.rt.bandwidth;
import zxfoundation.dgp.domain.core;
import zxfoundation.sched.cpudl.core;
import zxfoundation.sched.smt.core;
import zxfoundation.dgp.signal;
import zxfoundation.sync.qspinlock.core;
import zxfoundation.sched.numa.core;
import zxfoundation.sched.nohz.core;
import arch.s390x.cpu.processor;
import zxfoundation.memory.numa.types;
import lib.rbtree;
import zxfoundation.sched.pelt.core;
import zxfoundation.sched.sd.types;
import zxfoundation.sched.softirq.core;
import zxfoundation.sched.entity;
import zxfoundation.scoms.kobject.types;
import zxfoundation.sys.timer.types;
import zxfoundation.sched.topology.core;
import lib.format;
import zxfoundation.sched.sd.core;
import zxfoundation.sched.idle;
import arch.s390x.cpu.cpumask;
import arch.s390x.cpu.irq;
import zxfoundation.sched.topology.types;
import zxfoundation.base.config;
import zxfoundation.sched.strandctx.core;
import zxfoundation.sched.balance.core;
import zxfoundation.sys.syschk.core;
import zxfoundation.sched.fair.core;
import zxfoundation.sched.policy;
import zxfoundation.sched.rq_snapshot.core;
import zxfoundation.sched.classed.core;
import zxfoundation.sched.context.core;
import zxfoundation.scoms.kobject.ref;
import lib.container_of;
import zxfoundation.sys.time.core;
import arch.s390x.cpu.ctlreg;
import arch.s390x.cpu.ar;
import zxfoundation.dgp.isolation.types;
import arch.s390x.cpu.clock;
import zxfoundation.sched.cbs.core;
import zxfoundation.dgp.sync_contract;
import zxfoundation.sched.rt.core;
import zxfoundation.memory.hhdm;
import zxfoundation.sys.printk.core;
import zxfoundation.dgp.portal;
import zxfoundation.sys.timer.core;
import zxfoundation.sys.irq.consts;
import zxfoundation.sched.admit.core;
import arch.s390x.cpu.ipi;
import zxfoundation.smp.csd.core;
import std;
import lib.list;
import zxfoundation.scoms.kobject.base;
import arch.s390x.cpu.aste;
import arch.s390x.cpu.psw;
Include dependency graph for core.cxx:

Data Structures

struct  zxfoundation::sched::domain
 The domain struct — the central entity of the DGP kernel. More...
struct  zxfoundation::sched::run_queue
 Per-CPU run queue — schedules strands (execution contexts). More...
struct  zxfoundation::sched::sched_domain_tree
 Per-CPU sched_domain tree rooted at run_queue::sd. More...
struct  zxfoundation::sched::strand
 Strand — the DGP kernel's unit of schedulable execution. More...

Typedefs

using zxfoundation::sched::domain_id
 Opaque domain identifier.

Enumerations

enum class  zxfoundation::sched::domain_flags
 Per-domain flags (bitfield).
enum class  zxfoundation::sched::lifecycle_state
 Unified lifecycle states for ALL typestate-tracked resources. More...
enum class  zxfoundation::sched::sched_substate
 Scheduler substate within the active lifecycle.

Functions

auto zxfoundation::sched::cpu_down (u16 cpu_id) noexcept -> ::std::expected< void, ::lib::kernel_error >
 Notify the scheduler that a CPU is going offline.
auto zxfoundation::sched::cpu_rq (u16 cpu_id) noexcept -> run_queue &
auto zxfoundation::sched::cpu_timer (u16 cpu_id) noexcept -> zxfoundation::sys::timer::kernel_timer &
 Return the per-CPU periodic tick timer used by the nohz machinery.
auto zxfoundation::sched::cpu_timer_tick () noexcept -> void
 CPU timer quantum enforcement — fires when a strand's quantum expires.
auto zxfoundation::sched::cpu_up (u16 cpu_id) noexcept -> ::std::expected< void, ::lib::kernel_error >
 Notify the scheduler that a CPU has come online.
 declscope (C) auto sched_strand_trampoline_exit() noexcept -> void
auto zxfoundation::sched::dequeue_domain (domain *d) noexcept -> void
auto zxfoundation::sched::dequeue_strand (strand *s) noexcept -> void
auto zxfoundation::sched::domain_enter_user (strand *s) noexcept -> void
 Enter user mode for a domain.
auto zxfoundation::sched::detail::domain_reap (domain &d) noexcept -> void
auto zxfoundation::sched::enqueue_domain (domain *d) noexcept -> void
auto zxfoundation::sched::enqueue_strand (strand *s) noexcept -> void
auto zxfoundation::sched::idle_enter () noexcept -> void
auto zxfoundation::sched::irq_handler_cpu_timer (u16 irq, arch::s390x::cpu::irq::irq_frame *frame, void *data) noexcept -> void
 CPU timer IRQ handler — dispatches vector EXT_IRQ_CPU_TIMER.
auto zxfoundation::sched::need_resched () noexcept -> bool
auto zxfoundation::sched::preempt_schedule () noexcept -> void
auto zxfoundation::sched::quiesce_domain (domain &d) noexcept -> std::expected< void, lib::kernel_error >
 Quiesce every strand owned by a domain before identity teardown.
auto zxfoundation::sched::detail::record_asce_attachment (domain &d) noexcept -> void
auto zxfoundation::sched::sched_active () noexcept -> bool
auto zxfoundation::sched::sched_init () noexcept -> void
auto zxfoundation::sched::sched_init_ap (u16 cpu_id) noexcept -> void
auto zxfoundation::sched::sched_resched_current () noexcept -> void
 Mark the currently executing domain as needing rescheduling.
auto zxfoundation::sched::schedule () noexcept -> void
auto zxfoundation::sched::scheduler_tick () noexcept -> void
 Periodic scheduler tick.
auto zxfoundation::sched::detail::set_need_resched () noexcept -> void
auto zxfoundation::sched::setup_primary_strand_context (domain *d, strand_entry_fn entry, void *arg) noexcept -> void
 Convenience wrapper — kernel-thread first-switch for the primary strand of a domain.
auto zxfoundation::sched::setup_primary_strand_context_user (domain *d) noexcept -> void
 Convenience wrapper — user-process first-switch for the primary strand of a domain.
auto zxfoundation::sched::setup_strand_context_kernel_thread (strand *s, strand_entry_fn entry, void *arg) noexcept -> void
 Set up the initial kernel stack frame for a strand so that the.
auto zxfoundation::sched::setup_strand_context_user (strand *s, const user_regs *uregs, const domain *owner) noexcept -> void
 Set up the initial kernel stack frame for a strand whose first context switch performs an LPSWE into user mode.
auto zxfoundation::sched::strand_admit_policy (strand &s, const zxfoundation::sched::sched_policy &policy) noexcept -> std::expected< zxfoundation::sched::sched_admission_result, lib::kernel_error >
 Admit a scheduler policy for a strand before run-queue insertion.
auto zxfoundation::sched::strand_spawn (const zxfoundation::dgp::domain::strand_create_request &request) noexcept -> std::expected< zxfoundation::dgp::domain::strand *, lib::kernel_error >
 Create and optionally enqueue a secondary strand for a DGP domain.
auto zxfoundation::sched::strand_trampoline_exit () noexcept -> void
auto zxfoundation::sched::this_rq () noexcept -> run_queue &
auto zxfoundation::sched::detail::try_steal_strand_locked (run_queue &local_rq) noexcept -> strand *
 Hierarchical work stealing walking the sched_domain tree.
auto zxfoundation::sched::detail::validate_scheduler_irq_context (u32 domain_id=0U) noexcept -> void

Variables

no_export std::array< sys::timer::kernel_timer, zxfoundation::base::config::CONFIG_ZX_MAX_CPUS > zxfoundation::sched::detail::g_ap_tick_timers {}
no_export sys::timer::kernel_timer zxfoundation::sched::detail::g_bsp_tick_timer {}
no_export std::array< run_queue, zxfoundation::base::config::CONFIG_ZX_MAX_CPUS > zxfoundation::sched::detail::g_rqs {}
no_export bool zxfoundation::sched::detail::g_sched_initialized {false}

Detailed Description

Scheduler core — schedule(), tick, init, work-stealing, softirq, nohz.

SPDX-License-Identifier: Apache-2.0

Enumeration Type Documentation

◆ lifecycle_state

enum class zxfoundation::base::lifecycle_state : u8
strong

Unified lifecycle states for ALL typestate-tracked resources.

Every SCOMS-managed object, every folio, and every slab cache uses exactly these states. No subsystem may define its own.

Function Documentation

◆ cpu_down()

auto zxfoundation::sched::cpu_down ( u16 cpu_id) ->::std::expected< void,::lib::kernel_error >
nodiscardexportnoexcept

Notify the scheduler that a CPU is going offline.

Parameters
[in]cpu_idLogical CPU ID going offline.
Returns
Success or kernel_error.

◆ domain_enter_user()

Enter user mode for a domain.

Enter user mode for a domain at runtime.

Parameters
sStrand with valid body->uregs; domain accessed via s->owner.

◆ quiesce_domain()

auto zxfoundation::sched::quiesce_domain ( domain & d) ->std::expected< void, lib::kernel_error >
nodiscardexportnoexcept

Quiesce every strand owned by a domain before identity teardown.

Parameters
[in]dDomain entering the dying state.
Returns
Success when no strand is running and all runnable strands are removed.

◆ setup_strand_context_kernel_thread()

auto zxfoundation::sched::strandctx::setup_strand_context_kernel_thread ( strand * s,
strand_entry_fn entry,
void * arg )->void
noexcept

Set up the initial kernel stack frame for a strand so that the.

Parameters
sTarget strand with valid kstack_top
entryNon-null kernel entry function
argOpaque argument passed to entry in r2

◆ setup_strand_context_user()

auto zxfoundation::sched::strandctx::setup_strand_context_user ( strand * s,
const user_regs * uregs,
const domain * owner )->void
noexcept

Set up the initial kernel stack frame for a strand whose first context switch performs an LPSWE into user mode.

Parameters
sTarget strand with valid kstack_top and body->uregs already populated
uregsPointer to the user_regs snapshot
ownerThe owning domain, used for ASC normalization and DGP isolation validation.

◆ strand_admit_policy()

auto zxfoundation::sched::strand_admit_policy ( strand & s,
const zxfoundation::sched::sched_policy & policy )->std::expected< zxfoundation::sched::sched_admission_result, lib::kernel_error >
nodiscardexportnoexcept

Admit a scheduler policy for a strand before run-queue insertion.

Parameters
[in,out]sStrand receiving the policy metadata.
[in]policyRequested scheduler policy.
Returns
Admission record on success, or kernel_error when DGP/class policy denies the request.

◆ strand_spawn()

auto zxfoundation::sched::strand_spawn ( const zxfoundation::dgp::domain::strand_create_request & request) ->std::expected< zxfoundation::dgp::domain::strand *, lib::kernel_error >
nodiscardexportnoexcept

Create and optionally enqueue a secondary strand for a DGP domain.

Parameters
[in]requestExecutor-style creation request selecting one of three strand kinds:
  • Kernel-thread: entry != nullptr, uregs == nullptr. The strand's first __switch_to_asm dispatches via ret_from_fork to domain_trampoline, which invokes entry(arg) on the kernel stack and then tail-calls sched_strand_trampoline_exit (the do_exit analog).
  • User-process: entry == nullptr, uregs != nullptr with psw_addr != 0. The strand's first __switch_to_asm dispatches via ret_from_fork to ret_to_user, which LPSWEs into user mode at uregs->psw_addr with uregs->psw_mask. The AR/VR/FPC state from uregs is pre-staged in the strand's save area so __switch_to_asm itself restores them onto the CPU before control reaches ret_from_fork.
  • Bare (idle): entry == nullptr AND uregs == nullptr. The strand is allocated but no first-switch frame is written. request.enqueue MUST be false (a bare strand with no entry must not be admitted to a run queue — scheduling it would LPSWE into garbage). Useful for SCOMS bookkeeping paths that need a strand object but have no runnable work yet.
Returns
Pointer to the created strand, or kernel_error if validation, allocation, or admission fails.
Warning
The kernel-thread and user-process modes are mutually exclusive: entry != nullptr AND uregs != nullptr is rejected with invalid_arg. The bare mode requires enqueue == false.

The kthread vs user split mirrors Linux copy_thread:

  • Kernel-thread: entry(arg) runs on the new strand's kernel stack and tail-calls sched_strand_trampoline_exit on return.
  • User-process: the new strand's first context switch LPSWEs into user mode at uregs->psw_addr with uregs->psw_mask.
Parameters
[in]requestExecutor-style creation request selecting one of three strand kinds (kernel-thread, user-process, bare). See zxfoundation::dgp::domain::strand_create_request for the full duality documentation.
Returns
Pointer to the created strand, or kernel_error if validation, allocation, or admission fails.

◆ try_steal_strand_locked()

auto zxfoundation::sched::detail::try_steal_strand_locked ( run_queue & local_rq) ->strand *
noexcept

Hierarchical work stealing walking the sched_domain tree.

Parameters
[in,out]local_rqThe idle CPU's run queue (lock held on entry).
Returns
A stolen strand, or nullptr.
Note
The stolen strand's se.vruntime is normalized to the local run queue's min_vruntime;