mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-26 18:41:17 +00:00
util: Fix getting CPU frequency on Apple Silicon
The hw.cpufrequency sysctl, which we use to obtain the CPU frequency on macOS, is not available when running on Apple Silicon, and as a consequence we currently report an error whenever such information is requested. The virNodeInfo.mhz field, where the CPU frequency gets stored, is documented as being zero when the information could not be obtained, and we already do that for Linux on aarch64. Extend this behavior to macOS on Apple Silicon. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
2a273072b6
commit
85064aae64
@ -928,8 +928,14 @@ virHostCPUGetInfo(virArch hostarch G_GNUC_UNUSED,
|
|||||||
*mhz = cpu_freq;
|
*mhz = cpu_freq;
|
||||||
# else
|
# else
|
||||||
if (sysctlbyname("hw.cpufrequency", &cpu_freq, &cpu_freq_len, NULL, 0) < 0) {
|
if (sysctlbyname("hw.cpufrequency", &cpu_freq, &cpu_freq_len, NULL, 0) < 0) {
|
||||||
virReportSystemError(errno, "%s", _("cannot obtain CPU freq"));
|
if (errno == ENOENT) {
|
||||||
return -1;
|
/* The hw.cpufrequency sysctl is not implemented on Apple Silicon.
|
||||||
|
* In that case, we report 0 instead of erroring out */
|
||||||
|
cpu_freq = 0;
|
||||||
|
} else {
|
||||||
|
virReportSystemError(errno, "%s", _("cannot obtain CPU freq"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*mhz = cpu_freq / 1000000;
|
*mhz = cpu_freq / 1000000;
|
||||||
|
Loading…
Reference in New Issue
Block a user