# why qemu creates 4 threads for a single-core vm

## fpemud

My box is quad-core, but my virt-machine is a single-core one.

qemu created 4 threads for this virt-machine, 2 of them take much cpu time.

AFAIK, one of the 4 threads simulates the cpu of the vm.

Can anyone tell me what the functions of the rest 3 threads are? is there any relative doc?

```

[fpemud@fpemud-workstation /usr/lib64/fpemud-virtmanager/plugins/winxp]$ pstree -c

...

├─gnome-terminal─┬─bash───fpemud-virtmana───sh───qemu-system-x86─┬─{qemu-system-x86}

                                                                                                            ├─{qemu-system-x86}

                                                                                                            ├─{qemu-system-x86}

                                                                                                            ├─{qemu-system-x86}

...
```

```

[fpemud@fpemud-workstation /usr/lib64/fpemud-virtmanager/plugins/winxp]$ cat /tmp/new2/fqemu.cmd

/usr/bin/qemu-system-x86_64 -name "" -enable-kvm -no-user-config -nodefaults -M pc -cpu host -smp 1,sockets=1,cores=1,threads=1 -m 1024 -rtc base=localtime -drive 'file=/tmp/new2/disk-main.img,if=none,id=main-disk,format=raw' -device ide-hd,bus=ide.0,unit=0,drive=main-disk,id=main-disk,bootindex=2 -drive 'file=/tmp/new2/temp/floppy.img,if=none,id=extra-floopy,format=raw' -global isa-fdc.driveA=extra-floopy -drive 'file=/opt/fpemud-virtmanager/plugins/winxp/winxp_sp3.iso,if=none,id=extra-cdrom,readonly=on,format=raw' -device ide-cd,bus=ide.1,unit=0,drive=extra-cdrom,id=extra-cdrom,bootindex=1 -spice port=5910,addr=127.0.0.1,disable-ticketing,seamless-migration=on -device VGA,bus=pci.0,addr=0x04 -usbdevice tablet >fqemu.log 2>&1
```

----------

## vaxbrat

I do sometimes see qemu buzzing top for a windows guest (xp, server 2003) in the initial black screen mode with however many cores I've thrown at it get maxed.  It does settle right down after whatever foolishness M$ does plumbing up the devices.

I see you doing spice.  I think some threads are for the spice agent and clipboarding.

----------

## _______0

kvm may use whatever cpu's are availble on your system as it sees fit irrespective if you assign half cpu to your vm guest. That's the nature of threaded apps. Or do you want to hand pick threading to every single process on your system (possibly doable with cpu-set kernel option)?

----------

## Hu

 *_______0 wrote:*   

> kvm may use whatever cpu's are availble on your system as it sees fit irrespective if you assign half cpu to your vm guest. That's the nature of threaded apps. Or do you want to hand pick threading to every single process on your system (possibly doable with cpu-set kernel option)?

 I believe the OP was curious why qemu created more threads than he could justify based on the VM configuration.  KVM is not able to take more CPUs than it has threads to run, and the number of vCPUs in the guest influences how many threads KVM creates.

Threads can be restricted to a subset of CPUs via taskset.

----------

## fpemud

thank you all for replying.

I think vaxbrat gives a good hint.

----------

