[libvirt] [PATCHv2 3/3] virsh: Use virNodeGetCPUMap if possible
Eric Blake
eblake at redhat.com
Thu Nov 1 03:47:29 UTC 2012
On 10/31/2012 08:58 PM, Hu Tao wrote:
> On Wed, Oct 31, 2012 at 06:20:58PM +0100, Viktor Mihajlovski wrote:
>> Modified the places where virNodeGetInfo was used for the purpose
>> of obtaining the maximum node CPU number. Transparently falling
>> back to virNodeGetInfo in case of failure.
>> Wrote utility function vshNodeGetCPUCount to compute node CPU
>> number.
>>
>> +static int
>> +vshNodeGetCPUCount(virConnectPtr conn)
>> +{
>> + int ret;
>> + virNodeInfo nodeinfo;
>> +
>> + if ((ret = virNodeGetCPUMap(conn, NULL, NULL, 0)) < 0) {
>> + /* fall back to nodeinfo */
>> + if (virNodeGetInfo(conn, &nodeinfo) == 0) {
>> + ret = VIR_NODEINFO_MAXCPUS(nodeinfo);
>> + }
>
> Isn't VIR_NODEINFO_MAXCPUS buggy? Either don't fall back to nodeinfo
> or fix it.
Hmm, and I just realized another issue - on the RHEL 5 box I tested,
there is no /sys/devices/system/cpu/possible, so virNodeGetCPUCount()
currently fails, even though virNodeGetInfo() succeeded. I'm going to
hold off pushing this series until after 1.0.0, to avoid any chance of a
last-minute unintentional regression.
You were asking about VIR_NODEINFO_MAXCPUS:
#define VIR_NODEINFO_MAXCPUS(nodeinfo)
((nodeinfo).nodes*(nodeinfo).sockets*(nodeinfo).cores*(nodeinfo).threads)
I can confirm that virNodeGetInfo misbehaves if enough trailing cpus are
offline, and therefore agree that we need to fix that API:
# virsh nodeinfo
CPU model: x86_64
CPU(s): 2
CPU frequency: 2801 MHz
CPU socket(s): 1
Core(s) per socket: 2
Thread(s) per core: 1
NUMA cell(s): 1
Memory size: 3941792 KiB
# echo 0 > /sys/devices/system/cpu/cpu1/online
# virsh nodeinfo
CPU model: x86_64
CPU(s): 1
CPU frequency: 2801 MHz
CPU socket(s): 1
Core(s) per socket: 1
Thread(s) per core: 1
NUMA cell(s): 1
Memory size: 3941792 KiB
That just changed things from 2 to 1. No fun.
--
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/20121031/b1ed8cfa/attachment-0001.sig>
More information about the libvir-list
mailing list