Skip to content

Commit

Permalink
axhal: refactor codes related to physical memory regions
Browse files Browse the repository at this point in the history
  • Loading branch information
equation314 committed Aug 8, 2023
1 parent f50b696 commit 1e74d04
Show file tree
Hide file tree
Showing 45 changed files with 198 additions and 290 deletions.
2 changes: 1 addition & 1 deletion apps/c/helloworld/expect_info.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/c/helloworld/expect_info_smp4.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CPU 0 started
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/c/httpclient/expect_info.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/c/memtest/expect_trace.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/c/pthread/basic/expect_info_smp4_fifo.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CPU 0 started
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/c/pthread/parallel/expect_info_smp4_fifo.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CPU 0 started
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
4 changes: 2 additions & 2 deletions apps/c/pthread/parallel/expect_info_smp4_rr.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CPU 0 started
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down Expand Up @@ -58,4 +58,4 @@ part 14 finished
part 15 finished
actual sum = 61783189038
(C)Pthread parallel run OK!
Shutting down...
Shutting down...
4 changes: 2 additions & 2 deletions apps/c/pthread/pipe/expect_info_smp4_fifo.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CPU 0 started
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand All @@ -27,4 +27,4 @@ Child thread send message(5)
Main thread recieve (4): I am child(4)!
Main thread recieve (5): I am child(5)!
(C)Pipe tests run OK
Shutting down...
Shutting down...
2 changes: 1 addition & 1 deletion apps/c/pthread/sleep/expect_info_smp4_fifo.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CPU 0 started
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/c/sqlite3/expect_info.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/c/sqlite3/expect_info_again.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/c/sqlite3/expect_info_ramdisk.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/exception/expect_debug_aarch64.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/exception/expect_debug_riscv64.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/exception/expect_debug_x86_64.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/helloworld/expect_info.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/helloworld/expect_info_smp4.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CPU 0 started
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/memtest/expect_trace.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/net/httpclient/expect_info.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/net/httpclient/expect_info_dns.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/task/parallel/expect_info_smp1_fifo.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/task/parallel/expect_info_smp4_cfs.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CPU 0 started
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/task/parallel/expect_info_smp4_rr.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CPU 0 started
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/task/priority/expect_info_smp1_cfs.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/task/priority/expect_info_smp1_fifo.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/task/priority/expect_info_smp1_rr.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/task/priority/expect_info_smp4_cfs.out
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Secondary CPU [0-9]\+ init OK.
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/task/sleep/expect_info_smp4_fifo.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CPU 0 started
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/task/sleep/expect_info_smp4_rr.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CPU 0 started
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/task/yield/expect_debug_smp1_fifo.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Primary CPU 0 started,
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/task/yield/expect_info_smp4_fifo.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CPU 0 started
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
2 changes: 1 addition & 1 deletion apps/task/yield/expect_info_smp4_rr.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CPU 0 started
Found physcial memory regions:
.text (READ | EXECUTE | RESERVED)
.rodata (READ | RESERVED)
.data (READ | WRITE | RESERVED)
.data .tdata .tbss .percpu (READ | WRITE | RESERVED)
.percpu (READ | WRITE | RESERVED)
boot stack (READ | WRITE | RESERVED)
.bss (READ | WRITE | RESERVED)
Expand Down
12 changes: 6 additions & 6 deletions crates/percpu/src/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ const fn align_up(val: usize) -> usize {
#[cfg(not(target_os = "none"))]
static PERCPU_AREA_BASE: spin::once::Once<usize> = spin::once::Once::new();

/// Returns the per-CPU data area size for each CPUs.
/// Returns the per-CPU data area size for one CPU.
#[doc(cfg(not(feature = "sp-naive")))]
pub fn percpu_area_size() -> usize {
extern "C" {
fn __percpu_offset_start();
fn __percpu_offset_end();
fn _percpu_load_start();
fn _percpu_load_end();
}
use percpu_macros::percpu_symbol_offset;
percpu_symbol_offset!(__percpu_offset_end) - percpu_symbol_offset!(__percpu_offset_start)
percpu_symbol_offset!(_percpu_load_end) - percpu_symbol_offset!(_percpu_load_start)
}

/// Returns the base address of the per-CPU data area on the given CPU.
Expand All @@ -25,9 +25,9 @@ pub fn percpu_area_base(cpu_id: usize) -> usize {
cfg_if::cfg_if! {
if #[cfg(target_os = "none")] {
extern "C" {
fn percpu_start();
fn _percpu_start();
}
let base = percpu_start as usize;
let base = _percpu_start as usize;
} else {
let base = *PERCPU_AREA_BASE.get().unwrap();
}
Expand Down
19 changes: 10 additions & 9 deletions crates/percpu/test_percpu.x
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ CPU_NUM = 4;

SECTIONS
{
percpu_start = .;
.percpu 0x0 (NOLOAD) : AT(percpu_start) ALIGN(4K) {
__percpu_offset_start = .;
. = ALIGN(4K);
_percpu_start = .;
.percpu 0x0 (NOLOAD) : AT(_percpu_start) {
_percpu_load_start = .;
*(.percpu .percpu.*)
__percpu_offset_end = .;
. = ALIGN(4K);
__percpu_size_aligned = .;
_percpu_load_end = .;
. = ALIGN(64);
_percpu_size_aligned = .;

. = __percpu_offset_start + __percpu_size_aligned * CPU_NUM;
. = _percpu_load_start + _percpu_size_aligned * CPU_NUM;
}
. = percpu_start + SIZEOF(.percpu);
percpu_end = .;
. = _percpu_start + SIZEOF(.percpu);
_percpu_end = .;
}
INSERT BEFORE .bss;
Loading

0 comments on commit 1e74d04

Please sign in to comment.