@@ -272,11 +272,14 @@ pub fn interpret_command(command: &str) {
272272 "bench" => {
273273 use crate :: benchmark:: Benchmark ;
274274 use crate :: provenance:: { provenance_hash, constant_time_eq} ;
275+ use crate :: pmc;
275276 use core:: hint:: black_box;
276277
277278 println ! ( "=== Axiom OS Benchmark Suite ===" ) ;
278- println ! ( "[bench] all cycle counts are RDTSC hardware measurements" ) ;
279- println ! ( "[bench] black_box used throughout to prevent dead-code elimination" ) ;
279+ println ! ( "[bench] RDTSC cycle counts; black_box throughout to block dead-code elimination" ) ;
280+ println ! ( "[bench] LLC-miss counts are valid ONLY under KVM (-cpu host,pmu=on) or bare metal;" ) ;
281+ println ! ( "[bench] under pure QEMU/TCG they are meaningless and should not be reported." ) ;
282+ pmc:: init_cache_miss_counter ( ) ;
280283 println ! ( "" ) ;
281284
282285 println ! ( "--- BLAKE3 hash throughput ---" ) ;
@@ -312,21 +315,76 @@ pub fn interpret_command(command: &str) {
312315 }
313316 println ! ( "" ) ;
314317
315- println ! ( "--- VFS in-memory read+verify ---" ) ;
318+ println ! ( "--- read+verify: whole-file vs block-level (proportional access) ---" ) ;
319+ println ! ( "[bench] setup (alloc + insert) is OUTSIDE the timed loop; only read+verify is timed" ) ;
316320 {
317- let mut b = Benchmark :: new ( "vfs_read_verify" ) ;
318- b. run ( 100 , || {
321+ let sizes: [ usize ; 6 ] = [ 4096 , 16384 , 65536 , 262144 , 1048576 , 4194304 ] ;
322+ for & sz in sizes. iter ( ) {
323+ // --- setup once, OUTSIDE the timed region ---
319324 let mut v = crate :: vfs:: VirtualFS :: new ( ) ;
320- v. create ( "t" , b"test data" ) ;
321- let r = v. read ( "t" ) ;
322- let _ = black_box ( r) ;
323- } ) ;
324- b. report ( ) ;
325+ let payload = alloc:: vec![ 0xABu8 ; sz] ;
326+ v. create ( "bench" , & payload) ;
327+ let nblocks = ( sz + crate :: vfs:: BLOCK_SIZE - 1 ) / crate :: vfs:: BLOCK_SIZE ;
328+
329+ // baseline: rehash the WHOLE file each read
330+ let mut bw = Benchmark :: new ( "wholefile_verify" ) ;
331+ bw. run ( 100 , || {
332+ let r = v. read ( black_box ( "bench" ) ) ;
333+ let _ = black_box ( r) ;
334+ } ) ;
335+
336+ // block-level: verify ONLY the one 4 KiB block read
337+ let mut bb = Benchmark :: new ( "block_verify_one_4k" ) ;
338+ bb. run ( 100 , || {
339+ let r = v. read_range ( black_box ( "bench" ) , 0 , 4096 ) ;
340+ let _ = black_box ( r) ;
341+ } ) ;
342+
343+ // single-shot cycles + LLC misses for each path (KVM/bare-metal only)
344+ let ( _, wmiss, wcyc) = pmc:: measure ( || { let r = v. read ( black_box ( "bench" ) ) ; black_box ( r) ; } ) ;
345+ let ( _, bmiss, bcyc) = pmc:: measure ( || { let r = v. read_range ( black_box ( "bench" ) , 0 , 4096 ) ; black_box ( r) ; } ) ;
346+
347+ println ! ( "[size={} bytes, {} blocks]" , sz, nblocks) ;
348+ bw. report ( ) ;
349+ bb. report ( ) ;
350+ println ! ( "[pmc] wholefile: {} cyc, {} LLC-miss | block: {} cyc, {} LLC-miss" ,
351+ wcyc, wmiss, bcyc, bmiss) ;
352+ }
353+ println ! ( "[bench] expected shape: wholefile grows ~linearly with size; block stays ~flat" ) ;
325354 }
326355 println ! ( "" ) ;
327356
328- println ! ( "--- FAT32 persistent read+verify (provenance-enforced path) ---" ) ;
357+ println ! ( "--- write path: one block write (+ lazy Merkle root) vs full-file rehash ---" ) ;
329358 {
359+ let sz = 1_048_576usize ; // 1 MiB = 256 blocks
360+ let mut v = crate :: vfs:: VirtualFS :: new ( ) ;
361+ let payload = alloc:: vec![ 0xABu8 ; sz] ;
362+ v. create ( "w" , & payload) ;
363+ let patch = alloc:: vec![ 0x5Au8 ; crate :: vfs:: BLOCK_SIZE ] ;
364+
365+ // cheap path: update one leaf + recompute the root lazily from leaves
366+ let mut bwrite = Benchmark :: new ( "block_write_plus_lazy_root_1MiB" ) ;
367+ bwrite. run ( 100 , || {
368+ let _ = v. write_block ( black_box ( "w" ) , 0 , black_box ( & patch) ) ;
369+ let _ = black_box ( v. merkle_root ( black_box ( "w" ) ) ) ;
370+ } ) ;
371+ bwrite. report ( ) ;
372+
373+ // baseline: what a full-file rehash on every write would cost
374+ let slice = & payload[ ..] ;
375+ let mut brehash = Benchmark :: new ( "fullfile_rehash_1MiB" ) ;
376+ brehash. run ( 100 , || {
377+ let h = provenance_hash ( black_box ( slice) ) ;
378+ let _ = black_box ( h) ;
379+ } ) ;
380+ brehash. report ( ) ;
381+ println ! ( "[bench] note: root recompute is from-leaves (O(blocks)), still far below O(filesize) rehash" ) ;
382+ }
383+ println ! ( "" ) ;
384+
385+ println ! ( "--- FAT32 persistent read+verify (skipped by default — it WRITES to disk) ---" ) ;
386+ println ! ( "[bench] run 'bench disk' to include it, and ONLY against a throwaway disk image" ) ;
387+ if arg. trim ( ) == "disk" {
330388 let payload = alloc:: vec![ 0xCDu8 ; 512 ] ;
331389 FAT32 . lock ( ) . write_file ( "bench.dat" , & payload) ;
332390 let mut b = Benchmark :: new ( "fat32_read_verify_512B" ) ;
@@ -335,6 +393,8 @@ pub fn interpret_command(command: &str) {
335393 let _ = black_box ( r) ;
336394 } ) ;
337395 b. report ( ) ;
396+ } else {
397+ println ! ( "[bench] FAT32 path skipped (no disk writes performed)" ) ;
338398 }
339399 println ! ( "" ) ;
340400
@@ -636,4 +696,4 @@ pub fn interpret_command(command: &str) {
636696fn shell_process ( ) -> ! {
637697 crate :: println!( "[process] spawned from shell - running" ) ;
638698 loop { }
639- }
699+ }
0 commit comments