Bug 1618688

Summary: pidstat shows wrong CPU for pinned threads
Product: Red Hat Enterprise Linux 7 Reporter: Julio Entrena Perez <jentrena>
Component: sysstatAssignee: Michal Sekletar <msekleta>
Status: CLOSED ERRATA QA Contact: Radka Brychtova <rskvaril>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.5CC: jheger, kwalker, msekleta, pdwyer, rskvaril
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-08-06 13:16:08 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1630908, 1630917, 1643104    

Description Julio Entrena Perez 2018-08-17 10:42:50 UTC
Description of problem:
pidstat reports the wrong CPU for a pinned qemu-kvm thread

Version-Release number of selected component (if applicable):
sysstat-10.1.5-13.el7.x86_64

How reproducible:
Always

Steps to Reproduce:
1. Create a virtual machine and pin a VCPU thread to a CPU.
2. Run a CPU intensive workload in the VM (e.g. "openssl speed")
3.

Actual results:
pidstat reports the wrong CPU for the pinned VCPU qemu-kvm thread

Expected results:
pidstat reports the correct CPU for the pinned VCPU qemu-kvm thread

Additional info:

Example: a single VCPU VM has its VCPU pinned to CPU 0 in the host using
- "0#1" for RHV CPU pinning topology 
or
- libvirt:
  <cputune>
    <vcpupin vcpu='0' cpuset='1'/>
  </cputune>

# virsh -r vcpuinfo rhel7a
VCPU:           0
CPU:            1
State:          running
CPU time:       289.8s
CPU Affinity:   -y

# virsh -r vcpupin rhel7a
VCPU: CPU Affinity
----------------------------------
   0: 1
   1: 0-1
   2: 0-1
   3: 0-1

Running "top -H" and adding the P (processor) column shows that the VCPU thread is running in physical CPU 1:

top - 16:11:31 up 16 days, 21:39,  1 user,  load average: 1.08, 0.75, 0.39
Threads: 359 total,   3 running, 356 sleeping,   0 stopped,   0 zombie
%Cpu(s): 50.2 us,  0.2 sy,  0.0 ni, 49.6 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  7881488 total,  1840740 free,  1300100 used,  4740648 buff/cache
KiB Swap:  1023996 total,  1023996 free,        0 used.  6201844 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ P COMMAND                                                                                                        
19762 qemu      20   0 2796560 835020  13424 R 99.3 10.6   6:29.88 1 CPU 0/KVM
 1833 root      20   0 1546680  45292  11412 S  0.3  0.6  29:46.39 0 python                   

Taskset confirms this thread is bound to CPU 1:

# taskset -p 19762
pid 19762's current affinity mask: 2

But pidstat insists on reporting the VCPU thread as running on CPU 0:

# pidstat -ut -p 19753
Linux 3.10.0-693.21.1.el7.x86_64 (rhevh3-375.usersys.redhat.com) 	13/08/18 	_x86_64_	(2 CPU)

16:06:18      UID      TGID       TID    %usr %system  %guest    %CPU   CPU  Command
16:06:18      107     19753         -  100.00    0.00  100.00    0.01     0  qemu-kvm
16:06:18      107         -     19753    0.00    0.00    0.00    0.00     0  |__qemu-kvm
16:06:18      107         -     19757    0.00    0.00    0.00    0.00     0  |__qemu-kvm
16:06:18      107         -     19758    0.00    0.00    0.00    0.00     0  |__IO
16:06:18      107         -     19762    0.00    0.00    0.00    0.00     0  |__CPU
16:06:18      107         -     19765    0.00    0.00    0.00    0.00     0  |__SPICE
16:06:18      107         -     21882    0.00    0.00    0.00    0.00     0  |__worker

Comment 9 errata-xmlrpc 2019-08-06 13:16:08 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2019:2299