mirror of
https://github.com/Zenithsiz/ftmemsim.git
synced 2026-02-03 17:52:16 +00:00
Added example simple-rw to generate traces.
This commit is contained in:
parent
d7e521e31d
commit
2f621c7a1c
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -847,6 +847,10 @@ dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simple-rw"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "0.3.10"
|
||||
|
||||
@ -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]
|
||||
|
||||
|
||||
6
examples/simple-rw/Cargo.toml
Normal file
6
examples/simple-rw/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "simple-rw"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
25
examples/simple-rw/run.sh
Executable file
25
examples/simple-rw/run.sh
Executable file
@ -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
|
||||
38
examples/simple-rw/src/main.rs
Normal file
38
examples/simple-rw/src/main.rs
Normal file
@ -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;
|
||||
Loading…
x
Reference in New Issue
Block a user