@@ -853,11 +853,24 @@ int get_cacheinfo(int type, cache_info_t *cacheinfo){
853853 if (get_vendor () == VENDOR_INTEL ) {
854854 cpuid (0x80000000 , & cpuid_level , & ebx , & ecx , & edx );
855855 if (cpuid_level >= 0x80000006 ) {
856- cpuid (0x80000006 , & eax , & ebx , & ecx , & edx );
856+ if (L2 .size <=0 ){
857+ //If we didn't detect L2 correctly before,
858+ cpuid (0x80000006 , & eax , & ebx , & ecx , & edx );
859+
860+ L2 .size = BITMASK (ecx , 16 , 0xffff );
861+ L2 .associative = BITMASK (ecx , 12 , 0x0f );
862+
863+ switch (L2 .associative ){
864+ case 0x06 :
865+ L2 .associative = 8 ;
866+ break ;
867+ case 0x08 :
868+ L2 .associative = 16 ;
869+ break ;
870+ }
857871
858- L2 .size = BITMASK (ecx , 16 , 0xffff );
859- L2 .associative = BITMASK (ecx , 12 , 0x0f );
860- L2 .linesize = BITMASK (ecx , 0 , 0xff );
872+ L2 .linesize = BITMASK (ecx , 0 , 0xff );
873+ }
861874 }
862875 }
863876
@@ -916,10 +929,22 @@ int get_cacheinfo(int type, cache_info_t *cacheinfo){
916929 if (L2ITB .associative == 0xff ) L2ITB .associative = 0 ;
917930 L2ITB .linesize = BITMASK (ebx , 0 , 0xff );
918931
919- L2 .size = BITMASK (ecx , 16 , 0xffff );
920- L2 .associative = BITMASK (ecx , 12 , 0xf );
921- if (L2 .associative == 0xff ) L2 .associative = 0 ;
922- L2 .linesize = BITMASK (ecx , 0 , 0xff );
932+ if (L2 .size <= 0 ){
933+ //If we didn't detect L2 correctly before,
934+ L2 .size = BITMASK (ecx , 16 , 0xffff );
935+ L2 .associative = BITMASK (ecx , 12 , 0xf );
936+ switch (L2 .associative ){
937+ case 0x06 :
938+ L2 .associative = 8 ;
939+ break ;
940+ case 0x08 :
941+ L2 .associative = 16 ;
942+ break ;
943+ }
944+
945+ if (L2 .associative == 0xff ) L2 .associative = 0 ;
946+ L2 .linesize = BITMASK (ecx , 0 , 0xff );
947+ }
923948
924949 L3 .size = BITMASK (edx , 18 , 0x3fff ) * 512 ;
925950 L3 .associative = BITMASK (edx , 12 , 0xf );
0 commit comments