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

Posted on In QA

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

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
sysmen tmp1.libvirt-qemu # cat vcpu0/tasks 
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.

Leave a Reply

Your email address will not be published. Required fields are marked *