]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
nodeinfo: make freebsdNodeGetCPUCount work on Mac OS X
authorRyota Ozaki <ozaki.ryota@gmail.com>
Sat, 5 Oct 2013 05:56:37 +0000 (14:56 +0900)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 7 Oct 2013 08:28:18 +0000 (10:28 +0200)
This fixes the following error:
  error : nodeGetInfo:933 : this function is not supported
  by the connection driver: node info not implemented on this platform

The freebsdNodeGetCPUCount was renamed to appleFreebsdNodeGetCPUCount
in order to make more visible the fact, that it works on Mac OS X too.

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@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/nodeinfo.c

index 33a79b7ae93221efe3e5ff7c03702ac8af8543d0..320d8f88656cec1e2868aa589461fba441ad44c0 100644 (file)
@@ -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,9 +58,9 @@
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__APPLE__)
 static int
-freebsdNodeGetCPUCount(void)
+appleFreebsdNodeGetCPUCount(void)
 {
     int ncpu_mib[2] = { CTL_HW, HW_NCPU };
     unsigned long ncpu;
@@ -882,13 +882,13 @@ cleanup:
     VIR_FORCE_FCLOSE(cpuinfo);
     return ret;
     }
-#elif defined(__FreeBSD__)
+#elif defined(__FreeBSD__) || defined(__APPLE__)
     {
     nodeinfo->nodes = 1;
     nodeinfo->sockets = 1;
     nodeinfo->threads = 1;
 
-    nodeinfo->cpus = freebsdNodeGetCPUCount();
+    nodeinfo->cpus = appleFreebsdNodeGetCPUCount();
     if (nodeinfo->cpus == -1)
         return -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 };