fix(bench): eliminate SIGBUS handler static mut UB with Once + raw atomics (closes #33)
Replace `static mut OLD_SIGBUS_HANDLER` with AtomicU8 + AtomicPtr to remove data race UB when concurrent benchmarks call open() from multiple threads. Key changes: - Use `Once::call_once` to guarantee single handler installation - Publish old handler to atomics BEFORE installing new handler (closes the handler-active-but-state-unpublished race window) - Read atomics with Acquire in signal handler (async-signal-safe) - Align si_addr to page boundary before mmap(MAP_FIXED) - Add concurrent test: 8 threads open all 5 variants simultaneously
This commit is contained in:
59
crates/bench/src/runner.rs
Normal file
59
crates/bench/src/runner.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
use crate::metrics::MetricsCollector;
|
||||
use crate::types::BenchmarkResult;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub struct BenchConfig {
|
||||
pub test_file: PathBuf,
|
||||
pub quick_mode: bool,
|
||||
pub suites: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
fn warn_reset_hwm() {
|
||||
if let Err(e) = MetricsCollector::reset_vm_hwm() {
|
||||
if e.kind() == std::io::ErrorKind::PermissionDenied {
|
||||
eprintln!("WARNING: VmHWM reset requires root: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_all(config: &BenchConfig) -> Vec<BenchmarkResult> {
|
||||
let mut results = Vec::new();
|
||||
|
||||
let should_run = |name: &str| -> bool {
|
||||
match &config.suites {
|
||||
Some(suites) => suites.iter().any(|s| s == name),
|
||||
None => true,
|
||||
}
|
||||
};
|
||||
|
||||
if should_run("startup") {
|
||||
warn_reset_hwm();
|
||||
results.extend(crate::suites::startup::run(config));
|
||||
}
|
||||
if should_run("render") {
|
||||
warn_reset_hwm();
|
||||
results.extend(crate::suites::render::run(config));
|
||||
}
|
||||
if should_run("jump") {
|
||||
warn_reset_hwm();
|
||||
results.extend(crate::suites::jump::run(config));
|
||||
}
|
||||
if should_run("memory") {
|
||||
warn_reset_hwm();
|
||||
results.extend(crate::suites::memory::run(config));
|
||||
}
|
||||
if should_run("growth") {
|
||||
warn_reset_hwm();
|
||||
results.extend(crate::suites::growth::run(config));
|
||||
}
|
||||
if should_run("rotation") {
|
||||
warn_reset_hwm();
|
||||
results.extend(crate::suites::rotation::run(config));
|
||||
}
|
||||
if should_run("concurrent") {
|
||||
warn_reset_hwm();
|
||||
results.extend(crate::suites::concurrent::run(config));
|
||||
}
|
||||
|
||||
results
|
||||
}
|
||||
Reference in New Issue
Block a user