Skip to content
Draft
Show file tree
Hide file tree
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
76 changes: 65 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ members = [
"benches/mutex",
"benches/startup",
"benches/multithreaded",
"benches/getpid",
"examples/axum",
"examples/demo",
"examples/fork",
"examples/pipe",
"examples/true",
"examples/false",
"examples/fuse_test",
"examples/hello_world",
"examples/httpd",
Expand All @@ -17,6 +22,7 @@ members = [
"examples/mioudp",
"examples/polling",
"examples/rftrace-example",
"examples/spawn",
"examples/stdin",
"examples/testtcp",
"examples/testudp",
Expand Down
13 changes: 13 additions & 0 deletions benches/getpid/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "getpid"
authors = ["Stefan Lankes <slankes@eonerc.rwth-aachen.de>"]
edition = "2021"

[dependencies]
hermit-abi = { path = "../../hermit-abi" }

[target.'cfg(target_os = "hermit")'.dependencies]
hermit = { path = "../../hermit", default-features = false }

[features]
default = ["hermit/acpi", "hermit/pci"]
28 changes: 28 additions & 0 deletions benches/getpid/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::hint::black_box;
use std::time::{Duration, Instant};

#[cfg(target_os = "hermit")]
use hermit as _;
use hermit_abi::getpid;

fn getpid_bench(count: usize) -> Duration {
let start = Instant::now();
for _ in 0..count {
let _pid = black_box(unsafe { getpid() });
}
start.elapsed()
}

fn main() {
println!("Determine overhead of getpid...");

// warmup cache
let _ = getpid_bench(2);

let count = 10_0000_0000;
let result = black_box(getpid_bench(count));

println!("Number of iterations: {count}");
println!("Total time: {result:?}");
println!("Time per getpid: {:?}", result / count.try_into().unwrap());
}
10 changes: 10 additions & 0 deletions examples/false/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "false"
authors = ["Stefan Lankes <slankes@eonerc.rwth-aachen.de>"]
edition = "2021"

[target.'cfg(target_os = "hermit")'.dependencies]
hermit = { path = "../../hermit", default-features = false }

[features]
default = ["hermit/acpi", "hermit/pci"]
6 changes: 6 additions & 0 deletions examples/false/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[cfg(target_os = "hermit")]
use hermit as _;

fn main() {
std::process::exit(1);
}
13 changes: 13 additions & 0 deletions examples/fork/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "fork"
authors = ["Stefan Lankes <slankes@eonerc.rwth-aachen.de>"]
edition = "2021"

[dependencies]
hermit-abi = { path = "../../hermit-abi" }

[target.'cfg(target_os = "hermit")'.dependencies]
hermit = { path = "../../hermit", default-features = false }

[features]
default = ["hermit/acpi", "hermit/pci"]
75 changes: 75 additions & 0 deletions examples/fork/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use std::time::{Duration, Instant};

#[cfg(target_os = "hermit")]
use hermit as _;
use hermit_abi::{exec, fork, getpid, waitpid, Pid};

fn fork_bench(count: usize) -> Duration {
let mut pids = vec![Pid::default(); count]; // Pre-allocate with zeros
let app = c"/bin/true";

let start = Instant::now();
for pid in pids.iter_mut().take(count) {
*pid = unsafe { fork() };

if *pid == 0 {
//std::process::exit(0);
unsafe {
let _ = exec(app.as_ptr(), std::ptr::null(), std::ptr::null());
}
}
}

for pid in &pids {
unsafe {
waitpid(*pid);
}
}

start.elapsed()
}

fn main() {
println!("Try to fork a process...");

let pid = unsafe { fork() };
if pid == 0 {
println!("Hello from child process with id {}!", unsafe { getpid() });

let app = c"/bin/hello_world";
// Pass an argument vector and an environment to the new
// process image; both arrays are NULL-terminated.
let argv = [app.as_ptr(), c"--from-exec".as_ptr(), std::ptr::null()];
let envp = [c"GREETING=Hello from exec!".as_ptr(), std::ptr::null()];
unsafe {
let _ = exec(app.as_ptr(), argv.as_ptr(), envp.as_ptr());
}

println!("ERROR: Exec failed!!!");
} else if pid > 0 {
println!(
"Hello from parent process with id {}! Child has the id {}!",
unsafe { getpid() },
pid
);

unsafe {
waitpid(pid);
}

println!("Measure overhead of the system call fork.");

// warmup cache
let _ = fork_bench(2);

for i in 0..14 {
let count = 1 << i;
let result = fork_bench(count);
println!("Time to fork/join {count} processes: {result:?}");
}
} else {
println!("Unable to fork a process!");
}

println!("Leave program");
}
7 changes: 7 additions & 0 deletions examples/hello_world/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@ use hermit as _;

fn main() {
println!("Hello, world!");

for (i, arg) in std::env::args().enumerate() {
println!("arg[{i}]: {arg}");
}
for (key, value) in std::env::vars() {
println!("env: {key}={value}");
}
}
13 changes: 13 additions & 0 deletions examples/pipe/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "pipe"
authors = ["Stefan Lankes <slankes@eonerc.rwth-aachen.de>"]
edition = "2021"

[dependencies]
hermit-abi = { path = "../../hermit-abi" }

[target.'cfg(target_os = "hermit")'.dependencies]
hermit = { path = "../../hermit", default-features = false }

[features]
default = ["hermit/acpi", "hermit/pci"]
Loading