Skip to content

Conversation

@li041
Copy link
Contributor

@li041 li041 commented Jan 7, 2026

  • This change has not been fully tested yet. Currently it has only been verified on qemu-gicv3, qemu-aia, and rk3588.
  • I would appreciate it if other developers could help test this on additional platforms.
  • The main purpose of this PR is to introduce the percpu crate to better abstract per-CPU variables, instead of relying on global Vec.
  • Feedback on both correctness and design is very welcome.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the hypervisor to use the external percpu crate for managing per-CPU variables, replacing the previous approach that relied on global Vec collections. The main changes include renaming the percpu module to cpu_data, introducing per-CPU event queues, and adding linker script sections to support the percpu infrastructure.

  • Introduces the external percpu crate (v0.2) to abstract per-CPU variables
  • Refactors event management from a global Vec-based EventManager to per-CPU VecDeque instances
  • Adds .percpu sections to all platform linker scripts with proper sizing

Reviewed changes

Copilot reviewed 52 out of 54 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
src/cpu_data.rs New module containing PerCpu struct and related functions (renamed from percpu module)
src/event.rs Refactored to use percpu-based event queues instead of global EventManager with Vec
src/main.rs Added percpu initialization calls; removed event::init() call
src/zone.rs, src/pci/pci.rs, src/memory/mmio.rs, src/logging.rs, src/hypercall/mod.rs Updated imports from crate::percpu to crate::cpu_data
src/device/irqchip/**/*.rs Updated imports from crate::percpu to crate::cpu_data across all irqchip implementations
src/arch/**/*.rs Updated imports from crate::percpu to crate::cpu_data across all architectures
platform/**/linker.ld Added .percpu section definitions with CPU_NUM constant for sizing percpu areas
Cargo.toml Added percpu crate dependency with arm-el2 feature
Cargo.lock Added percpu and percpu_macros dependencies

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

cfg-if = "1.0"
bitvec = { version="1.0.1", default-features = false, features = ["atomic", "alloc"] }
heapless = { version = "0.8.0 "}
percpu = { package = "percpu", version="0.2", features=["arm-el2"]}
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The percpu dependency is configured with the "arm-el2" feature unconditionally in the general dependencies section. This feature is specific to AArch64's Exception Level 2 (hypervisor mode) and should not be enabled for other architectures like riscv64, loongarch64, or x86_64. Consider either making this a target-specific dependency under [target.'cfg(target_arch = "aarch64")'.dependencies], or using cfg-based features to conditionally enable the appropriate percpu features for each architecture.

Copilot uses AI. Check for mistakes.
@ForeverYolo
Copy link
Contributor

Can you explain why we need to do this?

@li041
Copy link
Contributor Author

li041 commented Jan 8, 2026

Can you explain why we need to do this?

less code, unified per-CPU abstraction, possible performance improvement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants