Skip to content

feat: add percpu#42

Open
AsakuraMizu wants to merge 4 commits intomainfrom
pr/percpu
Open

feat: add percpu#42
AsakuraMizu wants to merge 4 commits intomainfrom
pr/percpu

Conversation

@AsakuraMizu
Copy link
Copy Markdown
Contributor

Move part of axhal::percpu from ArceOS into axplat.

Useful for PLIC.

axcpu::init::init_percpu(x86_64) will be removed later.

Co-authored-by: lxh <lxh050013@outlook.com>
Copy link
Copy Markdown
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 introduces a new axplat::percpu module to provide common CPU-local (per-CPU) helpers inside axplat, and updates example kernels to use the new initialization and access APIs (removing the x86_64-specific axcpu::init::init_percpu call in examples).

Changes:

  • Add axplat::percpu with per-CPU CPU_ID/IS_BSP storage plus init_primary/init_secondary.
  • Update hello-kernel, irq-kernel, and smp-kernel examples to initialize per-CPU state via axplat::percpu and read CPU ID via axplat::percpu::this_cpu_id().
  • Adjust hello-kernel linker script to include linkme_* sections and drop the direct axcpu dependency for x86_64.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
platforms/axplat-riscv64-qemu-virt/src/irq.rs Minor import formatting change.
examples/smp-kernel/src/irq.rs Switch timer IRQ log to use axplat::percpu::this_cpu_id().
examples/smp-kernel/src/init.rs Replace local per-CPU CPU_ID plumbing with axplat::percpu::init_primary/init_secondary.
examples/irq-kernel/src/main.rs Use axplat::percpu::init_primary instead of x86_64-only axcpu percpu init.
examples/hello-kernel/src/main.rs Use axplat::percpu::init_primary unconditionally.
examples/hello-kernel/linker.lds.S Add linkme_* sections (IRQ + PAGE_FAULT) inserted after .data.
examples/hello-kernel/Cargo.toml Remove x86_64-only axcpu dependency.
axplat/src/percpu.rs New per-CPU API surface (CPU ID + BSP flag + init helpers).
axplat/src/lib.rs Export the new percpu module.
axplat/Cargo.toml Add percpu crate dependency.
Cargo.lock Lockfile updates for new dependency graph.

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

Comment thread examples/hello-kernel/linker.lds.S Outdated
Comment thread axplat/src/percpu.rs
Comment thread axplat/src/percpu.rs Outdated
}
}

SECTIONS {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These sections are unnecessary for hello-kernel.

Copy link
Copy Markdown
Contributor Author

@AsakuraMizu AsakuraMizu Feb 12, 2026

Choose a reason for hiding this comment

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

Removing it will cause builds to fail on aarch64 and riscv64, just like in https://github.com/arceos-org/axplat_crates/actions/runs/21898792110?pr=42. I don't actually know why.

Comment thread axplat/src/lib.rs
#[cfg(feature = "irq")]
pub mod irq;
pub mod mem;
pub mod percpu;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add a feature for percpu? Introducing percpu requires modifying the linker script, which some kernels may not want.

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.

3 participants