Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix align up percpu #149

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/percpu/src/imp.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fn align_up(val: usize) -> usize {
const PAGE_SIZE: usize = 0x1000;
(val + PAGE_SIZE - 1) & !(PAGE_SIZE - 1)
const fn align_up_64(val: usize) -> usize {
const SIZE_64BIT: usize = 0x40;
(val + SIZE_64BIT - 1) & !(SIZE_64BIT - 1)
}

#[cfg(not(target_os = "none"))]
Expand Down Expand Up @@ -32,7 +32,7 @@ pub fn percpu_area_base(cpu_id: usize) -> usize {
let base = *PERCPU_AREA_BASE.get().unwrap();
}
}
base + cpu_id * align_up(percpu_area_size())
base + cpu_id * align_up_64(percpu_area_size())
}

/// Initialize the per-CPU data area for `max_cpu_num` CPUs.
Expand All @@ -42,7 +42,7 @@ pub fn init(max_cpu_num: usize) {
#[cfg(target_os = "linux")]
{
// we not load the percpu section in ELF, allocate them here.
let total_size = align_up(size) * max_cpu_num;
let total_size = align_up_64(size) * max_cpu_num;
let layout = std::alloc::Layout::from_size_align(total_size, 0x1000).unwrap();
PERCPU_AREA_BASE.call_once(|| unsafe { std::alloc::alloc(layout) as usize });
}
Expand Down
Loading