Skip to content

refactor: split the green scheduler into modules and bring its comments up to date - #1236

Merged
kacy merged 11 commits into
mainfrom
refactor/green-modules
Oct 29, 2026
Merged

kacy merged 11 commits into
mainfrom
refactor/green-modules

Conversation

@kacy

@kacy kacy commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Stacked on #1235. No behavior change.

The green scheduler is split into modules by concern. concurrency/green.rs was one 3,200-line file. It is now concurrency/green/:

module what it holds
mod.rs design overview, the scheduler, thread identity, spawn/await/detach/is_done
task.rs handles, the scheduling word, SyncBlock, join, the arena, task ids
queues.rs PinnedQueue and StealQueue
wake.rs park, wake, the migration claim, enqueueing
worker.rs Worker and its cache, the worker loop, finding and stealing work, parking
run.rs resuming a task and recording its completion
preempt.rs safe-points and the monitor thread
stack.rs the coroutine stack pool
stats.rs PITH_GREEN_STATS counters
probe.rs the cross-thread resume probe
tests.rs unit tests

The code moved as is. Items used across modules are now pub(super), and mod.rs re-exports what the rest of the runtime calls, so outside paths (green::wake, green::encode_probe, green::PITH_PREEMPT_REQUESTED) are unchanged.

Comments describe the current design. The module doc was a phase-by-phase history (P1a, P2, P2b, P2c) with a synchronization section that still described the slab and the Arc join. It is now a short overview: what blocks and how, which module owns what, the placement rules and the lock order. Comments that referred to the retired slab or slab lock, or narrated earlier designs, now state the current behavior. The pith_green_maybe_yield doc said it sets wake_pending; it sets preempt_pending.

Struct counts. In runtime_core.rs, the struct retain, release, weak retain and weak release paths repeated the "local count or atomic count" step inline with fully qualified std::sync::atomic::Ordering paths. They now call two #[inline(always)] helpers, count_up and count_down. The atomics import moved from the middle of the file to the top.

Lock-order notes. channel.rs, semaphore.rs, waitgroup.rs and docs/concurrency.md said wake takes the slab lock. It takes only the scheduling word and one run-queue lock.

Green unit tests, the cross-thread resume test and the TLS-barrier check pass. The full local gates run on the combined branch.

@kacy
kacy changed the base branch from perf/spawn-path to main October 29, 2026 01:06
# Conflicts:
#	cranelift/runtime/src/concurrency/green.rs
@kacy
kacy merged commit 4b6fbde into main Oct 29, 2026
4 checks passed
@kacy
kacy deleted the refactor/green-modules branch October 29, 2026 02:17
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