diff --git a/Cargo.lock b/Cargo.lock index 3ef6af0..64ab277 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -847,6 +847,10 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "simple-rw" +version = "0.1.0" + [[package]] name = "siphasher" version = "0.3.10" diff --git a/Cargo.toml b/Cargo.toml index db7d0ad..434e6f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,13 @@ [workspace] resolver = "2" -members = ["ftmemsim", "ftmemsim-util", "ftmemsim-graphs", "util/parse-lackey"] +members = [ + "ftmemsim", + "ftmemsim-util", + "ftmemsim-graphs", + "util/parse-lackey", + "examples/simple-rw", +] [workspace.dependencies] diff --git a/examples/simple-rw/Cargo.toml b/examples/simple-rw/Cargo.toml new file mode 100644 index 0000000..47b8ef4 --- /dev/null +++ b/examples/simple-rw/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "simple-rw" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/examples/simple-rw/run.sh b/examples/simple-rw/run.sh new file mode 100755 index 0000000..e9c74ce --- /dev/null +++ b/examples/simple-rw/run.sh @@ -0,0 +1,25 @@ +#!/bin/env bash + +# Prepare the `lackey` parser +# Note: We always compile the `lackey` parser in release, as it might be too slow otherwise +cargo build --manifest-path "../../Cargo.toml" --release --package "parse-lackey" +parse_lackey="../../target/release/parse-lackey" + + +# Profile to run the example +#PROFILE="dev" +#PROFILE_PATH="debug" +PROFILE="release" +PROFILE_PATH="release" + +# Compile the example +cargo build --profile "$PROFILE" + +# Then run valgrind on the example and pipe it to the `lackey` parser +valgrind \ + --tool=lackey \ + --trace-mem=yes \ + --log-fd=1 \ + "../../target/$PROFILE_PATH/simple-rw" \ + | + $parse_lackey diff --git a/examples/simple-rw/src/main.rs b/examples/simple-rw/src/main.rs new file mode 100644 index 0000000..35d1263 --- /dev/null +++ b/examples/simple-rw/src/main.rs @@ -0,0 +1,38 @@ +//! Simple read-write test binary + +// Imports +use std::{hint, ptr}; + +// TODO: Make these runtime constants? +const PASSES: usize = 2; +const WRITES_PER_PASS: usize = 100; +const READS_PER_PASS: usize = 150; + +fn main() { + let mut v = vec![0u8; 128 * PAGE_SIZE]; + + // Note: We `step_by` the page size because we only care about initializing a single page. + for _ in 0..PASSES { + for x in v.iter_mut().step_by(PAGE_SIZE) { + for _ in 0..WRITES_PER_PASS { + // SAFETY: Target is valid for writes. + // Note: We simply want to avoid the write being elided + unsafe { + ptr::write_volatile(x, hint::black_box(0)); + } + } + } + + for x in v.iter().step_by(PAGE_SIZE) { + for _ in 0..READS_PER_PASS { + // SAFETY: Target is valid for writes. + // Note: We simply want to avoid the write being elided + unsafe { + hint::black_box(ptr::read_volatile(x)); + } + } + } + } +} + +const PAGE_SIZE: usize = 4096; diff --git a/run.sh b/run.sh index 9997f27..49f25aa 100755 --- a/run.sh +++ b/run.sh @@ -12,6 +12,7 @@ PROFILE="release" #TRACE_FILE="resources/traces/bfs.g15.n15.trace" TRACE_FILE="resources/traces/bfs.g17.n100.t1.trace" #TRACE_FILE="resources/traces/bc.g18.n100.t1.trace" +#TRACE_FILE="examples/simple-rw/output.trace" OUTPUT_FILE="resources/data/output.bin.gz"