Bug 830766 - [libvirt] Can not pin vcpu to pcpu
[libvirt] Can not pin vcpu to pcpu
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: libvirt (Show other bugs)
x86_64 Linux
high Severity unspecified
: rc
: ---
Assigned To: Libvirt Maintainers
Virtualization Bugs
Depends On:
  Show dependency treegraph
Reported: 2012-06-11 07:26 EDT by Kiril Nesenko
Modified: 2012-06-15 21:28 EDT (History)
11 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2012-06-15 21:28:30 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
logs (375.61 KB, application/x-bzip)
2012-06-11 07:26 EDT, Kiril Nesenko
no flags Details

  None (edit)
Description Kiril Nesenko 2012-06-11 07:26:13 EDT
Created attachment 590903 [details]

Description of problem:
Trying to pin vcpu to pcpu and seems like the vm jumps between cpus.

From dumpxml:
    <vcpupin vcpu='0' cpuset='1'/>                 

[root@white-vdsg tmp]# ps -U qemu -o pid,psr,comm
 4040   0 qemu-kvm
[root@white-vdsg tmp]# ps -U qemu -o pid,psr,comm
 4040   2 qemu-kvm
[root@white-vdsg tmp]# ps -U qemu -o pid,psr,comm
 4040   1 qemu-kvm

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Create a vm and try to pin cpu from rhevm ui. Parameters: 0#1
Actual results:
seems like pin cpu option does not works

Expected results:
vm should be pinned to the specific cpu

Additional info:
Comment 2 Daniel Berrange 2012-06-11 08:03:39 EDT
The QEMU process run for KVM is a multi-threaded process, which has one child thread per VCPU. The main thread leader handles the event loop. The XML you have provided *only* sets affinity for the VCPU threads. The main thread is left unpinned. In other words your test case is broken.

If you want to pin *all* threads, then use  <vcpu cpuset='1'>1</vcpu>.

Alternatively if you check to check just the vCPU pinning, then you need to look at the child threads of process 4040 (ie /proc/4040/task/NNNN)
Comment 3 Laszlo Hornyak 2012-06-14 08:56:04 EDT
Ok, we do not want to pin the quemu main process to CPU, but only a thread. Is there a way to find out whuch quemu process belongs to which VM?
Comment 4 Daniel Berrange 2012-06-14 09:41:31 EDT
There is no supported API for obtaining that information, because it is not required in order to do CPU pinning with libvirt. You just use the libvirt APIs / virsh commands or XML to pin individual vCPUs.

If you just want this info, for the sake of QA testing of libvirt though, you can use the unsupported 'qemu-monitor-command' call to discover it, eg

# virsh qemu-monitor-command --hmp demovm 'info cpus' 
* CPU #0: pc=0x00000000000fefc6 (halted) thread_id=7394
  CPU #1: pc=0x00000000000ff0a2 (halted) thread_id=7398
  CPU #2: pc=0x00000000000ff0a2 (halted) thread_id=7403
  CPU #3: pc=0x00000000000ff0a2 (halted) thread_id=7412

The thread-id field is the process ID
Comment 5 Laszlo Hornyak 2012-06-15 07:34:38 EDT
Cool, thank you Daniel!
Comment 6 Laszlo Hornyak 2012-06-15 08:56:22 EDT
I checked the process over, Kiril please check your system:

- I created a Vm in oVirt with cpu pinning (0#0)
- in vdsm log, I found that the domain was created with         
                <vcpupin cpuset="0" vcpu="0"/>
- As Daniel recommended, I used `qemu-monitor-command --hmp vm1 'info cpus'` from virsh, returned
* CPU #0: pc=0x00000000000ff858 (halted) thread_id=9803
- I checked cpu-affinity with taskset
taskset -p 9803
pid 9803's current affinity mask: 1
(according to taskset's documentation, "0x00000001 is processor #0", this looks correct)

It looks all correct. Can we close this issue?
Comment 7 Dave Allan 2012-06-15 21:28:30 EDT
Kiril, this looks correct to me, so I'm closing.  Please don't hesitate to reopen if you believe it's not working correctly for you.

Note You need to log in before you can comment on or make changes to this bug.