feat(boot): report the host's regime changes and prediction isolations, count and time each, in a PES REGIME line under profiling

This commit is contained in:
Tyler Smith committed 2026-11-12 10:42:08 -05:00
1 parent 19a3df94df
commit c6c41c2f71
3 files changed
+85

No files matched your search

+19
View File
@@ -320,6 +320,24 @@ fn barrier_waits_report(waits: &step_timing::BarrierWaits, tsc_hz: u64) {
output::arguments(format_args!("{line}\n"));
}
/// `PES REGIME`: the host's regime changes and prediction isolations, how
/// many and the time each took.
fn regime_syncs_report(regimes: &step_timing::RegimeSyncs, tsc_hz: u64) {
if regimes.syncs == 0 {
return;
}
let each = |count: u64, ticks: u64| {
u128::from(ticks) * 1_000_000_000 / u128::from(count.max(1)) / u128::from(tsc_hz.max(1))
};
output::arguments(format_args!(
"PES REGIME syncs={} ns_each={} isolations={} ns_each={}\n",
regimes.syncs,
each(regimes.syncs, regimes.sync_ticks),
regimes.isolations,
each(regimes.isolations, regimes.isolation_ticks),
));
}
fn device_exits_report<H: Host>(
machine: &Machine<H, parallel::Board>,
exits: &step_timing::DeviceExits,
@@ -1845,6 +1863,7 @@ impl Heartbeat {
let exits = parallel::system_exits(machine);
system_exits_report(&exits, tsc_hz);
barrier_waits_report(&exits.barriers, tsc_hz);
regime_syncs_report(&exits.regimes, tsc_hz);
device_exits_report(machine, &exits.devices, tsc_hz);
transfer_times_report(machine, tsc_hz);
hot_blocks_report(
@@ -270,12 +270,26 @@ impl<H: Host, D: Devices> Machine<H, D> {
tag_checks: self.tag_checks,
};
self.publish_translating(&regime.controls);
let syncing = self.timing_start();
self.host.set_regime(&regime);
let synced = self.timing_since(syncing);
let context = PredictionContext::of(&self.cpu);
let mut isolated = None;
if self.prediction_context != Some(context) {
self.prediction_context = Some(context);
self.statistics.prediction_isolations += 1;
let isolating = self.timing_start();
self.host.isolate_predictions();
isolated = Some(self.timing_since(isolating));
}
if self.step_timing.is_some() {
let regimes = &mut self.system_exits.regimes;
regimes.syncs += 1;
regimes.sync_ticks += synced;
if let Some(ticks) = isolated {
regimes.isolations += 1;
regimes.isolation_ticks += ticks;
}
}
}
}
@@ -304,6 +304,28 @@ pub struct SystemExits {
pub floating: [u64; FloatingReason::COUNT],
pub floating_words: FloatingWords,
pub barriers: BarrierWaits,
pub regimes: RegimeSyncs,
}
/// The host's regime changes ([`super::Host::set_regime`]) and prediction
/// isolations ([`super::Host::isolate_predictions`]) under step timing: how
/// many and their profile ticks.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct RegimeSyncs {
pub syncs: u64,
pub sync_ticks: u64,
pub isolations: u64,
pub isolation_ticks: u64,
}
impl RegimeSyncs {
/// Add every change `other` counts.
pub fn merge(&mut self, other: &Self) {
self.syncs += other.syncs;
self.sync_ticks += other.sync_ticks;
self.isolations += other.isolations;
self.isolation_ticks += other.isolation_ticks;
}
}
/// The [`BarrierWaits`] blocker of a PE in native code, or between its
@@ -881,6 +903,7 @@ impl Default for SystemExits {
floating: [0; FloatingReason::COUNT],
floating_words: FloatingWords::default(),
barriers: BarrierWaits::default(),
regimes: RegimeSyncs::default(),
}
}
}
@@ -915,6 +938,7 @@ impl SystemExits {
}
self.floating_words.merge(&exits.floating_words);
self.barriers.merge(&exits.barriers);
self.regimes.merge(&exits.regimes);
}
/// The keys with exits.
@@ -929,6 +953,7 @@ impl SystemExits {
&& self.floating.iter().all(|&count| count == 0)
&& self.floating_words.is_empty()
&& self.barriers.waits == 0
&& self.regimes == RegimeSyncs::default()
}
}
@@ -1854,6 +1879,33 @@ mod tests {
);
}
#[test]
fn regime_syncs_merge() {
let regimes = RegimeSyncs {
syncs: 3,
sync_ticks: 30,
isolations: 1,
isolation_ticks: 7,
};
let exits = SystemExits {
regimes,
..SystemExits::default()
};
assert!(!exits.is_empty());
let mut merged = SystemExits::default();
merged.merge(&exits);
merged.merge(&exits);
assert_eq!(
merged.regimes,
RegimeSyncs {
syncs: 6,
sync_ticks: 60,
isolations: 2,
isolation_ticks: 14,
}
);
}
#[test]
fn barrier_waits_count_quick_ones_apart_and_merge_by_blocker() {
let system = stela_compiler::block::ExitKind::System as usize;