On 2012年10月10日 23:18, Viktor Mihajlovski wrote:
Hi,
in order to use the APIs listed below it is necessary for a client to
know the maximum number of node CPUs which is passed via the maplen
argument.
virDomainGetEmulatorPinInfo
virDomainGetVcpuPinInfo
virDomainGetVcpus
virDomainPinEmulator
virDomainPinVcpu
virDomainPinVcpuFlags
The current approach uses virNodeGetInfo to determine the maximum CPU
number. This can lead to incorrect results if not all node CPUs are
online. The maximum CPU number should always be the number of CPUs
present on the host, regardless of their online/offline state.
Agree.
It doesn't make sense to show online CPU number on PowerPC either.
It's better to show the CPU number of online and offline.
When SMT is disabled on PowerPC, node info is not right either.
And there is no relationship as x86 as the following:
nodeinfo->nodes *
nodeinfo->sockets *
nodeinfo->cores *
nodeinfo->threads = nodeinfo->cpus + offline
It should be for PowerPC :
nodeinfo->sockets *
nodeinfo->cores *
nodeinfo->threads = nodeinfo->cpus + offline
The following example illustrates the issue:
Host has 3 logical CPUs, 1 socket, 3 cores, 1 thread.
Guest has 1 virtual CPU and is started while all 3 host CPUs are
online.
$ virsh vcpuinfo guest
VCPU: 0
CPU: 0
State: running
CPU time: 35.4s
CPU Affinity: yyy
$ echo 0 > /sys/devices/system/cpu/cpu1/online
$ virsh vcpuinfo guest
VCPU: 0
CPU: 0
State: running
CPU time: 35.5s
CPU Affinity: y-
The correct display for CPU affinity would have been y-y, as the guest
continues to use CPUs 0 and 2.
This is not a display problem only, because it is also not possible to
explicitly pin the virtual CPU to host CPUs 0 and 2, due to the
truncated CPU mask.
How is CPU mask truncated? CPU 2 is still online, right?
PROPOSAL:
To help solve the issue above I suggest two new public API functions:
int
virNodeGetCpuNum(virConnectPtr conn);
returning the number of present CPUs on the host or -1 upon failure
and
int
virNodeGetCpuMap(virConnectPtr conn, unsigned char * cpumap, int maplen);
returning the number of present CPUs or -1 on failure and storing a
bit map of real CPUs as described in virDomainPinVcpu in cpumap. The
bits in the bit map are set to 1 for online CPUs and set to 0 for
offline CPUs.
Implementation is facilitated by the function nodeGetCPUmap in
nodeinfo.c.
Clients can use virNodeGetCpuNum to properly determine the maximum
number of node CPUs and the online/offline information.
Thanks for your comments.