-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04bd3ff
commit efa4ae9
Showing
9 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "arceos-tls" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["Yuekai Jia <[email protected]>"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
axstd = { path = "../../../ulib/axstd", features = ["tls", "alloc", "multitask"], optional = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
smp = 1 | ||
build_mode = release | ||
log_level = info | ||
|
||
Primary CPU 0 started, | ||
Found physcial memory regions: | ||
.text (READ | EXECUTE | RESERVED) | ||
.rodata (READ | RESERVED) | ||
.data .tdata .tbss .percpu (READ | WRITE | RESERVED) | ||
boot stack (READ | WRITE | RESERVED) | ||
.bss (READ | WRITE | RESERVED) | ||
free memory (READ | WRITE | FREE) | ||
Initialize global memory allocator... | ||
Initialize platform devices... | ||
Initialize scheduling... | ||
use FIFO scheduler. | ||
Primary CPU 0 init OK. | ||
Running TLS tests... | ||
main: true 0xaa 0xcafe 0xdeadbeed 0xa2ce05a2ce05 Hello, world! | ||
1: false 0xab 0xcaff 0xdeadbeee 0xa2ce05a2ce06 Hello1 world! | ||
2: true 0xac 0xcb00 0xdeadbeef 0xa2ce05a2ce07 Hello2 world! | ||
3: false 0xad 0xcb01 0xdeadbef0 0xa2ce05a2ce08 Hello3 world! | ||
4: true 0xae 0xcb02 0xdeadbef1 0xa2ce05a2ce09 Hello4 world! | ||
5: false 0xaf 0xcb03 0xdeadbef2 0xa2ce05a2ce0a Hello5 world! | ||
6: true 0xb0 0xcb04 0xdeadbef3 0xa2ce05a2ce0b Hello6 world! | ||
7: false 0xb1 0xcb05 0xdeadbef4 0xa2ce05a2ce0c Hello7 world! | ||
8: true 0xb2 0xcb06 0xdeadbef5 0xa2ce05a2ce0d Hello8 world! | ||
9: false 0xb3 0xcb07 0xdeadbef6 0xa2ce05a2ce0e Hello9 world! | ||
10: true 0xb4 0xcb08 0xdeadbef7 0xa2ce05a2ce0f Hello: world! | ||
TLS tests run OK! | ||
Shutting down... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
smp = 4 | ||
build_mode = release | ||
log_level = info | ||
|
||
Primary CPU 0 started, | ||
Found physcial memory regions: | ||
.text (READ | EXECUTE | RESERVED) | ||
.rodata (READ | RESERVED) | ||
.data .tdata .tbss .percpu (READ | WRITE | RESERVED) | ||
boot stack (READ | WRITE | RESERVED) | ||
.bss (READ | WRITE | RESERVED) | ||
free memory (READ | WRITE | FREE) | ||
Initialize global memory allocator... | ||
Initialize platform devices... | ||
Initialize scheduling... | ||
use Round-robin scheduler. | ||
Initialize interrupt handlers... | ||
CPU 0 init OK | ||
CPU 1 started | ||
CPU 2 started | ||
CPU 3 started | ||
CPU 1 init OK | ||
CPU 2 init OK | ||
CPU 3 init OK | ||
Running TLS tests... | ||
main: true 0xaa 0xcafe 0xdeadbeed 0xa2ce05a2ce05 Hello, world! | ||
1: false 0xab 0xcaff 0xdeadbeee 0xa2ce05a2ce06 Hello1 world! | ||
2: true 0xac 0xcb00 0xdeadbeef 0xa2ce05a2ce07 Hello2 world! | ||
3: false 0xad 0xcb01 0xdeadbef0 0xa2ce05a2ce08 Hello3 world! | ||
4: true 0xae 0xcb02 0xdeadbef1 0xa2ce05a2ce09 Hello4 world! | ||
5: false 0xaf 0xcb03 0xdeadbef2 0xa2ce05a2ce0a Hello5 world! | ||
6: true 0xb0 0xcb04 0xdeadbef3 0xa2ce05a2ce0b Hello6 world! | ||
7: false 0xb1 0xcb05 0xdeadbef4 0xa2ce05a2ce0c Hello7 world! | ||
8: true 0xb2 0xcb06 0xdeadbef5 0xa2ce05a2ce0d Hello8 world! | ||
9: false 0xb3 0xcb07 0xdeadbef6 0xa2ce05a2ce0e Hello9 world! | ||
10: true 0xb4 0xcb08 0xdeadbef7 0xa2ce05a2ce0f Hello: world! | ||
TLS tests run OK! | ||
Shutting down... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#![cfg_attr(feature = "axstd", no_std)] | ||
#![cfg_attr(feature = "axstd", no_main)] | ||
#![feature(thread_local)] | ||
#![allow(unused_unsafe)] | ||
|
||
#[macro_use] | ||
#[cfg(feature = "axstd")] | ||
extern crate axstd as std; | ||
|
||
use std::{thread, vec::Vec}; | ||
|
||
#[thread_local] | ||
static mut BOOL: bool = true; | ||
|
||
#[thread_local] | ||
static mut U8: u8 = 0xAA; | ||
|
||
#[thread_local] | ||
static mut U16: u16 = 0xcafe; | ||
|
||
#[thread_local] | ||
static mut U32: u32 = 0xdeadbeed; | ||
|
||
#[thread_local] | ||
static mut U64: u64 = 0xa2ce05_a2ce05; | ||
|
||
#[thread_local] | ||
static mut STR: [u8; 13] = *b"Hello, world!"; | ||
|
||
macro_rules! get { | ||
($var:expr) => { | ||
unsafe { $var } | ||
}; | ||
} | ||
|
||
macro_rules! set { | ||
($var:expr, $value:expr) => { | ||
unsafe { $var = $value } | ||
}; | ||
} | ||
|
||
macro_rules! add { | ||
($var:expr, $value:expr) => { | ||
unsafe { $var += $value } | ||
}; | ||
} | ||
|
||
#[cfg_attr(feature = "axstd", no_mangle)] | ||
#[inline(never)] | ||
fn main() { | ||
println!("Running TLS tests..."); | ||
|
||
println!( | ||
"main: {} {:#x} {:#x} {:#x} {:#x} {}", | ||
get!(BOOL), | ||
get!(U8), | ||
get!(U16), | ||
get!(U32), | ||
get!(U64), | ||
get!(std::str::from_utf8_unchecked(&STR)) | ||
); | ||
assert!(get!(BOOL)); | ||
assert_eq!(get!(U8), 0xAA); | ||
assert_eq!(get!(U16), 0xcafe); | ||
assert_eq!(get!(U32), 0xdeadbeed); | ||
assert_eq!(get!(U64), 0xa2ce05_a2ce05); | ||
assert_eq!(get!(&STR), b"Hello, world!"); | ||
|
||
let mut tasks = Vec::new(); | ||
for i in 1..=10 { | ||
tasks.push(thread::spawn(move || { | ||
set!(BOOL, i % 2 == 0); | ||
add!(U8, i as u8); | ||
add!(U16, i as u16); | ||
add!(U32, i as u32); | ||
add!(U64, i as u64); | ||
set!(STR[5], 48 + i as u8); | ||
|
||
thread::yield_now(); | ||
|
||
println!( | ||
"{}: {} {:#x} {:#x} {:#x} {:#x} {}", | ||
i, | ||
get!(BOOL), | ||
get!(U8), | ||
get!(U16), | ||
get!(U32), | ||
get!(U64), | ||
get!(std::str::from_utf8_unchecked(&STR)) | ||
); | ||
assert_eq!(get!(BOOL), i % 2 == 0); | ||
assert_eq!(get!(U8), 0xAA + i as u8); | ||
assert_eq!(get!(U16), 0xcafe + i as u16); | ||
assert_eq!(get!(U32), 0xdeadbeed + i as u32); | ||
assert_eq!(get!(U64), 0xa2ce05_a2ce05 + i as u64); | ||
assert_eq!(get!(STR[5]), 48 + i as u8); | ||
assert_eq!(get!(STR.len()), 13); | ||
})); | ||
} | ||
|
||
tasks.into_iter().for_each(|t| t.join().unwrap()); | ||
|
||
// TLS of main thread must not have been changed by the other thread. | ||
assert!(get!(BOOL)); | ||
assert_eq!(get!(U8), 0xAA); | ||
assert_eq!(get!(U16), 0xcafe); | ||
assert_eq!(get!(U32), 0xdeadbeed); | ||
assert_eq!(get!(U64), 0xa2ce05_a2ce05); | ||
assert_eq!(get!(&STR), b"Hello, world!"); | ||
|
||
println!("TLS tests run OK!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
test_one "LOG=info" "expect_info_smp1_fifo.out" | ||
test_one "SMP=4 LOG=info FEATURES=sched_rr" "expect_info_smp4_rr.out" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters