Skip to content

Commit dabf1be

Browse files
committed
Add a benchmark for cross-task kernel memory region synchronization
Vectors are allocated from the kernel's memory region, which has some heinous synchronization. This is a stress test of vector allocation in many tasks.
1 parent 30447e1 commit dabf1be

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Vectors are allocated in the Rust kernel's memory region, use of
2+
// which requires some amount of synchronization. This test exercises
3+
// that synchronization by spawning a number of tasks and then
4+
// allocating and freeing vectors.
5+
6+
use std;
7+
import std::vec;
8+
import std::uint;
9+
import std::istr;
10+
import std::task;
11+
12+
fn f(n: uint) {
13+
for each i in uint::range(0u, n) {
14+
let v: [u8] = [];
15+
vec::reserve(v, 1000u);
16+
}
17+
}
18+
19+
fn main(args: [istr]) {
20+
let n = if vec::len(args) < 2u {
21+
100u
22+
} else {
23+
uint::parse_buf(istr::bytes(args[1]), 10u)
24+
};
25+
for each i in uint::range(0u, 100u) {
26+
task::spawn(bind f(n));
27+
}
28+
}

0 commit comments

Comments
 (0)