1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2024-11-10 22:59:13 +00:00

Merge pull request #120 from X0rg/master

Fix Ryzen core count calculation
This commit is contained in:
Veselin Georgiev 2018-11-04 23:25:46 +02:00 committed by GitHub
commit 84423b63b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 109 additions and 4 deletions

View file

@ -702,7 +702,7 @@ static int get_amd_multipliers(struct msr_info_t *info, uint32_t pstate, double
Note: This family contains only APUs */
err = cpu_rdmsr_range(info->handle, pstate, 8, 6, &CpuDid);
err += cpu_rdmsr_range(info->handle, pstate, 5, 0, &CpuFid);
*multiplier = (double) ((CpuFid + magic_constant) / (1ull << CpuDid)) / divisor;
*multiplier = ((double) (CpuFid + magic_constant) / (1ull << CpuDid)) / divisor;
break;
case 0x17:
/* PPR 17h, pages 30 and 138-139
@ -711,7 +711,7 @@ static int get_amd_multipliers(struct msr_info_t *info, uint32_t pstate, double
CoreCOF is (Core::X86::Msr::PStateDef[CpuFid[7:0]] / Core::X86::Msr::PStateDef[CpuDfsId]) * 200 */
err = cpu_rdmsr_range(info->handle, pstate, 13, 8, &CpuDid);
err += cpu_rdmsr_range(info->handle, pstate, 7, 0, &CpuFid);
*multiplier = (double) (CpuFid / CpuDid) * 2;
*multiplier = ((double) CpuFid / CpuDid) * 2;
break;
default:
err = 1;

View file

@ -381,8 +381,13 @@ static void decode_amd_number_of_cores(struct cpu_raw_data_t* raw, struct cpu_id
}
if (data->flags[CPU_FEATURE_HT]) {
if (num_cores > 1) {
if (data->ext_family >= 23)
num_cores /= 2; // e.g., Ryzen 7 reports 16 "real" cores, but they are really just 8.
if ((data->ext_family >= 23) && (raw->ext_cpuid[0][0] >= 30))
/* Ryzen 3 has SMT flag, but in fact cores count is equal to threads count.
Ryzen 5/7 reports twice as many "real" cores (e.g. 16 cores instead of 8) because of SMT. */
/* On PPR 17h, page 82:
CPUID_Fn8000001E_EBX [Core Identifiers][15:8] is ThreadsPerCore
ThreadsPerCore: [...] The number of threads per core is ThreadsPerCore+1 */
num_cores /= ((raw->ext_cpuid[30][1] >> 8) & 0xff) + 1;
data->num_cores = num_cores;
data->num_logical_cpus = logical_cpus;
} else {

100
tests/amd/zen/ryzen3.test Normal file
View file

@ -0,0 +1,100 @@
basic_cpuid[0]=0000000d 68747541 444d4163 69746e65
basic_cpuid[1]=00810f10 02040800 7ed8320b 178bfbff
basic_cpuid[2]=00000000 00000000 00000000 00000000
basic_cpuid[3]=00000000 00000000 00000000 00000000
basic_cpuid[4]=00000000 00000000 00000000 00000000
basic_cpuid[5]=00000040 00000040 00000003 00000011
basic_cpuid[6]=00000004 00000000 00000001 00000000
basic_cpuid[7]=00000000 209c01a9 00000000 00000000
basic_cpuid[8]=00000000 00000000 00000000 00000000
basic_cpuid[9]=00000000 00000000 00000000 00000000
basic_cpuid[10]=00000000 00000000 00000000 00000000
basic_cpuid[11]=00000000 00000000 00000000 00000000
basic_cpuid[12]=00000000 00000000 00000000 00000000
basic_cpuid[13]=00000007 00000340 00000340 00000000
basic_cpuid[14]=00000000 00000000 00000000 00000000
basic_cpuid[15]=00000000 00000000 00000000 00000000
basic_cpuid[16]=00000000 00000000 00000000 00000000
basic_cpuid[17]=00000000 00000000 00000000 00000000
basic_cpuid[18]=00000000 00000000 00000000 00000000
basic_cpuid[19]=00000000 00000000 00000000 00000000
basic_cpuid[20]=00000000 00000000 00000000 00000000
basic_cpuid[21]=00000000 00000000 00000000 00000000
basic_cpuid[22]=00000000 00000000 00000000 00000000
basic_cpuid[23]=00000000 00000000 00000000 00000000
basic_cpuid[24]=00000000 00000000 00000000 00000000
basic_cpuid[25]=00000000 00000000 00000000 00000000
basic_cpuid[26]=00000000 00000000 00000000 00000000
basic_cpuid[27]=00000000 00000000 00000000 00000000
basic_cpuid[28]=00000000 00000000 00000000 00000000
basic_cpuid[29]=00000000 00000000 00000000 00000000
basic_cpuid[30]=00000000 00000000 00000000 00000000
basic_cpuid[31]=00000000 00000000 00000000 00000000
ext_cpuid[0]=8000001f 68747541 444d4163 69746e65
ext_cpuid[1]=00810f10 20000000 35c233ff 2fd3fbff
ext_cpuid[2]=20444d41 657a7952 2033206e 30303232
ext_cpuid[3]=69772047 52206874 6f656461 6556206e
ext_cpuid[4]=47206167 68706172 20736369 00202020
ext_cpuid[5]=ff40ff40 ff40ff40 20080140 40040140
ext_cpuid[6]=26006400 66006400 02006140 00208140
ext_cpuid[7]=00000000 0000001b 00000000 00006599
ext_cpuid[8]=00003030 00001007 00004003 00000000
ext_cpuid[9]=00000000 00000000 00000000 00000000
ext_cpuid[10]=00000001 00008000 00000000 0001bcff
ext_cpuid[11]=00000000 00000000 00000000 00000000
ext_cpuid[12]=00000000 00000000 00000000 00000000
ext_cpuid[13]=00000000 00000000 00000000 00000000
ext_cpuid[14]=00000000 00000000 00000000 00000000
ext_cpuid[15]=00000000 00000000 00000000 00000000
ext_cpuid[16]=00000000 00000000 00000000 00000000
ext_cpuid[17]=00000000 00000000 00000000 00000000
ext_cpuid[18]=00000000 00000000 00000000 00000000
ext_cpuid[19]=00000000 00000000 00000000 00000000
ext_cpuid[20]=00000000 00000000 00000000 00000000
ext_cpuid[21]=00000000 00000000 00000000 00000000
ext_cpuid[22]=00000000 00000000 00000000 00000000
ext_cpuid[23]=00000000 00000000 00000000 00000000
ext_cpuid[24]=00000000 00000000 00000000 00000000
ext_cpuid[25]=f040f040 00000000 00000000 00000000
ext_cpuid[26]=00000003 00000000 00000000 00000000
ext_cpuid[27]=000003ff 00000000 00000000 00000000
ext_cpuid[28]=00000000 00000000 00000000 00000000
ext_cpuid[29]=00000121 01c0003f 0000003f 00000000
ext_cpuid[30]=00000002 00000002 00000000 00000000
ext_cpuid[31]=0000000f 0000016f 0000000f 00000000
intel_fn4[0]=00000000 00000000 00000000 00000000
intel_fn4[1]=00000000 00000000 00000000 00000000
intel_fn4[2]=00000000 00000000 00000000 00000000
intel_fn4[3]=00000000 00000000 00000000 00000000
intel_fn4[4]=00000000 00000000 00000000 00000000
intel_fn4[5]=00000000 00000000 00000000 00000000
intel_fn4[6]=00000000 00000000 00000000 00000000
intel_fn4[7]=00000000 00000000 00000000 00000000
intel_fn11[0]=00000000 00000000 00000000 00000000
intel_fn11[1]=00000000 00000000 00000000 00000000
intel_fn11[2]=00000000 00000000 00000000 00000000
intel_fn11[3]=00000000 00000000 00000000 00000000
--------------------------------------------------------------------------------
15
1
0
23
17
4
4
32
64
512
4096
-1
8
8
16
-1
64
64
64
-1
128 (authoritative)
Ryzen 3 (Raven Ridge)
fpu vme de pse tsc msr pae mce cx8 apic mtrr sep pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht pni pclmul monitor ssse3 cx16 sse4_1 sse4_2 syscall movbe popcnt aes xsave osxsave avx mmxext nx fxsr_opt rdtscp lm lahf_lm cmp_legacy svm abm misalignsse sse4a 3dnowprefetch osvw skinit wdt ts ttp tm_amd hwpstate constant_tsc fma3 f16c rdrand aperfmperf avx2 bmi1 bmi2