Expand description
The concurrency-lowering knob for the C-family backends.
LOGOS’s deterministic concurrency (channels / tasks / Await the first of / virtual-time Sleep)
needs a task to SUSPEND at a blocking op and RESUME later. There are two ways to lower that suspend,
and — like the CUDA crate::codegen_cuda::CudaKnobs lattice — neither is strictly better, so it
is a knob with a documented trade-off (ConcurrencyLowering::tradeoffs). Unlike most knobs, one end
is capability-forced: a target with no ucontext/setjmp (a GPU kernel, WASM, bare metal) can
ONLY do the stackless form. So the lattice point is chosen by ConcurrencyLowering::for_target:
the best-general choice each target can express.
ConcurrencyLowering::Ucontext— stackful coroutines (getcontext/makecontext/swapcontext). A blocking op yields mid-loop / mid-nested-call and the native stack survives, so codegen is SIMPLE (emit native code + alogos_yield()at each blocking point) and straight-line code runs at native speed with arbitrary nesting. But it needsucontext/setjmp(host, RISC-V under qemu, a Tensix baby core) and a full stack per task (~256 KB). This is the RISC-V tier’s approach today.ConcurrencyLowering::Stackless— a state machine: each task body is transformed into a resumableswitchover its blocking points, with live locals hoisted into a heap frame. UNIVERSAL (CUDA device, WASM, embedded — no OS/libc), a tiny per-task frame, cheap function-return yields, and it scales to many tasks. But codegen is COMPLEX (the async/await-style transform) and each resume pays a smallswitch-dispatch cost. This is what the CUDA tier requires.
Structs§
- Concurrency
Tradeoff - One knob’s trade-off — the regime where the setting wins and where it loses (why it can’t be
baked in unconditionally). Mirrors
crate::codegen_cuda::KnobTradeoffbut kept local socodegen_cdoes not depend oncodegen_cuda. - Scheduler
Config - All scheduler knobs, bundled. Has a
Defaultand fluent setters so it is easy to annotate while still having a sensible baseline. - Scheduler
Knobs - The knobs that parameterize the emitted deterministic scheduler. This is the SAME
SchedulerConfigthe oracle runtime (logicaffeine_runtime) runs — the ready-queuepolicy(FIFO / LIFO / round-robin / seeded-random / priority), theclock(virtualLogicalvsWall), the default channel capacity, and the M:Nworkerscount (1 = cooperative single core, N = work-stealing) — plus theseedthat drives the seeded chooser for the random-choice points (TaskPickunderRandom,SelectWinner,TimerTieBreak). Emitting C straight from aSchedulerConfigguarantees the AOT scheduler’s knobs are ONE-TO-ONE with the oracle’s, so a program run atknobson the VM and the sameknobsin AOT-C agree.
Enums§
- CTarget
- A C-family lowering target, classified by whether it can express stackful coroutines. The
concurrency knob is forced to
ConcurrencyLowering::Stacklessexactly whenucontextis absent. - Clock
Mode - How the scheduler’s clock advances.
- Concurrency
Lowering - How the C-family backend lowers a task’s suspend/resume. One point in the (one-dimensional) knob
lattice; pick with
ConcurrencyLowering::for_target. - Schedule
Policy - The ready-task selection discipline. Determinism holds under every policy:
Fifo/Lifo/RoundRobin/Priorityare deterministic by construction, andRandomresolves its pick through the seededChooser, so it is reproducible under a fixed seed.