Skip to main content

Module scheduler

Module scheduler 

Source
Expand description

Work scheduler - priority-aware slot scanning for the persistent megakernel.

Extends the base slot-claim logic with priority partitioning: each priority level occupies a contiguous partition of the ring buffer. Workers scan from highest priority (0=CRITICAL) to lowest (4=IDLE), claiming the first PUBLISHED slot found. This ensures latency-sensitive work is processed before background tasks without true preemption.

§Slot Layout Extension

The priority is encoded in ring_buffer[slot_base + PRIORITY_WORD]. The host sets this when publishing; the scheduler reads it to sort work into the right scan order.

§Starvation Guard

After STARVATION_THRESHOLD consecutive high-priority claims, the scheduler forcibly scans lower-priority partitions for one iteration. This prevents priority inversion where a flood of CRITICAL slots starves NORMAL/“background” work indefinitely.

Modules§

priority
Priority discriminants.

Constants§

PRIORITY_LEVELS
Number of priority levels the scheduler supports.
PRIORITY_OFFSETS_BASE
Control word storing the priority partition offsets. control[PRIORITY_OFFSETS_BASE + pri] = first slot index for priority pri. control[PRIORITY_OFFSETS_BASE + PRIORITY_LEVELS] = total slot count (sentinel).
PRIORITY_STARVATION_COUNTER
Control word storing consecutive high-priority claims.
STARVATION_THRESHOLD
After this many consecutive claims at the same (or higher) priority, the scheduler forcibly scans lower-priority partitions for one iteration.
TENANT_FAIRNESS_THRESHOLD
After this many claims by a single tenant in a single worker’s “epoch”, the tenant is considered “greedy” and may be throttled.

Functions§

check_priority_fairness
Policy helper: check if a priority level has exceeded its fairness quota.
check_tenant_fairness
Policy helper: check if a tenant has exceeded its fairness quota.
default_priority_offsets_array
Encode default priority partition offsets into a fixed array without allocation.
policy_offset_start
Policy helper: select the next slot to probe within a partition.
priority_partition_active_lane_count
Number of lanes that should actively probe one priority partition.
priority_partition_probe_budget
Upper bound on slot status probes for one priority partition.
priority_partition_probe_count
Number of strided probes each lane needs to cover a priority partition.
priority_scan_body
Build the priority-aware scan loop as Vec<Node> for composition.
priority_scan_body_with_stride
Build the priority-aware scan loop with an explicit global worker stride.
write_default_priority_offsets
Write default priority partition offsets into an encoded control buffer.