This commit is contained in:
Generated
+537
-345
File diff suppressed because it is too large
Load Diff
@@ -19,8 +19,8 @@ prometeu-system = { path = "../../console/prometeu-system" }
|
|||||||
prometeu-drivers = { path = "../../console/prometeu-drivers" }
|
prometeu-drivers = { path = "../../console/prometeu-drivers" }
|
||||||
prometeu-hal = { path= "../../console/prometeu-hal" }
|
prometeu-hal = { path= "../../console/prometeu-hal" }
|
||||||
winit = "0.30.12"
|
winit = "0.30.12"
|
||||||
pixels = "0.15.0"
|
pixels = "0.17.2"
|
||||||
cpal = "0.15.3"
|
cpal = "0.15.3"
|
||||||
ringbuf = "0.4.7"
|
ringbuf = "0.4.7"
|
||||||
serde_json = "1.0.149"
|
serde_json = "1.0.149"
|
||||||
clap = { version = "4.5", features = ["derive"] }
|
clap = { version = "4.5", features = ["derive"] }
|
||||||
|
|||||||
@@ -397,7 +397,7 @@ impl AudioMixer {
|
|||||||
let vol_l = vol_f * (1.0 - pan_f).sqrt();
|
let vol_l = vol_f * (1.0 - pan_f).sqrt();
|
||||||
let vol_r = vol_f * pan_f.sqrt();
|
let vol_r = vol_f * pan_f.sqrt();
|
||||||
|
|
||||||
for frame in buffer.chunks_exact_mut(2) {
|
for frame in buffer.as_chunks_mut::<2>().0 {
|
||||||
let pos_int = voice.pos as usize;
|
let pos_int = voice.pos as usize;
|
||||||
let pos_fract = voice.pos - pos_int as f64;
|
let pos_fract = voice.pos - pos_int as f64;
|
||||||
|
|
||||||
|
|||||||
@@ -12,3 +12,7 @@ prometeu-drivers = { path = "../../console/prometeu-drivers" }
|
|||||||
prometeu-firmware = { path = "../../console/prometeu-firmware" }
|
prometeu-firmware = { path = "../../console/prometeu-firmware" }
|
||||||
prometeu-hal = { path = "../../console/prometeu-hal" }
|
prometeu-hal = { path = "../../console/prometeu-hal" }
|
||||||
prometeu-system = { path = "../../console/prometeu-system" }
|
prometeu-system = { path = "../../console/prometeu-system" }
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "temporal"
|
||||||
|
harness = false
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
use std::fs;
|
||||||
|
use std::hint::black_box;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::time::{Instant, SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
|
use prometeu_bytecode::SourceSpan;
|
||||||
|
use prometeu_bytecode::assembler::assemble;
|
||||||
|
use prometeu_bytecode::model::{BytecodeModule, DebugInfo, Export, FunctionMeta};
|
||||||
|
use prometeu_host_headless::{AdvanceFramesStop, HeadlessHost};
|
||||||
|
|
||||||
|
const SAMPLE_FRAMES: u64 = 300;
|
||||||
|
const SAMPLE_COUNT: u32 = 10;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let cartridge = benchmark_cartridge();
|
||||||
|
let mut samples = Vec::with_capacity(SAMPLE_COUNT as usize);
|
||||||
|
|
||||||
|
for _ in 0..SAMPLE_COUNT {
|
||||||
|
let mut host = HeadlessHost::new();
|
||||||
|
host.boot(cartridge.to_string_lossy()).expect("boot benchmark cartridge");
|
||||||
|
|
||||||
|
let started = Instant::now();
|
||||||
|
let outcome =
|
||||||
|
black_box(host.advance_frames(SAMPLE_FRAMES)).expect("advance benchmark frames");
|
||||||
|
let elapsed = started.elapsed();
|
||||||
|
|
||||||
|
assert_eq!(outcome.completed, SAMPLE_FRAMES);
|
||||||
|
assert_eq!(outcome.stop, AdvanceFramesStop::Completed);
|
||||||
|
samples.push(elapsed.as_secs_f64());
|
||||||
|
}
|
||||||
|
|
||||||
|
samples.sort_by(f64::total_cmp);
|
||||||
|
let median_seconds = samples[samples.len() / 2];
|
||||||
|
let frames_per_second = SAMPLE_FRAMES as f64 / median_seconds;
|
||||||
|
println!(
|
||||||
|
"headless advance_frames: median={median_seconds:.6}s frames={SAMPLE_FRAMES} throughput={frames_per_second:.2} frames/s samples={SAMPLE_COUNT}"
|
||||||
|
);
|
||||||
|
|
||||||
|
fs::remove_dir_all(&cartridge).expect("remove benchmark cartridge");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn benchmark_cartridge() -> PathBuf {
|
||||||
|
let directory = std::env::temp_dir().join(format!(
|
||||||
|
"prometeu-headless-benchmark-{}-{}",
|
||||||
|
std::process::id(),
|
||||||
|
SystemTime::now().duration_since(UNIX_EPOCH).expect("system clock").as_nanos()
|
||||||
|
));
|
||||||
|
fs::create_dir_all(&directory).expect("create benchmark cartridge");
|
||||||
|
|
||||||
|
let code = assemble("FRAME_SYNC\nRET\n").expect("assemble benchmark program");
|
||||||
|
let module = BytecodeModule {
|
||||||
|
version: 0,
|
||||||
|
const_pool: vec![],
|
||||||
|
functions: vec![FunctionMeta {
|
||||||
|
code_offset: 0,
|
||||||
|
code_len: code.len() as u32,
|
||||||
|
param_slots: 0,
|
||||||
|
local_slots: 0,
|
||||||
|
return_slots: 0,
|
||||||
|
max_stack_slots: 1,
|
||||||
|
}],
|
||||||
|
code,
|
||||||
|
debug_info: Some(DebugInfo {
|
||||||
|
pc_to_span: vec![(0, SourceSpan { file_id: 1, start: 0, end: 10 })],
|
||||||
|
function_names: vec![(0, "main".into())],
|
||||||
|
}),
|
||||||
|
exports: vec![Export { symbol: "main".into(), func_idx: 0 }],
|
||||||
|
syscalls: vec![],
|
||||||
|
}
|
||||||
|
.serialize();
|
||||||
|
|
||||||
|
fs::write(directory.join("program.pbx"), module).expect("write benchmark program");
|
||||||
|
write_manifest(&directory);
|
||||||
|
directory
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_manifest(directory: &Path) {
|
||||||
|
fs::write(
|
||||||
|
directory.join("manifest.json"),
|
||||||
|
"{\n \"magic\": \"PMTU\",\n \"cartridge_version\": 1,\n \"app_id\": 90,\n \"title\": \"Headless Temporal Benchmark\",\n \"app_version\": \"0.1.0\",\n \"app_mode\": \"Game\",\n \"capabilities\": []\n}\n",
|
||||||
|
)
|
||||||
|
.expect("write benchmark manifest");
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ use prometeu_hal::{
|
|||||||
use prometeu_system::{CrashReport, LatestRenderFrameStore};
|
use prometeu_system::{CrashReport, LatestRenderFrameStore};
|
||||||
|
|
||||||
const BOOT_TICK_LIMIT: usize = 64;
|
const BOOT_TICK_LIMIT: usize = 64;
|
||||||
const LOGICAL_FRAME_TICK_LIMIT: usize = 100_000;
|
const HOST_FRAME_ADVANCE_TICK_LIMIT: usize = 100_000;
|
||||||
|
|
||||||
/// One published logical frame plus the automation counter.
|
/// One published logical frame plus the automation counter.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
@@ -68,7 +68,7 @@ pub enum HostError {
|
|||||||
AlreadyBooted,
|
AlreadyBooted,
|
||||||
BootFailed { reason: String, report: Option<CrashReport> },
|
BootFailed { reason: String, report: Option<CrashReport> },
|
||||||
InvalidState { operation: &'static str, status: HostExecutionStatus },
|
InvalidState { operation: &'static str, status: HostExecutionStatus },
|
||||||
LogicalFrameDidNotClose,
|
FrameAdvanceWatchdogExpired { host_tick_limit: usize },
|
||||||
FrameNotPublished { previous: Option<FrameId> },
|
FrameNotPublished { previous: Option<FrameId> },
|
||||||
NoFrameAvailable,
|
NoFrameAvailable,
|
||||||
}
|
}
|
||||||
@@ -81,8 +81,11 @@ impl fmt::Display for HostError {
|
|||||||
Self::InvalidState { operation, status } => {
|
Self::InvalidState { operation, status } => {
|
||||||
write!(f, "{operation} is invalid while execution is {status:?}")
|
write!(f, "{operation} is invalid while execution is {status:?}")
|
||||||
}
|
}
|
||||||
Self::LogicalFrameDidNotClose => {
|
Self::FrameAdvanceWatchdogExpired { host_tick_limit } => {
|
||||||
write!(f, "logical frame did not reach FrameSync, end of ROM, or a fault")
|
write!(
|
||||||
|
f,
|
||||||
|
"headless host frame-advance watchdog expired after {host_tick_limit} firmware ticks"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
Self::FrameNotPublished { .. } => {
|
Self::FrameNotPublished { .. } => {
|
||||||
write!(f, "logical frame closed without its canonical published frame")
|
write!(f, "logical frame closed without its canonical published frame")
|
||||||
@@ -217,19 +220,20 @@ impl HeadlessHost {
|
|||||||
self.firmware.os.vm().set_paused(false);
|
self.firmware.os.vm().set_paused(false);
|
||||||
self.firmware.os.vm().request_debug_step();
|
self.firmware.os.vm().request_debug_step();
|
||||||
|
|
||||||
for _ in 0..LOGICAL_FRAME_TICK_LIMIT {
|
for _ in 0..HOST_FRAME_ADVANCE_TICK_LIMIT {
|
||||||
self.tick_once();
|
self.tick_once();
|
||||||
if let Some(report) = self.get_fault() {
|
if let Some(report) = self.get_fault() {
|
||||||
self.finish_frame_step();
|
self.finish_frame_advance();
|
||||||
return Ok(AdvanceFrameOutcome::Faulted(report));
|
return Ok(AdvanceFrameOutcome::Faulted(report));
|
||||||
}
|
}
|
||||||
if !matches!(self.firmware.state, FirmwareState::GameRunning(_)) {
|
if !matches!(self.firmware.state, FirmwareState::GameRunning(_)) {
|
||||||
|
self.finish_frame_advance();
|
||||||
return Ok(AdvanceFrameOutcome::Terminated);
|
return Ok(AdvanceFrameOutcome::Terminated);
|
||||||
}
|
}
|
||||||
|
|
||||||
let logical_frame_index = self.firmware.os.vm().logical_frame_index();
|
let logical_frame_index = self.firmware.os.vm().logical_frame_index();
|
||||||
if logical_frame_index > start {
|
if logical_frame_index > start {
|
||||||
self.finish_frame_step();
|
self.finish_frame_advance();
|
||||||
let frame = self
|
let frame = self
|
||||||
.platform
|
.platform
|
||||||
.store
|
.store
|
||||||
@@ -247,8 +251,10 @@ impl HeadlessHost {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.finish_frame_step();
|
self.finish_frame_advance();
|
||||||
Err(HostError::LogicalFrameDidNotClose)
|
Err(HostError::FrameAdvanceWatchdogExpired {
|
||||||
|
host_tick_limit: HOST_FRAME_ADVANCE_TICK_LIMIT,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn advance_frames(&mut self, count: u64) -> Result<AdvanceFramesOutcome, HostError> {
|
pub fn advance_frames(&mut self, count: u64) -> Result<AdvanceFramesOutcome, HostError> {
|
||||||
@@ -349,7 +355,7 @@ impl HeadlessHost {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finish_frame_step(&mut self) {
|
fn finish_frame_advance(&mut self) {
|
||||||
self.firmware.os.vm().set_paused(true);
|
self.firmware.os.vm().set_paused(true);
|
||||||
self.firmware.os.vm().clear_debug_step_request();
|
self.firmware.os.vm().clear_debug_step_request();
|
||||||
}
|
}
|
||||||
@@ -423,3 +429,69 @@ impl RuntimePlatform for HeadlessPlatform {
|
|||||||
self.hardware.telemetry()
|
self.hardware.telemetry()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
use prometeu_bytecode::assembler::assemble;
|
||||||
|
use prometeu_bytecode::model::{BytecodeModule, Export, FunctionMeta};
|
||||||
|
|
||||||
|
use super::{AdvanceFrameOutcome, HeadlessHost};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn termination_during_frame_advance_clears_host_step_control() {
|
||||||
|
let cartridge = non_closing_cartridge();
|
||||||
|
let mut host = HeadlessHost::new();
|
||||||
|
host.boot(cartridge.to_string_lossy()).expect("boot non-closing cartridge");
|
||||||
|
host.firmware.request_home_from_host();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
host.advance_frame().expect("lifecycle termination"),
|
||||||
|
AdvanceFrameOutcome::Terminated
|
||||||
|
);
|
||||||
|
assert!(host.firmware.os.vm().paused());
|
||||||
|
assert!(!host.firmware.os.vm().debug_step_requested());
|
||||||
|
|
||||||
|
fs::remove_dir_all(cartridge).expect("remove test cartridge");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn non_closing_cartridge() -> std::path::PathBuf {
|
||||||
|
let directory = std::env::temp_dir().join(format!(
|
||||||
|
"prometeu-headless-termination-cleanup-{}-{}",
|
||||||
|
std::process::id(),
|
||||||
|
std::time::SystemTime::now()
|
||||||
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
.expect("system clock")
|
||||||
|
.as_nanos()
|
||||||
|
));
|
||||||
|
fs::create_dir_all(&directory).expect("create test cartridge");
|
||||||
|
|
||||||
|
let code = assemble("JMP 0\n").expect("assemble non-closing program");
|
||||||
|
let module = BytecodeModule {
|
||||||
|
version: 0,
|
||||||
|
const_pool: vec![],
|
||||||
|
functions: vec![FunctionMeta {
|
||||||
|
code_offset: 0,
|
||||||
|
code_len: code.len() as u32,
|
||||||
|
param_slots: 0,
|
||||||
|
local_slots: 0,
|
||||||
|
return_slots: 0,
|
||||||
|
max_stack_slots: 1,
|
||||||
|
}],
|
||||||
|
code,
|
||||||
|
debug_info: None,
|
||||||
|
exports: vec![Export { symbol: "main".into(), func_idx: 0 }],
|
||||||
|
syscalls: vec![],
|
||||||
|
}
|
||||||
|
.serialize();
|
||||||
|
fs::write(directory.join("program.pbx"), module).expect("write test program");
|
||||||
|
fs::write(
|
||||||
|
directory.join("manifest.json"),
|
||||||
|
"{\n \"magic\": \"PMTU\",\n \"cartridge_version\": 1,\n \"app_id\": 91,\n \"title\": \"Termination Cleanup\",\n \"app_version\": \"0.1.0\",\n \"app_mode\": \"Game\",\n \"capabilities\": []\n}\n",
|
||||||
|
)
|
||||||
|
.expect("write test manifest");
|
||||||
|
|
||||||
|
directory
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::time::{Duration, Instant};
|
|
||||||
|
|
||||||
use prometeu_bytecode::SourceSpan;
|
use prometeu_bytecode::SourceSpan;
|
||||||
use prometeu_bytecode::assembler::assemble;
|
use prometeu_bytecode::assembler::assemble;
|
||||||
@@ -107,7 +106,10 @@ fn outer_frame_limit_is_a_host_error_and_finishes_paused() {
|
|||||||
let mut host = HeadlessHost::new();
|
let mut host = HeadlessHost::new();
|
||||||
host.boot(&dir).expect("boot non-closing cartridge");
|
host.boot(&dir).expect("boot non-closing cartridge");
|
||||||
|
|
||||||
assert_eq!(host.advance_frame(), Err(HostError::LogicalFrameDidNotClose));
|
assert_eq!(
|
||||||
|
host.advance_frame(),
|
||||||
|
Err(HostError::FrameAdvanceWatchdogExpired { host_tick_limit: 100_000 })
|
||||||
|
);
|
||||||
assert_eq!(host.get_state().status, HostExecutionStatus::Paused);
|
assert_eq!(host.get_state().status, HostExecutionStatus::Paused);
|
||||||
assert!(host.get_fault().is_none());
|
assert!(host.get_fault().is_none());
|
||||||
}
|
}
|
||||||
@@ -350,11 +352,9 @@ fn end_of_rom_completes_a_logical_frame() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn three_hundred_frames_finish_without_refresh_sleep() {
|
fn three_hundred_frames_complete_without_realtime_pacing() {
|
||||||
let mut host = boot_color();
|
let mut host = boot_color();
|
||||||
let started = Instant::now();
|
|
||||||
assert_completed(host.advance_frames(300).expect("fast frames"), 300);
|
assert_completed(host.advance_frames(300).expect("fast frames"), 300);
|
||||||
assert!(started.elapsed() < Duration::from_secs(2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -255,9 +255,13 @@ wall-clock timeout.
|
|||||||
- `advance_frames(n)` is repeated `advance_frame()`. It reports the requested
|
- `advance_frames(n)` is repeated `advance_frame()`. It reports the requested
|
||||||
and completed counts plus completed-all, fault, or termination. Zero is a
|
and completed counts plus completed-all, fault, or termination. Zero is a
|
||||||
no-op; fault or termination preserves partial completed progress.
|
no-op; fault or termination preserves partial completed progress.
|
||||||
- A frame advance finishes paused. Guest faults are outcomes represented by
|
- A frame advance finishes paused and clears its host-owned debug-step request,
|
||||||
`CrashReport`; host precondition, publication, and safety-limit failures are
|
including when lifecycle termination interrupts the advance. Guest faults
|
||||||
host errors.
|
are outcomes represented by `CrashReport`; host precondition and publication
|
||||||
|
failures are host errors. A deterministic headless-host watchdog also bounds
|
||||||
|
the number of firmware ticks spent advancing one logical frame. Its limit is
|
||||||
|
tooling policy, not a guest cycle budget, runtime fault, or wall-clock
|
||||||
|
performance requirement.
|
||||||
- `capture_frame()` returns an owned clone of the canonical frame paired with
|
- `capture_frame()` returns an owned clone of the canonical frame paired with
|
||||||
the latest successful advance. The explicit `{logical_frame_index, FrameId}`
|
the latest successful advance. The explicit `{logical_frame_index, FrameId}`
|
||||||
pair is authoritative; no numeric equality or fixed offset is implied.
|
pair is authoritative; no numeric equality or fixed offset is implied.
|
||||||
|
|||||||
Reference in New Issue
Block a user