diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d518bd..c7eb011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ remains unsupported. - Rewrote the README around the six development phases and the first-launchable-application target (#311), with colour-coded Mermaid diagrams (system flow, milestone roadmap, CPU, runtime-service and shader-form charts built from the generated registries), badges, a repository overview, a contributing section and corrected texture-sampling wording. The older X1–X25 capability map is kept in a collapsible section. The diagrams were not render-tested locally. - Added a fast "Repository hygiene" check (`.github/workflows/hygiene.yml`, `scripts/audit/docs_hygiene.py`). It runs on Ubuntu without a Rust toolchain or network access and fails only on merge-conflict markers, broken relative Markdown links and invalid workflow YAML in tracked files. A separate advisory step warns, without failing, when source or script changes have no changelog entry. A local run over the 626 tracked files found no problems, and planted failures of each kind were caught; it has not yet run on GitHub. - Documented the proposed guest AVX/AVX2 state and decoding contract and specified an original integer fixture with known results and fault controls (#299). +- `betterxen-hybrid host`, `receipt`, `bench` and every `run` record now include the GPU wired-memory sysctls `iogpu.wired_limit_mb` and `iogpu.wired_lwm_mb` as raw integers with their source command, or `null` when a key is absent (#386). They are read only and never set. `0` is recorded as observed, because Apple does not document what it means. Unit tests inject the values; an Apple M5 with macOS 27.2.1 reported `0` for both keys. Not run under CrossOver. ### Removed - Removed the "PR template" check (`.github/workflows/pr-template.yml`, `scripts/pr_template_check.py` and its tests) and its CI test step. Also removed `.github/PULL_REQUEST_TEMPLATE.md`. Pull request descriptions are no longer validated or pre-filled; CONTRIBUTING.md still asks for the same information and the claim-first rule still applies. diff --git a/crates/hybrid/src/host.rs b/crates/hybrid/src/host.rs index d2678a6..d8327ea 100644 --- a/crates/hybrid/src/host.rs +++ b/crates/hybrid/src/host.rs @@ -20,6 +20,7 @@ pub struct HostReceipt { pub gpu_name: Option, pub gpu_cores: Option, pub metal_support: Option, + pub gpu_wired: GpuWired, pub host_arch_of_this_binary: &'static str, } @@ -27,6 +28,48 @@ fn sysctl(name: &str) -> Option { run("/usr/sbin/sysctl", &["-n", name]) } +/// GPU wired-memory sysctls (issue #386), recorded as the raw integers `sysctl -n` prints. +/// +/// Read only: nothing in BetterXen writes these keys. `None` means the key is absent (the +/// command failed) or its output is not an unsigned integer. A value of 0 was observed on an +/// M4 and an M5; Apple does not document what 0 means in anything reviewed for #386, so it is +/// reported as observed and never interpreted (for example as "system default" or "no limit"). +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] +pub struct GpuWired { + /// `iogpu.wired_limit_mb`. + pub limit_mb: Option, + /// `iogpu.wired_lwm_mb`. + pub lwm_mb: Option, +} + +pub const GPU_WIRED_SOURCE: &str = "sysctl -n iogpu.wired_limit_mb, iogpu.wired_lwm_mb (read-only; raw values, meaning of 0 undocumented)"; + +/// Read the GPU wired-memory keys through `read`, which returns a key's trimmed output or +/// `None` when the key cannot be read. Injected so tests do not depend on this Mac. +pub fn gpu_wired_with(read: impl Fn(&str) -> Option) -> GpuWired { + let num = |key: &str| read(key).and_then(|v| v.trim().parse::().ok()); + GpuWired { + limit_mb: num("iogpu.wired_limit_mb"), + lwm_mb: num("iogpu.wired_lwm_mb"), + } +} + +pub fn gpu_wired() -> GpuWired { + gpu_wired_with(sysctl) +} + +impl GpuWired { + /// The record fields shared by the host receipt and every run record. + pub fn json_fields(&self) -> Vec<(&'static str, Json)> { + let n = |v: Option| v.map_or(Json::Null, |x| Json::Num(x as f64)); + vec![ + ("gpu_wired_limit_mb", n(self.limit_mb)), + ("gpu_wired_lwm_mb", n(self.lwm_mb)), + ("gpu_wired_source", Json::str(GPU_WIRED_SOURCE)), + ] + } +} + pub fn collect() -> HostReceipt { let gpu = run( "/usr/sbin/system_profiler", @@ -50,6 +93,7 @@ pub fn collect() -> HostReceipt { gpu_name: gpu.as_ref().map(|g| g.0.clone()), gpu_cores: gpu.as_ref().and_then(|g| g.1.clone()), metal_support: gpu.as_ref().and_then(|g| g.2.clone()), + gpu_wired: gpu_wired(), host_arch_of_this_binary: std::env::consts::ARCH, } } @@ -78,7 +122,7 @@ fn string_value(json: &str, key: &str) -> Option { impl HostReceipt { pub fn to_json(&self) -> Json { let n = |v: Option| v.map_or(Json::Null, |x| Json::Num(x as f64)); - Json::obj(vec![ + let mut fields = vec![ ("macos_version", Json::opt_str(self.macos_version.clone())), ("macos_build", Json::opt_str(self.macos_build.clone())), ("chip", Json::opt_str(self.chip.clone())), @@ -101,11 +145,13 @@ impl HostReceipt { ("gpu_name", Json::opt_str(self.gpu_name.clone())), ("gpu_cores", Json::opt_str(self.gpu_cores.clone())), ("metal_support", Json::opt_str(self.metal_support.clone())), - ( - "receipt_binary_arch", - Json::str(self.host_arch_of_this_binary), - ), - ]) + ]; + fields.extend(self.gpu_wired.json_fields()); + fields.push(( + "receipt_binary_arch", + Json::str(self.host_arch_of_this_binary), + )); + Json::obj(fields) } } @@ -128,6 +174,48 @@ mod tests { assert!(parse_gpu("{}").is_none()); } + fn reader<'a>(pairs: &'a [(&'a str, &'a str)]) -> impl Fn(&str) -> Option + 'a { + move |key| { + pairs + .iter() + .find(|(k, _)| *k == key) + .map(|(_, v)| v.to_string()) + } + } + + #[test] + fn gpu_wired_values_are_reported_raw() { + let w = gpu_wired_with(reader(&[ + ("iogpu.wired_limit_mb", "24576"), + ("iogpu.wired_lwm_mb", "0"), + ])); + assert_eq!(w.limit_mb, Some(24576)); + // 0 is a value like any other, not "absent". + assert_eq!(w.lwm_mb, Some(0)); + } + + #[test] + fn missing_or_unparsable_gpu_wired_keys_are_null() { + let w = gpu_wired_with(reader(&[("iogpu.wired_limit_mb", "unlimited")])); + assert_eq!(w, GpuWired::default()); + let j = Json::obj(w.json_fields()).render(); + assert!(j.contains("\"gpu_wired_limit_mb\": null"), "{j}"); + assert!(j.contains("\"gpu_wired_lwm_mb\": null"), "{j}"); + assert!(j.contains("\"gpu_wired_source\": \"sysctl -n"), "{j}"); + } + + #[test] + fn receipt_carries_gpu_wired_fields() { + let mut r = collect(); + r.gpu_wired = GpuWired { + limit_mb: Some(0), + lwm_mb: None, + }; + let j = r.to_json().render(); + assert!(j.contains("\"gpu_wired_limit_mb\": 0"), "{j}"); + assert!(j.contains("\"gpu_wired_lwm_mb\": null"), "{j}"); + } + #[test] fn collect_runs_on_this_host() { let r = collect(); diff --git a/crates/hybrid/src/run.rs b/crates/hybrid/src/run.rs index a65ac5d..1a8a6d4 100644 --- a/crates/hybrid/src/run.rs +++ b/crates/hybrid/src/run.rs @@ -164,6 +164,8 @@ pub fn execute(cfg: &RunConfig, crossover_build: Option) -> RunRecord { let t_wall = SystemTime::now() .duration_since(UNIX_EPOCH) .map_or(0, |d| d.as_secs()); + // Read before the launch so the record holds the ceiling this run started under (#386). + let gpu_wired = crate::host::gpu_wired(); let _ = std::fs::create_dir_all(&cfg.work_dir); let out_path = cfg .work_dir @@ -290,7 +292,7 @@ pub fn execute(cfg: &RunConfig, crossover_build: Option) -> RunRecord { }; Json::Arr(keep.iter().map(|l| Json::str(*l)).collect()) }; - result.json = Json::obj(vec![ + let mut fields = vec![ ("schema", Json::str("betterxen-hybrid-run/0")), ("unix_time", Json::Num(t_wall as f64)), ("crossover_build", Json::opt_str(crossover_build)), @@ -349,7 +351,9 @@ pub fn execute(cfg: &RunConfig, crossover_build: Option) -> RunRecord { ("frame_stats", frame_stats.unwrap_or(Json::Null)), ("stdout_tail", tail(&result.stdout)), ("stderr_tail", tail(&result.stderr)), - ]); + ]; + fields.extend(gpu_wired.json_fields()); + result.json = Json::obj(fields); let _ = std::fs::remove_file(&out_path); let _ = std::fs::remove_file(&err_path); result @@ -452,6 +456,8 @@ mod tests { !j.contains("frame_ms 10"), "frame lines belong in frame_stats, not the tail" ); + assert!(j.contains("\"gpu_wired_limit_mb\""), "{j}"); + assert!(j.contains("\"gpu_wired_source\""), "{j}"); } #[test] diff --git a/docs/research/upstream-integration-audit.md b/docs/research/upstream-integration-audit.md index efe9d55..7b25899 100644 --- a/docs/research/upstream-integration-audit.md +++ b/docs/research/upstream-integration-audit.md @@ -47,7 +47,7 @@ New crate `crates/hybrid` (`betterxen-hybrid`, no third-party dependencies, nati | Command | Purpose | Issue | Validated | | --- | --- | --- | --- | -| `host` | macOS version and build, chip, memory, core split, whether an x86_64 binary executes (Rosetta), GPU and Metal family from `system_profiler` | #353 | Run on the M4 reference machine; unit tests parse a GPU fixture | +| `host` | macOS version and build, chip, memory, core split, whether an x86_64 binary executes (Rosetta), GPU and Metal family from `system_profiler`, and the GPU wired-memory sysctls `iogpu.wired_limit_mb` and `iogpu.wired_lwm_mb` as raw integers (also written into every run record; read-only; `null` when a key is absent; Apple does not document what `0` means, so it is never interpreted) | #353, #386 | Run on the M4 reference machine; unit tests parse a GPU fixture and inject sysctl values. Apple M5, 32 GiB, macOS 27.2.1 (26B131) reported `0` and `0` for the two keys (2026-11-25), as did the M4 for `iogpu.wired_limit_mb` | | `crossover` | Finds `CrossOver.app` in standard locations and by Spotlight bundle identifier; reads version, build, executable architectures, minimum macOS, and the documented `BottleDir` and `ManagedBottleDirs` preferences | #350, #355 | Unit test on a **synthetic** bundle only. On the reference machine it reports `installed: false`. It has never inspected a real CrossOver | | `toolchain` | Lists mingw-w64 and llvm-mingw cross-compilers on `PATH` with version and target | #364 | Stub-compiler unit test; on the reference machine it found Homebrew `x86_64-w64-mingw32-gcc` 16.2.0 and `i686-w64-mingw32-gcc`. No ARM64 Windows target is installed. No program was compiled or run | | `frames ` | Frame-time statistics: mean, FPS, nearest-rank p50/p95/p99/p99.9, 1 % and 0.1 % lows, stutter count | #145 | Hand-derived known-answer tests, rejection of non-positive or non-finite intervals |