1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//! Background calibration: runtime measurement of per-host kernel
//! costs via the [`crate::sched::io_pool::IoPool`].
//!
//! Calibration microbenches run on the SMT-sibling IO pool so
//! measured per-host costs land in caller-owned tables without
//! occupying the compute pool. Requires
//! `FLYNNEL_SCHED_SMT_AS_IO=on`; with the IoPool disabled,
//! [`spawn_calibration`] is a no-op. Callers supply the microbench
//! closures (the scheduler is domain-agnostic); this module owns
//! only the IoPool dispatch wiring.
//!
//! ## Example
//!
//! ```no_run
//! use std::sync::{Arc, RwLock};
//! use std::collections::HashMap;
//! use std::time::Instant;
//! use flynnel::sched::spawn_calibration;
//!
//! // Caller-owned table.
//! let table: Arc<RwLock<HashMap<&'static str, f64>>> =
//! Arc::new(RwLock::new(HashMap::new()));
//!
//! let t1 = Arc::clone(&table);
//! let t2 = Arc::clone(&table);
//! spawn_calibration(vec![
//! Box::new(move || {
//! // microbench body for kernel "alpha"
//! let t0 = Instant::now();
//! for _ in 0..1000 { std::hint::black_box(1u64.wrapping_add(1)); }
//! let ns = t0.elapsed().as_nanos() as f64 / 1000.0;
//! t1.write().unwrap().insert("alpha", ns);
//! }),
//! Box::new(move || {
//! // microbench body for kernel "beta"
//! let t0 = Instant::now();
//! for _ in 0..1000 { std::hint::black_box(2u64.wrapping_mul(3)); }
//! let ns = t0.elapsed().as_nanos() as f64 / 1000.0;
//! t2.write().unwrap().insert("beta", ns);
//! }),
//! ]);
//! ```
use crateglobal_io_pool;
/// Run one timed microbench: invoke `op` `iters` times, return
/// average per-call cost in nanoseconds.
///
/// Uses an 8-iteration warm-up to stabilize the cache + branch
/// predictor before measuring. Callers that need a different warm-up
/// shape should write their own timer loop.
/// Spawn a list of calibration microbenches on the IO pool.
///
/// Each closure runs once on a free SMT-sibling thread. The IoPool
/// is shared with other non-compute roles (background memory zero,
/// verify-chain hashing); calibration jobs queue alongside those.
///
/// No-op when the IoPool is disabled.
// ---------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------