This fixes the following error:
error : nodeGetInfo:933 : this function is not supported
by the connection driver: node info not implemented on this platform
Mac OS X can use sysctlbyname as same as FreeBSD to get the CPU
frequency. However, the MIB style name is different from FreeBSD's.
And the unit of the return frequency is also different.
Signed-off-by: Ryota Ozaki <ozaki.ryota(a)gmail.com>
---
src/nodeinfo.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 33a79b7..0c92cfa 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -38,7 +38,7 @@
# include <numa.h>
#endif
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__APPLE__)
# include <sys/types.h>
# include <sys/sysctl.h>
#endif
@@ -58,7 +58,7 @@
#define VIR_FROM_THIS VIR_FROM_NONE
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__APPLE__)
static int
freebsdNodeGetCPUCount(void)
{
@@ -882,7 +882,7 @@ cleanup:
VIR_FORCE_FCLOSE(cpuinfo);
return ret;
}
-#elif defined(__FreeBSD__)
+#elif defined(__FreeBSD__) || defined(__APPLE__)
{
nodeinfo->nodes = 1;
nodeinfo->sockets = 1;
@@ -897,12 +897,21 @@ cleanup:
unsigned long cpu_freq;
size_t cpu_freq_len = sizeof(cpu_freq);
+#ifdef __FreeBSD__
if (sysctlbyname("dev.cpu.0.freq", &cpu_freq, &cpu_freq_len, NULL,
0) < 0) {
virReportSystemError(errno, "%s", _("cannot obtain CPU
freq"));
return -1;
}
nodeinfo->mhz = cpu_freq;
+#else
+ if (sysctlbyname("hw.cpufrequency", &cpu_freq, &cpu_freq_len, NULL,
0) < 0) {
+ virReportSystemError(errno, "%s", _("cannot obtain CPU
freq"));
+ return -1;
+ }
+
+ nodeinfo->mhz = cpu_freq / 1000000;
+#endif
/* get memory information */
int mib[2] = { CTL_HW, HW_PHYSMEM };
--
1.8.4