1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2024-12-16 16:35:45 +00:00

Fix issue #50: On some virtual machines, library returns zero number of cores.

As proposed in the issue discussion.
This commit is contained in:
Veselin Georgiev 2016-07-18 09:07:51 +03:00
parent 2a11739c10
commit e0505af4f6

View file

@ -558,8 +558,12 @@ static int decode_intel_extended_topology(struct cpu_raw_data_t* raw,
}
}
if (num_smt == -1 || num_core == -1) return 0;
data->num_cores = num_core / num_smt;
data->num_logical_cpus = num_core;
data->num_cores = num_core / num_smt;
// make sure num_cores is at least 1. In VMs, the CPUID instruction
// is rigged and may give nonsensical results, but we should at least
// avoid outputs like data->num_cores == 0.
if (data->num_cores <= 0) data->num_cores = 1;
return 1;
}