BKM: improve qemu performance: Difference between revisions

From Yocto Project
Jump to navigationJump to search
No edit summary
Line 13: Line 13:
* enable smp configuration in yocto kernel
* enable smp configuration in yocto kernel
* enable smp option for qemu, like '''-smp 4''' to give 4 vcpu to guest.
* enable smp option for qemu, like '''-smp 4''' to give 4 vcpu to guest.
----
qemu built from yocto may have some bug that only 1 vcpu is truly used by guest(You can use top -d1 inside guest to see only 100% CPU usage). Pls. switch to the qemu in the linux distribution, say ubuntu, as one workaround.


== Add extra disk space ==
== Add extra disk space ==

Revision as of 13:41, 6 December 2011

Link title= improve qemu performance = Qemu in yocto is emulator, and is slow when running huge task inside. E.g. running yocto build inside qemu. This article illustrate possible performance improvement to accelerate it

Enable KVM

If you have processor with VTx support, you can enable KVM so that virtualization rather than emulation is used for performance. Pls. refer following:

Add big memory

Sometimes, workload inside qemu requires huge memory. Fail to do this lead performance drop. So pls. add enough memory to qemu via -m 2048 (2G).

Enable SMP

If workload inside qemu is CPU-intensive, you can enable smp:

  • enable smp configuration in yocto kernel
  • enable smp option for qemu, like -smp 4 to give 4 vcpu to guest.

qemu built from yocto may have some bug that only 1 vcpu is truly used by guest(You can use top -d1 inside guest to see only 100% CPU usage). Pls. switch to the qemu in the linux distribution, say ubuntu, as one workaround.

Add extra disk space

If workload inside qemu is disk-intensive, it may requires huge disk space. You can set up NFS server or add extra disk image, which is preferred as NFS server introduce extra network workload. Following steps to create a new disk image(10G) with ext3 file system:

$ sudo dd if=/dev/zero of=b.img bs=1G count=10
$ sudo losetup /dev/loop0 b.img
$ sudo fdisk /dev/loop0
 Then create one new single partition
$ sudo mkfs.ext3 /dev/loop0
 to create ext3 file system
$ sudo losetup -d /dev/loop0

append this disk image to qemu via -hdb(need further changes if need virtio block device)

Create network environment

Default qemu in yocto talk with host via simple 192.168.7.X, you can use bridge to make the guest act as one true machine, E.g download source code from outside. Pls. see http://www.linux-kvm.org/page/Networking#public_bridge for details

Enable virtio block and network device

Virtio (block/network) device is a para-virtualized device for kvm guest. It is different from normal emulated hard drive, because it is simply faster.

  • enable yocto kernel configuration
+CONFIG_VIRTIO=y
+CONFIG_VIRTIO_PCI=y
+CONFIG_VIRTIO_BALLOON=y
+CONFIG_VIRTIO_RING=y
+CONFIG_VIRTIO_NET=y
+CONFIG_VIRTIO_BLK=y
  • change qemu block device parameter from "-hda <your_disk_image" to -drive file=<your_disk_image>,if=virtio
  • modify qemu NIC parameter: change the -net nic option to include model=virtio

Following is one example

-net nic,model=virtio,vlan=0 -net tap,vlan=0,ifname=tap0,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown -drive file=/home/source.img,if=virtio -drive file=/home/build.img,if=virtio

Enable VTd to for NIC/Block device

Enable VTd with KVM can directed assign PCI device(like NIC or USB disk) to guest, then achieve almost native performance. Pls. make sure your chipset and bios support VTd. Details is to be coming soon:)