Repository navigation
state_exec: threaded execution's S2a, the continuous pool - #1404
Conversation
S2a.0 of threaded execution's S2a (S2.md section 2): the declarations the continuous pool's implementers code against, with stubs that keep today's behaviour. - detail::wakeup gains a notifier (set_notifier, has_notifier; S2-Q2): kept, not yet called. - process_table::best_runnable(), the best effective priority among runnable processes. - async_scheduler: set_wake_notifier, the run loop's report (run_report, last_run_report), and the long-step monitor's settings (set_long_step_sink, set_long_step_default, long_steps). - exec_group: pump_result's runnable, next_deadline, deadline_precise and best_runnable, copied from the run loop's report; group_pool_link's state word with its transitions (S2-Q4), and the attachment. - exec_pool: pool_options' pump_steps, pump_seconds, priority_weights and force_move; the Stage 2 counters; attach, detach, pump_host, wait_for_work, with_group, take_failed and attached (attach and detach mark the group, the rest are stubs); detail::detach_begin and detach_end for an attached group's teardown; the host-queue rules for attached groups (S2-Q5). pump_all refuses an attached group (an assertion, std::logic_error in release builds). Frozen for S2a: the state word's bits and transitions, the notifier's lock order, the host-queue rules, pump_result's meaning and pump_all's refusal of attached groups.
S2a.9 (S2.md section 4), written from the plan and S2a.0's frozen API before the implementation lands. Each file's cases are at its end under the Stage 2a banner (RA-1 just above the script's runner, which collects the test_ functions there). - exec_pool_test: PL-2 (the eventcount under CVC_EXEC_FUZZ: every post's receiver runs), PL-3 (a host post wakes a parked pool), PL-4 (a lone sleeper pumped once at its deadline, no empty wake), PL-5 (a light group waits out at most the heavy pump in progress), PL-9 (a blocked worker blocks only its group; the long-step monitor names the native), PL-10 (~exec_pool joins after eight busy groups are detached: thread and handle counts). - state_exec_groups_test: CT-1 (GR-1's oracle attached at threads 0, 1, 2, 4, 8), CT-2 (teardown while workers re-pump, fuzzed: no pump after the token, no notifier or wake after the detach), CT-3 (host bodies and the token; with_group leaves a popped group notified), CT-4 (caller-only groups stay on their attaching thread), ST-3 (group churn with kernels in flight). - state_exec_locks_test: LocksGroups LG-1 (with-lock sections against their solo runs), LG-2 (cross-group grants racing kills and timeouts, fork-join and continuous; a lock post racing the target's destruction; a grant during teardown), LG-6 and LG-7 (deterministic grant order and deadlock victim). - test_pycvc_exec_pool.py: RA-1 (a post ends run_all's batch wait: batch_wait_timeouts stays 0). On S2a.0 every case fails for the missing behaviour: pump_host or with_group throws "continuous mode is not built yet", and ExecPool has no stats() (LG-2's fork-join races pass). The cases' host loop turns a throw into a failure and detaches what it attached, so a failing case leaves nothing attached and the binary runs on.
S2a.6 of threaded execution's S2a (S2.md section 2; S2-Q11; td 4.9 "Kernel pools"; section 0
row 24).
- app::trySubmitKernel is where the exec async host now queues a threaded call's kernel. Until
the app's exec pool is built with workers, every kernel goes to the background pool through
trySubmitPooled, as before: the same workers, order and counts. Once it has workers, the pools
split for the app's life:
- an io call's kernel (async_options::io, set by the net and room calls) stays on the
background pool, now background_io, whose size and other tasks are unchanged;
compute_async's blocking jobs stay there too;
- every other kernel runs on background_cpu: max(1, cores - exec workers) persistent workers
of its own, all started with it. Its queue is ordered by priority, FIFO within one. If no
worker can be started, the kernel goes to the background pool.
- background_cpu follows the background pool's rules. wait_for_threads() and ~app interrupt its
running tasks and wait for them. ~app closes it after the async host's shutdown and joins its
workers with the background pool's. A task it drops unrun reports kPoolStopped.
- app::kernelPoolHere() says which pool the calling thread works for, and
backgroundCpuPoolSize() gives background_cpu's size (0 before the split).
- STATE_EXEC_EXCEPTIONS.md settled question 4 and 3.5: the pool is split from Stage 2 on (Q9).
Tests (KernelPools.*): at threads 0, an io call and a plain one both run on the background pool,
with no exec pool and with one that has no workers. With exec workers, a plain call runs on
background_cpu and an io call on background_io, and background_cpu's size is the cores minus the
workers (at least 1). An io call isn't queued behind a held plain kernel. wait() interrupts a
background_cpu kernel. A call made after background_cpu has stopped raises RuntimeError, and the
host is left with no call.
…ink)
S2a.7's evaluator half (S2.md section 2; S2-Q11; section 0 row 25). W adds the readings in
async_scheduler.cpp.
- evaluator_state::native_site is the call-site name of the native function the state's latest
step applied, or null if that step applied none (step() clears it first).
- step_apply passes the call's head symbol to apply_native (`+`, `f` in `(f x)`), which stores
it. That costs one pointer store per native call.
- A function a deep-data job calls at the evaluator's level (step_data: collections.map's,
where no symbol is at hand) is "native". A lock wait is "with-lock", and a native method
`super` calls is "super".
- It points at the symbol's own characters, with no allocation or copy, while something besides
the call's frame holds the form. A form only its frame holds (a macro's expansion, an eval'd
list) is freed when the frame pops, so its name is copied to native_site_copy. A step that
raised copies the name there before it unwinds. The name stays valid until the state's next
step.
- app::exec_scheduler() installs group 0's long-step sink. It logs "long step: <native> took
<ms> ms (group 0)" through the app at level 2, with interruption held off. It is off unless the
tree sets state_exec.long_step_ms.
Tests (NativeSite.*): a step names the native it applied, and only that step does. + and * are
natives too. The name is the call site's symbol. A function collections.map's job calls while
slicing is "native"; without slicing it is collections.map's own call; a DSL function's body names
its own call sites. A macro's expansion and an eval'd list keep the name. A raising native keeps
its name through the unwind, caught or not. LongStepSink.DISABLED_Group0LogsALongStepThroughTheApp
waits for W's monitor.
…tor's names, group 0's sink)
S2a.9's PL-1 (S2.md S2-Q15, td 8.3): tools/locks_model/state_word.py, an exhaustive model of the continuous pool's group state word (SCHEDULED, NOTIFIED, PUMPING, DETACHING) and the pool's queued, host_held and deferred under the ready-queue mutex, as S2a.0 froze them in the comment on group_pool_link. Every atomic operation is a step; posters (ingress and lock), workers, the timer, hosts (with_group on other threads) and the attaching thread (attach, host bodies, waiting bodies, take_failed, then the teardown or the detach) are explored breadth first, the workers up to symmetry. Like gdestroy it has no C++ port. It checks no lost wake (at idle points), no double queueing, no pump of a host-held group or by two workers, the token held by one thread, and no wake, read or record access after the detach. The frozen transitions hold for posters, workers, the timer and the teardown; the host side fails four ways, each with an amendment the model checks (--amend): host-wake (a with_group or host body that submits under the token leaves an idle group runnable and unscheduled: a lost wake), host-excl (two host-side token holders), host-detaching (a with_group racing a detach sets host_held after step 2) and nested-release (a detach inside the same thread's with_group). Five mutations (--mutation), among them a release by a plain store and a pop that pumps a host-held group, are each caught. --suite quick (the CI checks, about 13 s) and --suite deep (about 8 minutes, up to 5.3 million states) exit 0 when every check holds; test_state_word.py runs the quick suite and checks the explorer's symmetry reduction and traces. README.md describes the model, its findings with their shortest traces, the amended host transition, and the state counts.
S2a.2 of threaded execution's S2a (S2.md section 2; S2-Q2, S2-Q3, S2-Q4, S2-Q13, S2-Q15): the continuous pool's worker side, on S2a.0's frozen transitions. - attach: an attachment record per group (the notifier's ctx and link.attached), the attaching thread's record (found by thread id), room reserved on every list a wake pushes onto, the notifier installed outside the pool's mutex, and one wake so earlier posts are seen. Caller-pumped groups (host affinity, a single-mode lock manager, a pool with no workers or in deterministic mode) go onto their attaching thread's ready list. - wake(g): the fetch_or, then under the mutex the queue: a worker's wake of another group goes into its next slot (Go's runnext; a slot's old occupant to the queue), else the ready queue, ordered by virtual time, clamped at the scheduled transition to the queue's floor less one pump. It never allocates; it notifies one parked worker (P-cores first) outside the mutex. - The worker loop serves pump_all first, as before, then pops: due timers, its next slot (3 uses in a row at most: Tokio's valve), the ready queue, another worker's slot. Pop and pumping are one step; a group a host holds is left notified and deferred. The release reads only the pump's report and the word: work left queues it again, else the CAS to 0 and only then the deadline is filed. CVC_EXEC_FORCE_MOVE (pool_options::force_move) gives each pump another worker. - Idle workers wait on Stage 1's condition variable while no group is attached for them, else spin about 20 us and park on an eventcount (an epoch and a wakeup per worker); one of them waits for the timer heap's earliest deadline, precisely only for a sleeper's or a timed wait's. They landed here rather than in S2a.4 because the worker loop needs them. - detach (steps 1-4, without the host queue yet) and detail::detach_begin / detach_end. - CVC_EXEC_FUZZ (read when the pool is built) yields at the word's points, counted in pool_stats::fuzz_points (appended). - The long-step monitor's default (1 ms) at a pool with workers' first pump of a group. With nothing attached, pump_all and the Stage 1 paths are unchanged. The host side (pump_host, wait_for_work, with_group, take_failed, the host queue) is S2a.4's. Tests (ExecPoolContinuous, P's block of exec_pool_test.cpp): attach's refusals and notifier; groups run to their results on the workers over many pumps; force-move gives each pump another worker; a late group does not starve a busy one (the clamp); idle workers park and the fuzz points count. The multi-pump cases need the run loop's report (S2a.3).
PL-1's model (tools/locks_model/state_word.py) found four problems in S2a.0's host transition, each with a shortest trace in its README: - a lost wake: with_group, or a host body, that submits, kills or resumes under the token posts nothing, so its release now does wake's transition when no pop was deferred; - two host threads at once: host_held now names its thread, and a host also waits while another thread holds it; - a with_group racing a detach: a host that finds the group detaching, or no longer attached, sets nothing and takes the token as for an unattached group; - a detach inside with_group: the release leaves the pool's record alone; a teardown inside it aborts, as one inside the group's own pump. Detach's step 4 stores 0 in the word only after the notifier is cleared. exec_pool.h's attach and with_group follow. The model's --amend now defaults to the amended transitions, and its quick suite joins CTest (state_exec_state_word_model_test).
S2a.4 of threaded execution's S2a (S2.md section 2; S2-Q4, S2-Q5; td 4.9, 4.14): the continuous pool's host side, on S2a.0's frozen transitions. (The eventcount and the workers' timer heap came with S2a.2, which the worker loop needed.) - The host queue per attaching thread: a worker pumping an attached group queues its host_proxied bodies (run_on_host, run_on_host_waiting) and its deferred on_complete callbacks (defer_on_complete) there; the attaching thread pumping a caller-pumped group runs them inline. An entry takes the group's token by with_group's rule (host_held; a worker that pops the group meanwhile leaves it notified and deferred, queued again at the hold's end); while the group's worker is blocked on a waiting body, its entries run in order under that worker's token, taking nothing. A worker waiting over 10 ms counts in long_host_waits, logged once a minute a group. - pump_host runs the entries, then pumps the queued caller-pumped groups on the pool's budget (deterministic mode: a rotation in creation order, on steps only); wait_for_work services the queue while it waits for a group, an entry or a failure, until the earliest deadline of its caller-pumped groups (their own timer heap, so no worker wakes for them). - with_group waits for a pump in progress or another thread's hold (servicing this thread's queue), holds the group, and afterwards queues it again if a pop was deferred, or wakes it when wants_pump() says what fn did left it work. - Failures: the pumping thread kills the processes, the release lists the group on its attaching thread's failed list; take_failed finishes the detach (running its entries) and logs as pump_all. - detach services this thread's queue while it waits, then runs the group's entries holding the token; detail::detach_end drops them unrun (nothing leads from the group to its pool once the attachment is gone, so purge_host_calls could not find them after it); purge_host_calls drops an attached group's entries too; in_pool_callback covers an attaching thread running an entry. Tests (ExecPoolContinuous, P's block): groups run to their results at threads 0 (every pump on the attaching thread) and 2; a post wakes an idle group; a group posted during with_group is not pumped while held and is pumped after; on_complete and a host_proxied body run on the attaching thread (the body under the token); a failed group is taken once, detached; deterministic mode rotates in creation order; detach runs, and detach_begin/detach_end drop, the group's queued entries.
S2a.1 of threaded execution's S2a (S2.md S2-Q2; section 0 row 7). - detail::wakeup::notify() calls the installed notifier instead of signalling, under the notifier lock, in both the Windows and the condition-variable wakeup. With none installed it costs one acquire load and no lock; the lock re-checks it, so a notify racing set_notifier(nullptr) signals. set_notifier keeps S2a.0's behaviour: it returns once no call of the old notifier runs. - async_scheduler::notify_work() notifies whenever a notifier is installed, whatever idle_waiting_ says. post_message, post_async_completion and post_control still call it under the ingress mutex, so the notifier runs there; a lock post reaches it through the wakeup the port shares (lock_home and lock_manager unchanged). - wait_for_work asserts, just before it would block, that no notifier is installed; a probe whose deadline has passed returns before that. In a release build such a wait lasts to its deadline. - CVC_EXEC_FUZZ (S2-Q15), read as a scheduler is made with lock_home.h's parser, yields at each ingress post between the push and the wake (a private ingress_fuzz_, null when off). Tests (state_exec_async_test, WakeNotifier.*), each failing before: each post kind (message, completion, control, a lock post through the port) calls the notifier once with no wait in progress, and none after it is cleared; a notify with a notifier ends no wait, and signals again once it is cleared; set_notifier(nullptr) returns only after a blocked notifier call returned; fuzzed posts from four threads each call it once and each land.
S2a.3 of threaded execution's S2a (S2.md S2-Q4; section 0 rows 8 and 10). The run loop publishes at its end what it left (async_scheduler::run_report, always on), which exec_group::pump copies into pump_result (S2a.0), so a pool's release never reads the scheduler: - runnable: has_runnable(); best_runnable: process_table::best_runnable(); - next_deadline: the earliest of the earliest live timer (sleepers, timed receives, lock deadlines; process_table::next_timer, which drops stale entries as wait_for_work's look does, read only while a timer is live), next_call_charge(now) while calls are in flight, now + 1 ms while a process waits for the next frame, and the idle collection falling due; time_point::max() when none; - precise: the deadline is the timer heap's, as wait_for_work's rule is. The clock is read only for a beat (calls in flight or frame waiters); nothing allocates. heap.h gains cycle_collection_due_at, the due rule as a time: min() when the growth rule holds, the last collection + 1 s under the exit rule. Tests (state_exec_async_test, PumpReport.*, through an exec_group's pump()): a sleeper's and a timed receive's deadlines are precise; a frame waiter is a coarse now + 1 ms after each pump; a max_steps process with a call in flight gets the coarse 1 ms beat; a budget that ran out leaves the group runnable; best_runnable is -2 for priorities 3 and -2 under the priority policy and 0 under round robin; nothing pending gives max(), and an exit within a second of the last collection gives a coarse deadline a second after it. Each but the max() checks failed before.
… stub) The amended transitions abort a teardown of a group inside its own with_group or host body; the teardown (S2a.5) asks the pool whether the calling thread holds the group's host_held. A stub until S2a.4.
S2a.5 of threaded execution's S2a (S2.md S2-Q4; section 0 row 12; the amended transitions in exec_group.h). - ~exec_group follows S2-Q4's order for an attached group: (1)-(2) detail::detach_begin sets detaching and waits for a pump in progress and another thread's host_held, servicing this thread's host queue; (3) the token (free by then; the retry loop stays for an unattached group), the lock port's close, the teardown hook; (4) detail::detach_end takes the group off the pool's queues and timer heap, clears its notifier and drops the attachment; (5) the kills, the host's shutdown, purge_host_calls and the reaps. Both calls do nothing for a group not attached, and a group whose pump failed attached (detaching already) goes the same way before take_failed. - A teardown inside the group's own with_group or host body, on the thread holding its host_held (detail::host_held_here), aborts in every build, as one inside its own pump does. - Ariadne: refuse_if_held does not refuse an attached group (no pump_all holds one); its teardown or move waits in detach_begin instead. assert_outside_pump also fires inside a pump of the document's own group (pumping_here), which an attached group's continuous pump would be. Ariadne's groups stay fork-join (S2-Q6). Tests: ExecGroupTeardown.AnAttachedGroupLeavesItsPoolBeforeTheKills (still attached at the teardown hook, detached with no notifier in the kernel's cancel hook the kill runs, nothing attached after) and AriadneIsolatedDocs.AnAttachedGroupsTeardownIsNotRefused fail before. ExecGroupDeathTest.DestroyedInsideItsOwnWithGroupAborts skips until with_group is built for attached groups (S2a.4).
test_bw01_a_post_is_consumed_before_a_sleeper_wakes (S2a.8, S2-Q6): a batch where pooled Exec 0 sleeps 20 ms and pooled Exec 1 awaits a Python async function that a Python thread lets finish mid-batch. The completion, a post to group 1, ends the batch wait, so program 1 notes "posted" before program 0's sleep ends (an order). ExecPool.stats() shows the batch waited and no wait timed out with work posted. It fails here: ExecPool has no stats().
S2a.8 (S2-Q6; S2.md section 0 row 28). ExecPool.run_all stays fork-join; its 1 ms rotation over
one parked group's wait_for_work at a time is replaced by one batch wait.
- For the batch, each pooled group's scheduler has a notifier (set_wake_notifier) that sets the
batch flag and notifies one batch wakeup; an RAII scope clears every notifier on each way out,
after the last wait_idle, before run_batch returns.
- The flag is cleared (an exchange) before each pump_all. After the round the batch pumps again
at once for a runnable slot, a queued program on an idle slot, the flag, close(), or a passed
deadline; otherwise it waits on the batch wakeup until the earliest of the groups'
last_run_report().next_deadline (precise when that one is) and idle limits, at most 50 ms (a
backstop, as Exec.run's kMaxIdleWait). No scheduler's wait_for_work blocks any more.
- The flag, wakeup, close()'s request and the counters are a batch_control the pool owns, so
close() notifies a batch waiting between rounds.
- ExecPool.stats() returns {"batch_waits", "batch_wait_timeouts"}: the batch waits, and those that
ran out with work posted meanwhile whose wake never came (the flag, or a probe with a past
deadline at a group whose own deadline is over 1 ms off; a 1 ms grace for a wake in flight).
Exec.run is unchanged. test_bw01 and RA-1 pass; with the notifier left out both fail (the post
is consumed after the sleeper; RA-1 counts a timeout).
…ded host transition S2a.4, following the state word's host transition as amended from PL-1's model (9302360), and two fixes found under K's cases: - with_group, a host body and a deferred callback release the group with wake's transition when no pop was deferred (what ran may have submitted, killed or resumed, which posts nothing); a host waits while another thread holds the group (host_held names its thread); a group being detached is taken as an unattached one, at once on the thread finishing its detach (a failed group on its attaching thread) and after the detach elsewhere; if fn detached the group, its release leaves the pool's record alone and does not touch the group. detail::host_held_here (exec_pool.h's detail namespace) tells a teardown that its thread holds the group, for its abort. - Detach's step 4 clears the notifier before it drops the attachment and stores 0 in the word. - attach takes the scheduled transition itself and queues the group only after the notifier is installed and, when the group has a lock home, its port's mutex was taken once: a lock post that raced the install, read no notifier and signalled the bare wakeup has its pending flag visible to the first pump (W's review). - Fix: a worker firing a due timer at its pop took a parked worker for the group it then pumped itself, without notifying it: that worker stayed in an untimed wait out of the eventcount's reach, so ~exec_pool's join hung (CT-2's end). Only the groups fired beyond the first take one, and each taken is notified. - Fix: a requeue its releasing worker takes next no longer moves the epoch, so idle workers park beside a busy group instead of re-checking it every pump. Tests (P's block): a submit inside with_group is pumped, and host_held_here holds inside fn only; fn may detach the group; a failed group is read before take_failed with no hold; a worker firing a timer takes no parked worker (the pool joins; it hung before the fix).
…s.async, mt.groups.move) S2.md S2a.10 and section 6's S2a gates. - mt.groups gains pump (fork_join, the default and Stage 1's pump_all rounds; continuous: the groups attached for the point to t workers, none at t=1, driven by the caller's pump_host and wait_for_work, each group submitted, read and reaped under with_group once its run's on_complete has said it ended) and shape (even, the default; uneven, S2-Q6's evidence: group 0 runs the program at about 11 times its work, the others 11 times as many runs of it). Fork-join points run as before. Continuous points add the pool's Stage 2 counters (wakes, timer_wakes, requeues, parks, empty_wakes, moves, host_pumps) and idle_waits; their ceiling's threads sit on the workers' CPUs. - mt.groups.async: G groups each making `calls` async calls in turn (a 20 us spin, or a 1 ms io block), completion latency from the kernel's end to the process running on (extra.lat_p50_ns, lat_p99_ns, latency_ns), extra.calls_per_s; fork_join waits for a post on a batch notifier every group's scheduler calls, as ExecPool.run_all does. - mt.groups.move: the same groups attached in turn to two pools alike but for pool_options::force_move, alternating order: extra.ns_per_move over extra.moves (the moves force_move added). - Records with an app carry app_cpu_pool_size_after (background_cpu's size; the active and pending counts are the background pool's alone once the kernel pools split). - The tool: pump=fork_join and shape=even are implicit defaults; GATE_GUARDS judges mt.groups' speedup gates on even groups only (uneven is n/a) and fails mt.groups.move's points with no added move as vacuous. Tests for both, each failing on the old tool.
…wasm smoke's attached group S2.md S2a.11 and section 5. - SAN_REQUIRED_S2A, appended to every leg as S1A's and S1B's are: PL-2..PL-5, PL-9, PL-10, CT-1..CT-4, ST-3, LG-1, LG-2, LG-6, LG-7, RA-1, the wake notifier's and the pump report's cases, the kernel pools' and native names' cases, pycvc's batch wait, and mt.groups' continuous points; the pool's own cases go at its marked end as they merge. - SAN_BENCH's mt.groups runs both pump modes (one line: a scenario's log is named after it); Stage 1a's mt.groups lines name pump=fork_join, since the continuous points' lines begin with theirs. - The clang leg: state_exec_coordinator_test, and state_exec_stackless_evaluator_test's NativeSite cases alone (cxx_runs); its bench is a block. - locks-deep.yml: a job for the state-word model's deep suite (no C++ build; a ref without the model stops at once). - state_exec_wasm_smoke attaches a group to a pool at threads 0 and drives it with pump_host and wait_for_work until its program ends: every pump on its thread, none on a worker.
A scenario's log is named after it, so a second line for it would replace the first run's log and fail its required lines with no word of why (S2a.11: mt.groups' two pump modes share one line).
Off, on, on, off, each side's time, moves and pumps summed, so a drift across the rep or the cost of going first falls on both pools alike (one alternating pair a rep left that to the rep count's parity). mt.groups.async's kernel flag is named blocks, not sleep (POSIX's sleep()).
…in's mt.groups at its smoke sizes, t=1 (every group on the caller) and t=2 (on workers), both shapes, both pump modes, then compare --pair pump=fork_join:continuous --metric steps_total --threshold 0 --fail-on-change: attached groups, pumped whenever they have work in the pool's budget, take the steps of groups pumped by pump_all rounds (S2a's rule: step counts unchanged). It needs continuous mode built (S2a.2, S2a.4): on S2a.0's stubs its continuous points fail. Passed against P's branch (0996257's code) in a scratch merge: 12 pairs, equal.
S2a.7's scheduler half (S2.md S2-Q11; section 0 row 25), on M's evaluator_state::native_site. - The threshold: the tree's state_exec.long_step_ms when set, read through the settings cache by the slice settings' rules (a strict number, the default again once unset; 0 or less: off), else set_long_step_default's. refresh_slice now reads the tree when both slice settings are given too. - The readings: each step's end (execute_process_step's clock reading); first in the catch of a step that throws, before kill_process or fail_process; and at slice_steps above 1 at a run's clock readings (after steps 2, 4, 8, 16, then every 16th), where a window longer than the threshold counts once. - A long step or window is counted (long_steps()) and reported to the sink with its last step's native_site, "" when that step applied none, copied only then, at most once a minute per name per scheduler. A sink that throws is dropped. - Off, it costs a branch on a cached double at a step's start and end and at a run's readings. - exec_group's constructor gives a group of an app a sink that logs "long step: <native> took <ms> ms (group '<name>')" through the app at level 2, interruption held off, as group 0's does. - async_scheduler.h's Stage 2 private block gains long_step_seconds_, long_step_tree_, long_window_, long_step_reported_ and time_long_step. Tests (LongSteps.*, each failing before): a group's 5 ms native at a 1 ms default is counted and logged with its name and group; the tree's 5000 ms wins over the default, a non-number leaves it, unset restores the default, 0 turns it off; a step cut by its deadline (it throws) is counted and named; at slice_steps 256 the long window is named by its last native; two long steps of one native count twice and report once. LongStepSink.Group0LogsALongStepThroughTheApp is enabled.
…p; S2a.7 the long-step monitor)
…d moves that cost little S2a.4, three changes found under K's CT-3 and B's mt.groups.move: - Fix: a host waiting to hold a group that its worker kept re-pumping never found it free: the release queued it again and the same worker popped it in the same critical section, so CT-3's with_group waited minutes and its host bodies starved. A release that queues a group again now sets host_held for a host waiting to hold it (a with_group, else its attaching thread with host entries for it), on that host's behalf, as its own look would once pumping cleared; the pop that follows leaves it notified and deferred (the frozen pop row), and the hold's end queues it again. A detach takes back a hold handed over and not yet taken up. - A non-waiting host body takes the group's token even while the group's worker is blocked on a waiting body (the frozen host row); only the waiting body runs under that worker's token, so it may run before an earlier non-waiting body of its group. - Moves and wakes: a waker spares a parked worker while another spins (it sees the epoch), and a worker that pops with more queued wakes one more; under CVC_EXEC_FORCE_MOVE a worker finds the first group it did not pump last by popping at most four and pushing them back (a scan only past them), and a skip no longer wakes a second worker. Test (P's block): a with_group gets a group its worker keeps re-pumping, which is left notified by the pop under the hold and pumped after it (it timed out before the fix).
- APP_API.md: continuous mode for C++ hosts (attach, with_group, the pump_host/wait_for_work loop, take_failed, detach before exit, the refusals) with an example loop; the kernel pools once split. - STATE_EXEC_DEVELOPER_GUIDE.md: continuous mode's host rules (what runs where, the token, the host loop, detaching, the refusals and aborts), the long-step monitor, the kernel pools and async_options::io; where an attached group runs; which settings each scheduler reads. - bindings/pycvc/README.md: run_all's batch wait and ExecPool.stats() (Y's text). - THREAD_POOL.md, THREAD_POOL_API.md: once the kernel pools split, setThreadPoolSize and the counts cover background_io only (R2b S-m11).
B's requests (S2a.10, S2a.11): - STATE_EXEC_BENCH.md: mt.groups' pump and shape keys and t's meaning in each mode, its continuous extras; mt.groups.async and mt.groups.move with their metrics; the implicit defaults; GATE_GUARDS' applies and numeric vacuous bounds; app_cpu_pool_size_after; the gates CTest's Stage 2a step; Stage 1's scaling gate with --where pump=fork_join; the Stage 2a gates. - TESTING.md: CVC_EXEC_FUZZ's pool and ingress points; mt.groups in both modes in every leg; the clang leg's coordinator suite and NativeSite cases; SAN_REQUIRED_S2A; the state-word model's CTest entry and locks-deep lane.
pump_result repeats the last report while no notifier is installed; active_workers subtracts workers blocked on a host body; the monitor names a step with no native "(no native)"; the model's lane and CTest entry give its current sizes and times.
…tretched pump ExecPoolContinuous.ANewGroupDoesNotStarveABusyOne asserted 10 of 40 pumps each; a pump the OS stretched on a loaded box counts as virtual time, and once in 50 repeats left the late group 5. Without the clamp the late group takes all 40, so 4 each still tells the two apart.
…xt slot's wake, the hold handoff with give-back, deterministic frames)
P's twelve ExecPoolContinuous cases from the review round, W's report and monitor cases and M's kernel-pool case join every sanitizer leg's required lines. AWorkersPumpExceptionReachesTheAttachingThread runs in Release only and stays out.
test_bw01 assumed the Python opener posts before a 20 ms sleeper wakes, which a loaded box broke once. The sleeper is now a timed wait, (await g 20), on a Python async function whose kernel finishes only once the test has seen "posted"; the opener lets program 1's kernel finish only once stats() shows the batch waiting. So "posted" comes before "sleeper" whatever the load, and the test still shows what it did: a host post ends the batch wait (batch_wait_timeouts 0) and is consumed while the sleeper still sleeps. With the batch notifier left out it fails every time (each lost wake counted: batch_wait_timeouts 2). The 20 s only bounds a hang.
…ions) - exec_group::execute on an attached group from inside a pump of its pool (a worker, or a thread pumping another group) is refused with std::logic_error: its with_group could wait for a pump that waits for this one (two groups submitting to each other deadlocked). A group reaches another by message; S2b's router carries cross-group work. - The release row: the host waiting now is one not running an entry or pumping a group of its own; a worker's pump exception that does not fail the group leaves one rethrowing entry per group at a time on its attaching thread (a later one while it is pending is logged and dropped). - exec_pool.h and td 4.12: only a host waiting in wait_for_work is handed a busy group's hold in practice; with_group, detach and a pump_all join run only waiting bodies beside a busy group; a frame loop calls wait_for_work when pump_host returns false.
LG-2's second part (a lock post racing the target group's destruction) ran until 10^4 runs or a 60 s budget and then asserted it had reached runs / 20: a throughput floor on wall time (hard rule 7). Under a 24-way compile on this box it reached 92-171 runs and failed 6 of 15. Most of a run's time there went to the gap before the destruction, up to 400 yield()s, each of which a saturated box turns into a time slice. Now every run is run and only the races' outcomes are asserted (nothing held or queued once A's holder ends; all runs done). There is no budget and no floor: a run over 60 s fails as a hang (its waits keep their own ceilings), and the total time is printed. The gap is a busy spin of 0-200 us, and the run's waits poll every 0.5 ms instead of 2 ms.
…tic fixes From skeptic-fixes.md (P's items), each with a test that failed before: - K-1: with_group on the thread finishing the group's own detach takes the token at once (throwing while another thread holds it); take_token's wait only after a wait_round on the group (C-m5's raced detach). - K-2: with_attached refuses (std::logic_error, naming both groups) an execute into an attached group from inside a pump of its pool: a worker, a caller-pumped pump in pump_host (host_thread::pumping), or a pump_all's group pumped on its caller (callers now carry their call). - K-3: a failed group's report is a per-attachment flag, not a count. - K-4: running a host entry or pumping a group of its own, the attaching thread is not waiting: servicing drops to 0 there and handed holds go back (busy_scope). - K-6: with_attached reads the record under link.membership; finish_detach stores null and frees it under membership (membership before Q). - K-8: one rethrowing entry per group at a time; a later worker pump exception is logged through the group's app and dropped. - K-9: pump_all's debug assertion also reads the host record's in_callback. - K-10: the calling thread's idle record goes at the ends of pump_host and wait_for_work, after with_group's waits and after a pump_all join's entry. - K-13: a skipped wake (CVC_EXEC_FORCE_MOVE) is not an empty wake.
…rts its hold Skeptic K-7. ExecGroupDeathTest.DestroyedInsideItsOwnWaitingBodyAborts asserted host_held_here in its probe of a waiting body only to skip when it was false, written before P's C-M3: with the waiting-body clause gone from host_held_here it skipped rather than failed. It now asserts that host_held_here is true in the group's own waiting body. With the clause removed (an uncommitted experiment in exec_pool.cpp) it fails 2/2; at the head it passes, the death case included.
Skeptic K-12, C-m3's other half. detail::wakeup::set_notifier asserts (debug builds) that it either clears the notifier or none is installed: a second notifier would take the first owner's place (a pool's attach, a host batch's) silently, and the first owner's clear would leave the second with none. attach already refuses a scheduler with one; every installer installs once and clears. Test: WakeNotifierDeathTest.InstallingOverAnotherAsserts (installing after a clear is fine; over another, the assertion). Debug builds only; it skips in Release.
…e notifier at a time)
PL-2 posted up to 10^6 messages within a 15 s budget and then asserted that it had reached total / 20: a throughput floor on wall time (hard rule 7). It failed once at CVC_EXEC_SLICE_STEPS=256 on a heavily loaded box, with no lost wake. Now every post of a fixed count is made: 5*10^5 in Release, about 4 s on a quiet box (Debug and sanitizer sizes unchanged; CVC_EXEC_PL02_POSTS overrides). There is no overall budget or ceiling. Each post keeps its 10 s ceiling as the hang guard, and the lost-wake and parks checks stay; that every post was made is asserted, and the time is printed.
Seven ExecPoolContinuous cases from the skeptic fix round (K-1, C-m5, K-2 twice, K-3, K-4, K-10). TwoWorkerPumpExceptionsLeaveOneRethrow skips in debug builds and stays out, as AWorkersPumpExceptionReachesTheAttachingThread does.
A/B (S2.md section 6, S2a rows)The window ran 2026-11-22 04:47-06:02 on the Windows workstation:
The regression family. Its round 2 candidate run was retried because another agent's
Each binary's change from round 1 to round 2: base −0.9%, candidate +4.6%. So the overall +1.74% comes from the disturbed run. The clean round shows no cost on the default path, and round 2 cannot separate S2a from the disturbance. The recorded families ( The continuous gate. The ceiling (
It may be the OS or a straggler stall in continuous mode. This run can't tell. Uneven groups. Continuous beats fork-join by just over S2-Q6's 10% bar, so the continuous Still open. A re-run of the regression family (2 rounds) and a 25-rep repro of the continuous fib t=8 points are ready to run in the next quiet window. The other choice is to accept the inconclusive 3% gates as recorded, as Stage 0's were. Either way, this PR stays a draft until that decision. |
Brings in master through aa158cc, among it #1395 (the pool's short-changed rule) and #1418 (state_exec_groups_test gives the oracle's pumps no wall-clock budget). Conflicts: - exec_group.h, pump_result: both sides added fields. Kept master's `runnable` and S2a's next_deadline / deadline_precise / best_runnable / awaiting_frame, with one doc comment covering both. - exec_group.cpp, exec_group::pump: `runnable` is read from the scheduler (has_runnable(), O(1)), not from S2a's run report. The report is recomputed only while a wake notifier is installed, and a fork-join group has none, so left.runnable would be stale there, and #1395's short-changed rule reads pump_result::runnable in fork-join pump_entry. The other four fields still come from the report. - exec_pool.h, pool_stats: master's short_changed goes after effective_threads, before S2a's continuous-mode counters. - docs/STATE_EXEC_THREADED.md: the pump_result and pool_stats sketches list both sides' fields. - ci.yml: both sides kept. The clang leg's cxx_tests lists state_exec_coordinator_test and state_exec_stackless_evaluator_test; the env keeps SAN_REQUIRED_S2A and SAN_REQUIRED_NET, and SAN_REQUIRED names both. exec_pool.cpp merged without conflict: #1395's half_span, pumped::short_changed, the pump_entry rule and finish_group's skipped stamp sit beside S2a's give_long_step_default.
…s env first; clang-format Fixes the three failures CI finds on every leg of #1404: - ST03 timed out on 4-core runners. The exec pool there has 3 workers, so S2a.6 gives background_cpu max(1, 4 - 3) = 1 thread. ST03 parks 8 kernels at once, and they block until cancelled, so only one started and the warm-up batch never finished. A kernel that waits on something outside the program is an io call (async_options::io), and io calls run on background_io. The case now registers its kernel that way and sizes the app's background pool to the batch plus two. With 21 workers locally (a 1-thread background_cpu, as on the runners), the case failed before this change and passes after it. - LeakSanitizer reported the K-1 case. Its program binds a generator, which closes a cycle through the program's environment. The group's registry frees that cycle at the group's end only if nothing outside the registry still holds it (heap.h), and the case still held `ea.env` and `env` when it destroyed the groups. The case now lets go of both first, and it checks with a weak_ptr that the environment is gone, so the leak shows on every platform, not only under ASan. - clang-format 18 realigns the trailing comments of the K-round fields in exec_pool.{h,cpp} (git clang-format against the merge base).
package-linux / libcvc-debug failed both, three tries each, on a runner about three times slower than the run before on the same code (GR01 242 s against 77 s): - S-M3 required the busy group's 20000-count to finish within 10 s while the host serviced nothing. A pump is capped at pump_seconds (2 ms) as well as pump_steps, so on that runner a pump ran about 100 steps; the workers pumped the group 2520 times, and it did not finish. The group was slow, not frozen. The case now waits until the workers have pumped it 100 times (a frozen group stops at its first pump, which queued the callback), or it finished, with 30 s only as a hang guard, and counts to 5000. - K-4's property is the 20 pumps of the busy group during the host's native; the rest of its 200000-count was run out after, under drive's 60 s guard, which took 25.8 s on the debug leg before and over 60 s on this one. The count is now 20000, still thousands of pumps against the 23 the native waits for.
Threaded execution's S2a, the continuous pool, as planned in transfix/workstreams'
state-exec-perf/threaded-impl/S2.md(section 2, S2a.0-S2a.12; decisions S2-Q1..S2-Q17, approved 2026-11-12). Draft until the A/B (section 6) is run.What it builds
detail::wakeup::set_notifier; while one is installed every post (a message, a completion, a control, a lock post through the port) calls it instead of signalling, under the poster's lock.lock_home.*andlock_manager.*are unchanged.exec_pool::attach; a group's state word (scheduled, notified, pumping, detaching) with the pool's queued, host_held and deferred beside it; wake(g); workers pop by virtual time with S2-Q13's clamp; thenextslot and its valve;force_movein continuous mode; P-core preference;CVC_EXEC_FUZZpoints. The transitions are written inexec_group.h(group_pool_link) and checked by an exhaustive Python model (PL-1,tools/locks_model/state_word.py), which found real bugs in the first text; they are fixed in the text and the code.pump_result's runnable, next deadline (timers, call charges, the collection, frame waiters), precision,best_runnableand frame waiters, computed only while a notifier is installed, so a scheduler with none runs master's loop.pump_host,wait_for_work,with_group,detach,take_failed, the hold handoff with its give-back, deterministic mode's rotation.background_cpu(cores minus the exec workers, at least 1) and the existing pool asbackground_io(picked byasync_options::io), only once the exec pool has workers.state_exec.long_step_mswins), named by the call-site native (evaluator_state::native_site), logged once per native per minute.ExecPool.run_allstays fork-join and waits once per round on a batch notifier;ExecPool.stats().mt.groups pump=fork_join|continuousandshape=even|uneven,mt.groups.async,mt.groups.move;SAN_REQUIRED_S2Ain every sanitizer leg, the state-word model in CTest and alocks-deep.ymllane, the wasm smoke attaching a group at threads 0.STATE_EXEC_THREADED.md(status, 4.4, 4.7, 4.9, 4.12-4.14, 4.17, 5, 6.3, 7, 8.3, 9.2),APP_API.md,STATE_EXEC_DEVELOPER_GUIDE.md, pycvc's README,THREAD_POOL*.md,STATE_EXEC_BENCH.md,TESTING.md,STATE_EXEC_EXCEPTIONS.md.With nothing attached, no notifier installed and no workers, behaviour and step counts are master's (S2.md section 1's exit for S2a).
Reviews
pump_host), refusals inside a group's own pump or waiting body,executeon an attached group underwith_group.with_groupon the detaching thread waited for the group's pump, andexecutefrom inside one group's pump into another attached group could deadlock two groups submitting to each other. Both are fixed: the detaching thread takes the token at once, andexecuteinto an attached group from inside a pump of its pool is refused withstd::logic_error(a group reaches another by message; S2b's router carries cross-group work). The minors (a stale failed count, a host counted as waiting during its own pumps, an unguarded read inwith_attached, the worker-exception entry coalesced, a host record left behind, an empty-wake count underCVC_EXEC_FORCE_MOVE) and two throughput floors on wall time in the lock and pool tests are fixed too.exec_group.hare what PL-1's model checks (quick suite in CTest, 41 deep checks inlocks-deep.yml).Status
CVC_EXEC_SLICE_STEPS=256(identical counts): exec_pool 86, groups 33, async 143, intrinsics 181, async_calls 83, priority 40, scheduler 200, exceptions 26, data_steps 54, hazards 12, integration 104, stackless 89, app 123, ariadne_host 51, ariadne 342, locks 221; CTest: the bench smoke and tool test, the model,pycvc_exec*andpycvc_state_exec*, both slice256 runs.CVC_EXEC_FORCE_MOVE=1only three Stage 1 cases fail, as they do before S2a (they assertpump_all's helper wakes, which the knob changes).Groups.GR01andGroups.DT02can fail at slice 256 on a loaded machine before S2a too: their pumps get a time budget (a 1 h deadline) and Stage S's 1 ms run cut then reorders a group's processes; the test fix is state_exec_groups_test: give the oracle's pumps no wall-clock budget #1418, merged on master.of_ceilinggate came out inconclusive on noise, and no point was worse beyond the noise. In the one fully quiet round of the regression family, the candidate is 0.5% faster than base as a geomean. A re-run in a quiet window, or accepting those gates as recorded, is Joe's call. Not to be merged before then.