How to get vCPU thread ID in QEMU/KVM host OS?

In order to collect more information about CPU information internal guest OS, we usually need to get vCPU's thread ID in host OS.

asked Sep 2 by harryxiyou (4,690 points)

1 Answer

 
Best answer

Solution 1: Under directory '/sys/fs/cgroup/cpuset/machine', you will find virtual_machine_name.libvirt-qemu directory. And under this directory, you will find all vCPU sub-directories and under these dirs, you will find vCPU thread IDs.

For example

sysmen tmp1.libvirt-qemu # ls
cgroup.clone_children  cpuset.cpus           cpuset.memory_migrate      cpuset.memory_spread_slab  cpuset.sched_relax_domain_level  tasks  vcpu2  vcpu5
cgroup.procs           cpuset.mem_exclusive  cpuset.memory_pressure     cpuset.mems                emulator                         vcpu0  vcpu3
cpuset.cpu_exclusive   cpuset.mem_hardwall   cpuset.memory_spread_page  cpuset.sched_load_balance  notify_on_release                vcpu1  vcpu4
sysmen tmp1.libvirt-qemu # pwd
/sys/fs/cgroup/cpuset/machine/tmp1.libvirt-qemu
sysmen tmp1.libvirt-qemu # cat vcpu0/tasks 
99461
sysmen tmp1.libvirt-qemu # taskset -pc 99461
pid 99461's current affinity list: 0

BTW, '# taskset -pc 99461' will get this thread ID's affinity information.

answered Sep 2 by harryxiyou (4,690 points)
edited Sep 2 by harryxiyou

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...