[libvirt] [PATCH 1/3] qemu, lxc: Change host CPU detection logic.

Eric Blake eblake at redhat.com
Wed Oct 31 00:29:55 UTC 2012


On 10/26/2012 07:19 AM, Viktor Mihajlovski wrote:
> The drivers for QEMU and LXC use virNodeGetInfo to determine the
> number of host CPUs. This approach can lead to a wrong (too small)
> number if one or more CPUs are offline.
> It is better to use virNodeGetCPUMap if available, which is the
> case here.

Hmm - ever since commit 4fbf322 added the simpler nodeGetCPUCount, that
function seems like a better option than calling virNodeGetCPUMap with
NULL arguments if all we need is the number of available (and possibly
offline) CPUs.

> 
> Signed-off-by: Viktor Mihajlovski <mihajlov at linux.vnet.ibm.com>
> ---
>  src/lxc/lxc_controller.c |  8 +++-----
>  src/qemu/qemu_driver.c   | 12 +++---------
>  src/qemu/qemu_process.c  | 10 ++++------
>  3 files changed, 10 insertions(+), 20 deletions(-)
> 
> diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
> index a41c903..e9720bc 100644
> --- a/src/lxc/lxc_controller.c
> +++ b/src/lxc/lxc_controller.c
> @@ -492,17 +492,15 @@ static int virLXCControllerSetupNUMAPolicy(virLXCControllerPtr ctrl)
>  static int virLXCControllerSetupCpuAffinity(virLXCControllerPtr ctrl)
>  {
>      int hostcpus, maxcpu = CPU_SETSIZE;
> -    virNodeInfo nodeinfo;
>      virBitmapPtr cpumap, cpumapToSet;
>  
>      VIR_DEBUG("Setting CPU affinity");
>  
> -    if (nodeGetInfo(NULL, &nodeinfo) < 0)
> -        return -1;
> -
>      /* setaffinity fails if you set bits for CPUs which
>       * aren't present, so we have to limit ourselves */
> -    hostcpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
> +    if ((hostcpus = nodeGetCPUMap(NULL, NULL, NULL, 0)) < 0)
> +        return -1;
> +
>      if (maxcpu > hostcpus)
>          maxcpu = hostcpus;

But the idea of using the simplest function possible instead of calling
nodeGetInfo() and discarding the bulk of the struct makes sense.
Looking forward to v2.

> @@ -1923,7 +1921,7 @@ qemuPrepareCpumap(struct qemud_driver *driver,
>              bool result;
>              if (virBitmapGetBit(nodemask, i, &result) < 0) {
>                  virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> -                               _("Failed to covert nodeset to cpuset"));
> +                               _("Failed to convert nodeset to cpuset"));
>                  virBitmapFree(cpumap);

I noticed this one independently, and fixed it in commit dd0a704 before
even seeing this thread from you.

-- 
Eric Blake   eblake at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 617 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20121030/79d3b3f3/attachment-0001.sig>


More information about the libvir-list mailing list