diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 33a79b7ae93221efe3e5ff7c03702ac8af8543d0..320d8f88656cec1e2868aa589461fba441ad44c0 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -38,7 +38,7 @@ # include #endif -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__APPLE__) # include # include #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 };