Rust comments that named scripts/offline/*, gen_goldens.py, oracle/gen_*.{sh,cpp,py}, build_oracle.sh and similar retired generators now say where the data
came from (the Original's code, Strata 41cf05a0) or drop the sentence. The path/generator text of seven generated fixtures (sampler_oracle.json, sampling_keys.json,
memory_plan_golden.json, rope_golden.json, cvec_oracle.json, stra161 fixtures.json, commentary-tool-prompt.json) is reworded; no test reads those fields and no pin
covers their bytes. cmd_time/doc.rs: the two path texts in the format string; its lines are re-broken so they stay within 120 columns (the string is unchanged
otherwise). Comment-only except those data/string spots; no behaviour change.
192 lines
8.0 KiB
Rust
192 lines
8.0 KiB
Rust
//! The KAB1-time JSON document of `kernel_ab time`, assembled in ten consecutive sections.
|
|
|
|
#[allow(unused_imports)]
|
|
use super::*;
|
|
|
|
/// The three inputs of the document besides the run itself: the pin facts after the run and the measurements.
|
|
pub(super) struct TimeDoc<'a> {
|
|
pub(super) run: &'a TimeRun<'a>,
|
|
pub(super) end: &'a PinEnd,
|
|
pub(super) m: &'a Measured,
|
|
}
|
|
|
|
fn frac(f: Option<f64>) -> String {
|
|
f.map_or("null".to_owned(), |v| jnum(v, 4))
|
|
}
|
|
|
|
impl TimeDoc<'_> {
|
|
/// The whole document: the sections follow each other in the order of the file.
|
|
pub(super) fn document(&self) -> String {
|
|
[
|
|
String::from(
|
|
"{\n \"format\": \"KAB1-time\",\n \"version\": 1,\n \"mode\": \"time\",\n \"writer\": \"rust\",\n",
|
|
),
|
|
self.run_info(),
|
|
self.case_json(),
|
|
self.tree_json(),
|
|
self.pool_json(),
|
|
self.pin_json(),
|
|
self.buffers_json(),
|
|
self.clock_json(),
|
|
self.build_json(),
|
|
self.tail_json(),
|
|
]
|
|
.concat()
|
|
}
|
|
|
|
/// The command line as `kab time` would have been given it.
|
|
fn command_line(&self) -> String {
|
|
let (t, args) = (&self.run.t, self.run.args);
|
|
format!(
|
|
"time --run-dir {} --case {} --slices {} --pin {} --out {}{}{}",
|
|
t.dir.display(),
|
|
t.case,
|
|
t.slices,
|
|
t.pin,
|
|
t.out.display(),
|
|
if args.iter().any(|a| a == "--slice-ms") { format!(" --slice-ms {}", t.slice_ms) } else { String::new() },
|
|
match t.regime {
|
|
RegimeSel::Both => String::new(),
|
|
RegimeSel::Resident => " --regime resident".to_owned(),
|
|
RegimeSel::Streamed => " --regime streamed".to_owned(),
|
|
}
|
|
)
|
|
}
|
|
|
|
fn run_info(&self) -> String {
|
|
let t = &self.run.t;
|
|
format!(
|
|
" \"command_line\": {},\n \"run_dir\": {},\n \"manifest_sha256\": {},\n",
|
|
jstr(&self.command_line()),
|
|
jstr(&t.dir.display().to_string()),
|
|
jstr(&self.run.loaded.manifest_sha)
|
|
)
|
|
}
|
|
|
|
fn case_json(&self) -> String {
|
|
let (t, loaded) = (&self.run.t, &self.run.loaded);
|
|
let header = loaded.case.header;
|
|
let (gu_name, down_name) =
|
|
(gate_up_row(header.gu).map_or("?", |x| x.4), down_row(header.down).map_or("?", |x| x.4));
|
|
let in_name = format!("case-{}.in", t.case);
|
|
format!(
|
|
" \"case\": {{\"id\": {}, \"gu_type\": {}, \"down_type\": {}, \"gu_name\": {}, \"down_name\": {}, \
|
|
\"rows\": {}, \"input_file\": {}, \"input_sha256\": {}, \"input_sha256_matches_manifest\": true, \
|
|
\"expert_bytes\": {}}},\n",
|
|
jstr(&t.case),
|
|
header.gu,
|
|
header.down,
|
|
jstr(gu_name),
|
|
jstr(down_name),
|
|
header.rows,
|
|
jstr(&in_name),
|
|
jstr(&loaded.entry.in_sha256),
|
|
loaded.expert_bytes()
|
|
)
|
|
}
|
|
|
|
fn tree_json(&self) -> String {
|
|
let host = &self.run.host;
|
|
format!(
|
|
" \"tree\": {},\n \"tree_detail\": {{\"tree\": {}, \"cpu_report\": [{}], \"strata_env\": {}}},\n \
|
|
\"effective_env\": {},\n",
|
|
jstr(host.tree),
|
|
jstr(host.tree),
|
|
host.report.iter().map(|l| jstr(l)).collect::<Vec<_>>().join(", "),
|
|
json_env(&host.env),
|
|
json_env(&host.env)
|
|
)
|
|
}
|
|
|
|
fn pool_json(&self) -> String {
|
|
format!(
|
|
" \"pool\": {{\"workers\": 1, \"host_drains\": true, \"threads_observed\": [{}], \"note\": \
|
|
\"DirectCpuPool::new(1): one worker thread plus the calling thread that drains beside it (pool.cpp \
|
|
host_works_); both inherit the one-CPU mask of the pin\"}},\n",
|
|
self.end
|
|
.threads
|
|
.iter()
|
|
.map(|(n, c)| format!(
|
|
"{{\"name\": {}, \"cpu\": {}}}",
|
|
jstr(n),
|
|
c.map_or("null".to_owned(), |c| c.to_string())
|
|
))
|
|
.collect::<Vec<_>>()
|
|
.join(", ")
|
|
)
|
|
}
|
|
|
|
fn pin_json(&self) -> String {
|
|
let (start, end) = (&self.run.start, self.end);
|
|
let (cpu_dir, sibling) = (&start.cpu_dir, start.sibling);
|
|
format!(
|
|
" \"pin\": {{\"cpu\": {}, \"thread_siblings_list\": {}, \"sibling_cpu\": {}, \"physical_core_id\": {}, \
|
|
\"pin_busy_fraction_during_run\": {}, \"sibling_busy_fraction_during_run\": {}, \"sibling_busy_note\": \
|
|
\"/proc/stat jiffies of the sibling logical CPU between the start and the end of this process; it is \
|
|
recorded, no threshold is applied here\", \"scaling_governor\": {}, \"cpufreq_boost\": {}, \
|
|
\"loadavg_start\": {}, \"loadavg_end\": {}, \"final_cpu\": {}}},\n",
|
|
self.run.t.pin,
|
|
jstr(&start.sib_text),
|
|
sibling.map_or("null".to_owned(), |s| s.to_string()),
|
|
jstr(&read_text(&format!("{cpu_dir}/topology/core_id"))),
|
|
frac(busy_fraction(start.pin0, end.pin1)),
|
|
if sibling.is_some() { frac(busy_fraction(start.sib0, end.sib1)) } else { "null".to_owned() },
|
|
jstr(&read_text(&format!("{cpu_dir}/cpufreq/scaling_governor"))),
|
|
jstr(&read_text("/sys/devices/system/cpu/cpufreq/boost")),
|
|
jstr(&start.load0),
|
|
jstr(&read_text("/proc/loadavg")),
|
|
current_cpu().map_or("null".to_owned(), |c| c.to_string())
|
|
)
|
|
}
|
|
|
|
fn buffers_json(&self) -> String {
|
|
let stride = self.run.plan.stride;
|
|
format!(
|
|
" \"buffers\": {{\"alignment_bytes\": {ALIGN}, \"expert_copy_stride_bytes\": {stride}, \
|
|
\"activations_aligned\": true, \"scratch_aligned\": false, \"scratch_note\": \"the pool's own scratch is \
|
|
allocated inside the crate\"}},\n"
|
|
)
|
|
}
|
|
|
|
fn clock_json(&self) -> String {
|
|
format!(
|
|
" \"clock_calibration\": {{\"method\": {}, \"source\": \"Strata 41cf05a0, \
|
|
src/kernels/cpu/tq_cpu_parity.cpp --bench: core_ghz() lines 273-284, time_slice() lines 290-304; the \
|
|
dependent-add chain needs inline assembly, so the safe Rust twin chains multiplies\", \"drop_rule\": \
|
|
{{\"source_file\": \"Strata 41cf05a0, src/kernels/cpu/tq_cpu_parity.cpp\", \"source_line\": 303, \
|
|
\"source_text\": \"std::fabs(g1 \
|
|
- g0) > 0.05 * g0\", \"fraction\": {}, \"meaning\": \"a slice whose calibrated clock moved by more than 5 \
|
|
percent between its before and after calibration is dropped\"}}, \"slice_ms_source\": \
|
|
\"tq_cpu_parity.cpp:461 slice_ms = quick ? 40 : 60\", \"ghz_at_start\": {}, \"ghz_at_end\": {}, \
|
|
\"tsc_invariant\": null, \"clocks\": \"monotonic ns (std::time::Instant); no TSC read: rdtsc and lfence \
|
|
are unsafe intrinsics and the crate keeps unsafe_code = deny\"}},\n",
|
|
jstr(CLOCK_METHOD),
|
|
jnum(CLOCK_MOVED_FRACTION, 2),
|
|
jnum(self.m.ghz.0, 6),
|
|
jnum(self.m.ghz.1, 6)
|
|
)
|
|
}
|
|
|
|
fn build_json(&self) -> String {
|
|
format!(
|
|
" \"build\": {{\"profile\": {}, \"rustflags\": {}, \"example\": \
|
|
\"crates/native-cpu-expert/examples/kernel_ab.rs\"}},\n",
|
|
jstr(if cfg!(debug_assertions) { "dev" } else { "release" }),
|
|
jstr(&std::env::var("RUSTFLAGS").unwrap_or_default())
|
|
)
|
|
}
|
|
|
|
fn tail_json(&self) -> String {
|
|
let (selfcheck, final_same) = (self.m.selfcheck, self.m.final_same);
|
|
format!(
|
|
" \"selfcheck_bitwise_equal_first_call\": {selfcheck},\n \"final_output_unchanged\": {final_same},\n \
|
|
\"output_sha256\": {},\n \"duration_ns\": {},\n \"timing_caveat\": \"numbers from a shared host are not \
|
|
evidence by themselves; loadavg and the sibling busy fraction are recorded above\",\n \"regimes\": [\n \
|
|
{}\n ]\n}}\n",
|
|
jstr(&self.m.output_sha),
|
|
mono_ns() - self.run.wall0,
|
|
self.m.regimes.json.join(",\n ")
|
|
)
|
|
}
|
|
}
|