@@ -1024,11 +1024,31 @@ static void print_mmu_cache_stats(vm_t *vm)
10241024 fprintf (stderr , "\n=== MMU Cache Statistics ===\n" );
10251025 for (uint32_t i = 0 ; i < vm -> n_hart ; i ++ ) {
10261026 hart_t * hart = vm -> hart [i ];
1027- uint64_t fetch_hits = 0 , fetch_misses = 0 ;
1028- fetch_hits = hart -> cache_fetch [1 ].hits + hart -> cache_fetch [2 ].hits ;
1029- fetch_misses =
1030- hart -> cache_fetch [1 ].misses + hart -> cache_fetch [2 ].misses ;
1031- uint64_t fetch_total = fetch_hits + fetch_misses ;
1027+
1028+ /* Combine 2-entry tlb statistics */
1029+ uint64_t fetch_hits_tlb = 0 , fetch_misses_tlb = 0 ;
1030+ fetch_hits_tlb =
1031+ hart -> cache_fetch [0 ].tlb_hits + hart -> cache_fetch [1 ].tlb_hits ;
1032+ fetch_misses_tlb =
1033+ hart -> cache_fetch [0 ].tlb_misses + hart -> cache_fetch [1 ].tlb_misses ;
1034+ uint64_t tlb_total = fetch_hits_tlb + fetch_misses_tlb ;
1035+
1036+ /* Combine icache statistics */
1037+ uint64_t fetch_hits_icache = 0 , fetch_misses_icache = 0 ;
1038+ fetch_hits_icache =
1039+ hart -> cache_fetch [0 ].icache_hits + hart -> cache_fetch [1 ].icache_hits ;
1040+ fetch_misses_icache = hart -> cache_fetch [0 ].icache_misses +
1041+ hart -> cache_fetch [1 ].icache_misses ;
1042+
1043+ /* Combine victim cache statistics */
1044+ uint64_t fetch_hits_vcache = 0 , fetch_misses_vcache = 0 ;
1045+ fetch_hits_vcache =
1046+ hart -> cache_fetch [0 ].vcache_hits + hart -> cache_fetch [1 ].vcache_hits ;
1047+ fetch_misses_vcache = hart -> cache_fetch [0 ].vcache_misses +
1048+ hart -> cache_fetch [1 ].vcache_misses ;
1049+
1050+ uint64_t access_total =
1051+ hart -> cache_fetch [0 ].total_fetch + hart -> cache_fetch [1 ].total_fetch ;
10321052
10331053 /* Combine 8-set × 2-way load cache statistics */
10341054 uint64_t load_hits = 0 , load_misses = 0 ;
@@ -1050,14 +1070,37 @@ static void print_mmu_cache_stats(vm_t *vm)
10501070 }
10511071 uint64_t store_total = store_hits + store_misses ;
10521072
1053- fprintf (stderr , "\nHart %u:\n" , i );
1054- fprintf (stderr , " Fetch: %12llu hits, %12llu misses" , fetch_hits ,
1055- fetch_misses );
1056- if (fetch_total > 0 )
1057- fprintf (stderr , " (%.2f%% hit rate)" ,
1058- 100.0 * fetch_hits / fetch_total );
1059- fprintf (stderr , "\n" );
10601073
1074+ fprintf (stderr , "\n=== Introduction Cache Statistics ===\n" );
1075+ fprintf (stderr , " Total access: %12llu\n" , access_total );
1076+ if (access_total > 0 ) {
1077+ fprintf (stderr , " Icache hits: %12llu (%.2f%%)\n" ,
1078+ fetch_hits_icache ,
1079+ (fetch_hits_icache * 100.0 ) / access_total );
1080+
1081+ fprintf (stderr , " Icache misses: %12llu (%.2f%%)\n" ,
1082+ fetch_misses_icache ,
1083+ (fetch_misses_icache * 100.0 ) / access_total );
1084+ }
1085+ if (access_total > 0 && fetch_misses_icache > 0 ) {
1086+ fprintf (stderr ,
1087+ " ├ Vcache hits: %8llu (%.2f%% of Icache misses)\n" ,
1088+ fetch_hits_vcache ,
1089+ (fetch_hits_vcache * 100.0 ) / fetch_misses_icache ,
1090+ (fetch_hits_vcache * 100.0 ) / access_total );
1091+ fprintf (stderr ,
1092+ " └ Vcache misses: %8llu (%.2f%% of Icache misses)\n" ,
1093+ fetch_misses_vcache ,
1094+ (fetch_misses_vcache * 100.0 ) / fetch_misses_icache ,
1095+ (fetch_misses_vcache * 100.0 ) / access_total );
1096+ }
1097+ if (tlb_total > 0 ) {
1098+ fprintf (stderr , " ├ TLB hits: %4llu (%.2f%%)\n" ,
1099+ fetch_hits_tlb , (fetch_hits_tlb * 100.0 ) / (tlb_total ));
1100+ fprintf (stderr , " └ TLB misses: %4llu (%.2f%%)\n" ,
1101+ fetch_misses_tlb , (fetch_misses_tlb * 100.0 ) / (tlb_total ));
1102+ }
1103+ fprintf (stderr , "\n=== Data Cache Statistics ===\n" );
10611104 fprintf (stderr , " Load: %12llu hits, %12llu misses (8x2)" , load_hits ,
10621105 load_misses );
10631106 if (load_total > 0 )
0 commit comments