Skip to content

feat(sched): round-robin time slicing below a threshold level (M2 leftover) - #42

Merged
teo1747 merged 2 commits into
mainfrom
feat/m2-time-slicing
Oct 31, 2026
Merged

teo1747 merged 2 commits into
mainfrom
feat/m2-time-slicing

Conversation

@teo1747

@teo1747 teo1747 commented Oct 31, 2026

Copy link
Copy Markdown
Member

Implements CONFIG_EMB_TIME_SLICING, which existed in Kconfig without an implementation (KRN-SCH-007, KRN-SCH-026, KRN-SCH-037; SPEC-003 §8, KRN-TIM-029). The project owner chose to "implement it now" to finish M2.

Behavior

  • A thread at or below CONFIG_EMB_TIMESLICE_PRIORITY (new; 255 means every level) gets CONFIG_EMB_TIMESLICE_TICKS at each dispatch.
  • When the quantum expires, it is renewed. If an equal-priority peer is READY, a per-CPU rotation flag makes the next decision put the thread behind its peers. A preempted thread still resumes ahead of its peers (KRN-SCH-041) and gets a fresh quantum.
  • The quantum is one more deadline in the tickless next-deadline computation, and one comparison in the periodic tick.
  • Slicing needs the list scheduler; on the table scheduler each level holds a single thread. It is off by default, so every existing configuration builds the same kernel; T1 stays at 4056 / 39.
  • A63 records the details for review: restart at dispatch, a yield without a peer, threshold changes while running, and the tickless counter.

Evidence

  • Model: _slice_start and _slice_check mirror the kernel, plus a new appended TIMESLICE scenario group explored exhaustively. 129 model tests pass, up from 122.
  • Bridge: the runner reports timeslice= and timeslice_prio= (only on slicing builds, so other captures stay byte-identical), and bridge.adapt adopts them.
    • New native-timeslice preset (quantum 2, threshold 20, periodic clock): seeds 1–3 × 40 runs gave 3560/3560 agreeing runs each.
    • Mutation check: a model without rotation diverges.
  • Tickless: new native-timeslice-tickless preset, conformance only.
    • A tickless quantum starts from the free-running counter, which can run ahead of the delivered ticks the model counts. Measured: 1 divergence in 5 × 3560 runs.
    • On that build the bridge refuses the combination and the differential checks are not registered.
  • Conformance: 4 new cases in test_sched.c, with a portable emb_test_spin_ticks() helper:
    • rotation behind every peer;
    • expiry without a peer;
    • two spinners sharing a level;
    • the threshold.
    • Mutation check: a kernel without rotation fails 2 of the 4.
  • Local runs, all passing:
    • native gcc/clang/release/tiny/periodic/timeslice/timeslice-tickless/asan/tsan/coverage;
    • QEMU cm3, cm4 ×3, rv32 ×3;
    • AVR uno ×3, within footprint thresholds;
    • EmbSIM uno, nucleo and c3.
    • The docs build has the 9 known shim warnings; Python tool suites, generate --check and check-banned are clean.
  • CI gains the native-timeslice and native-timeslice-tickless legs.

Docs

KRN-SCH-007/026/037/041 and KRN-TIM-029 statuses, SPEC-003 §8, the configuration guide (presets and scheduler options), the tasks guide, STATUS and CHANGELOG.

CONFIG_EMB_TIME_SLICING implements KRN-SCH-007, KRN-SCH-026 and
KRN-SCH-037 (SPEC-003 §8, KRN-TIM-029). A thread at or below
CONFIG_EMB_TIMESLICE_PRIORITY gets CONFIG_EMB_TIMESLICE_TICKS at each
dispatch. At expiry the quantum is renewed and, with a READY
equal-priority peer, a per-CPU rotation flag makes the next decision
place the thread behind its peers. The quantum is one more deadline in
the tickless computation and one comparison in the periodic tick. List
scheduler only. Off by default, so every existing configuration builds
the same kernel.

The reference model implements the same rules. The runner reports the
quantum and the threshold, and the bridge adopts them. native-timeslice
(periodic clock) checks slicing through the bridge, and
native-timeslice-tickless runs the conformance cases only: a tickless
quantum starts from the free-running counter, which the model does not
see. New conformance cases cover rotation behind every peer, expiry
without a peer, two spinners sharing a level and the threshold. A
portable emb_test_spin_ticks() helper supports them.

A63 records the details for review.

Signed-off-by: teo1747 <motsoujunior17@gmail.com>
@teo1747
teo1747 merged commit c6ecd02 into main Oct 31, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant