[libvirt] [PATCH 2/2] nodeinfo: make freebsdNodeGetCPUCount work on Mac OS X
Michal Privoznik
mprivozn at redhat.com
Mon Oct 7 08:33:48 UTC 2013
On 05.10.2013 07:56, Ryota Ozaki wrote:
> 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 at 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)
This function is now called on apple too. I'm renaming it to
appleFreebsdNodeGetCPUCount().
> {
> @@ -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
Again, indentation is off.
>
> /* get memory information */
> int mib[2] = { CTL_HW, HW_PHYSMEM };
>
ACKed, fixed and pushed.
Michal
More information about the libvir-list
mailing list