Skip to content

feat(rcu): add persistent CPU context tracking - #2218

Merged
fslongjin merged 2 commits into
DragonOS-Community:masterfrom
fslongjin:codex/issue-2210-rcu-context-tracking
Aug 29, 2026
Merged

feat(rcu): add persistent CPU context tracking#2218
fslongjin merged 2 commits into
DragonOS-Community:masterfrom
fslongjin:codex/issue-2210-rcu-context-tracking

Conversation

@fslongjin

Copy link
Copy Markdown
Member

Summary

  • add a persistent per-CPU RCU context model for kernel, user, idle, IRQ, and NMI states
  • let grace periods prove progress from either the current extended quiescent state or a quiescent-state generation change
  • integrate paired context boundaries into x86_64 and RISC-V entry, interrupt, idle, and user-return paths
  • add a dedicated RCU architecture chapter covering the stable design principles and subsystem boundaries

Design

The context tracker owns only per-CPU state transitions and quiescent-state generations. The grace-period state owns participant snapshots and the waiting mask, while the coordinator is the only layer that combines online CPU state, context snapshots, and callback progress. Architecture code only reports real entry and exit boundaries and does not maintain a second copy of RCU state.

The common transition path remains per-CPU and allocation-free. A per-CPU report hint prevents CPUs already credited for the active grace period from repeatedly taking the global slow path. The grace-period waiting mask remains the correctness source of truth.

User and idle contexts are persistent extended quiescent states. IRQ and NMI nesting temporarily restore RCU watching and only the outermost exit may restore the interrupted base context. Typed, single-use tokens make idle and IRQ entry and exit pairing explicit.

Correctness

Grace-period start and context transitions use an ordered two-way handshake. A CPU that enters an extended quiescent state before the snapshot is observed directly; a CPU that transitions after being recorded advances its generation and reports progress. A post-snapshot recheck closes the overlap window.

The x86_64 exception entry keeps the original error code in the completed trap frame across the Rust entry helper and reconstructs the handler ABI afterwards, preserving volatile-register semantics. User-accessible overflow and bounds gates use interrupt-gate entry so the context helper cannot be interrupted before the kernel state is established.

Validation

  • make fmt, including kernel Clippy
  • make kernel, including kallsyms generation and final x86_64 link
  • RISC-V Rust target compilation and kernel ELF link
  • fresh two-vCPU x86_64 QEMU boot to userspace
  • RCU dunitest executed twice consecutively, with 2/2 tests passing on both runs
  • userspace sleep and wakeup smoke test
  • multi-role adversarial review covering concurrency, correctness, architecture, performance, safety, maintainability, and over-design

Closes #2210

Introduce a cacheline-aligned per-CPU context state machine for kernel, user, idle, IRQ, and NMI contexts. Track quiescent-state generations so grace periods can exclude CPUs already in extended quiescent states and credit CPUs that pass through one after a grace period starts.

Wire the context boundaries into x86_64 and RISC-V entry, interrupt, idle, and user-return paths. Keep architecture code limited to paired transition hooks, preserve nested interrupt semantics with typed tokens, and retain the grace-period waiting mask as the source of truth.

Add deterministic transition and grace-period selftests, debug-only misuse diagnostics, and a dedicated RCU architecture document covering the stable context, grace-period, callback, ordering, and integration principles.

Validated with make fmt, make kernel, a RISC-V kernel link, and two consecutive 2/2 RCU dunitest passes in a two-vCPU x86_64 QEMU guest.

Closes DragonOS-Community#2210

Signed-off-by: longjin <longjin@dragonos.org>
@github-actions github-actions Bot added the enhancement New feature or request label Aug 29, 2026
@fslongjin

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 29, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-29T07:28:04.611912Z 75d2fa6 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Add the English RCU chapter and architecture guide alongside the Chinese source documentation. Preserve the same subsystem structure, context model, grace-period proofs, callback lifecycle, integration principles, and design boundaries in both language trees.

Link the new chapter from the English kernel documentation index and keep all diagrams and section ordering aligned with the source document.

Signed-off-by: longjin <longjin@dragonos.org>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 75d2fa6d9c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@fslongjin
fslongjin merged commit 1102f6c into DragonOS-Community:master Aug 29, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(rcu): add persistent architecture-neutral context tracking

1 participant