mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
util: hostcpu: improve CPU freq code for FreeBSD
Current implementation uses the dev.cpu.0.freq sysctl that is provided by the cpufreq(4) framework and returns the actual CPU frequency. However, there are environments where it's not available, e.g. when running nested in KVM. In this case fall back to hw.clockrate that reports CPU frequency at the boot time. Resolves (hopefully): https://bugzilla.redhat.com/show_bug.cgi?id=1369964
This commit is contained in:
parent
fb2025ede9
commit
f8435a434a
@ -994,9 +994,16 @@ virHostCPUGetInfo(virArch hostarch ATTRIBUTE_UNUSED,
|
||||
*threads = 1;
|
||||
|
||||
# ifdef __FreeBSD__
|
||||
/* dev.cpu.%d.freq reports current active CPU frequency. It is provided by
|
||||
* the cpufreq(4) framework. However, it might be disabled or no driver
|
||||
* available. In this case fallback to "hw.clockrate" which reports boot time
|
||||
* CPU frequency. */
|
||||
|
||||
if (sysctlbyname("dev.cpu.0.freq", &cpu_freq, &cpu_freq_len, NULL, 0) < 0) {
|
||||
virReportSystemError(errno, "%s", _("cannot obtain CPU freq"));
|
||||
return -1;
|
||||
if (sysctlbyname("hw.clockrate", &cpu_freq, &cpu_freq_len, NULL, 0) < 0) {
|
||||
virReportSystemError(errno, "%s", _("cannot obtain CPU freq"));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
*mhz = cpu_freq;
|
||||
|
Loading…
x
Reference in New Issue
Block a user