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 prioritypri.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.