-1

I was running a KVM host with Intel(R) Xeon(R) CPU E3-1230 v2 (8 cores total). When playing a 1080p video using VLC player, the perf stat result of the KVM process is as follows.

Performance counter stats for process id '120879':

      65235.881169 task-clock                #    1.631 CPUs utilized           [100.00%]
            99,073 context-switches          #    0.002 M/sec                   [100.00%]
            16,616 cpu-migrations            #    0.255 K/sec                   [100.00%]
             8,280 page-faults               #    0.127 K/sec                  
   129,136,372,749 cycles                    #    1.980 GHz                     [100.00%]
    69,852,938,816 stalled-cycles-frontend   #   54.09% frontend cycles idle    [100.00%]
   <not supported> stalled-cycles-backend  
   176,171,866,933 instructions              #    1.36  insns per cycle        
                                             #    0.40  stalled cycles per insn [100.00%]
    13,853,398,215 branches                  #  212.359 M/sec                   [100.00%]
       313,064,663 branch-misses             #    2.26% of all branches        

      40.001590915 seconds time elapsed

The VM guest is consuming too much CPU. I wonder why the freqency in the result is 1.98GHz while the actual CPU frequency is 3.3GHz (the cpufreq governor is set to performance). Also, the context-switches and CPU-migration is very frequent. The only running application is VLC.

The perf kvm --host --guest stat result of the process is:

Performance counter stats for process id '17720':

       6935.898736 task-clock:HG             #    1.653 CPUs utilized           [100.00%]
            11,713 context-switches:HG       #    0.002 M/sec                   [100.00%]
             2,027 cpu-migrations:HG         #    0.292 K/sec                   [100.00%]
           460,754 page-faults:HG            #    0.066 M/sec                  
    24,166,977,190 cycles:HG                 #    3.484 GHz                     [100.00%]
    12,972,225,263 stalled-cycles-frontend:HG #   53.68% frontend cycles idle    [100.00%]
   <not supported> stalled-cycles-backend:HG
    33,789,733,514 instructions:HG           #    1.40  insns per cycle        
                                             #    0.38  stalled cycles per insn [100.00%]
     3,111,479,733 branches:HG               #  448.605 M/sec                   [100.00%]
        60,351,733 branch-misses:HG          #    1.94% of all branches        

       4.196966586 seconds time elapsed 

The configuration for qemu-kvm is (some devices and chardev options are omitted):

qemu-kvm
-chardev socket,id=qmp,path=/var/run/qemu-server/$vmid.qmp,server,nowait
-mon chardev=qmp,mode=control
-vnc :0,websocket,to=200
-enable-kvm
-daemonize
-smp sockets=1,cores=2
-cpu core2duo,hv_spinlocks=0xffff,hv_relaxed,hv_time,hv_vapic,+sse4.1,+sse4.2,+x2apic,+pcid,+pdcm,+xtpr,+ht,+ss,+acpi,+ds
-nodefaults
-vga qxl
-spice port=0,disable-ticketing,up_port=5699,down_port=5500,os_type=win7,jpeg-wan-compression=never,jpeg_quality=85,streaming-video=filter
-boot menu=off,splash-time=1
-m 4096
-drive file=/sf/data/local/images/host-001e67b7f807/9cef0faa00d6/Win7x86-VM0001_hzq.vm/vm-disk-1.qcow2,if=none,id=drive-virtio0,cache=none,aio=native,forecast=enable,cache_cnt=4096,cache_size=256
-device virtio-blk-pci,drive=drive-virtio0,id=virtio0,bus=pci.0,addr=0xa,bootindex=100
-rtc driftfix=slew,clock=rt,base=localtime
-global kvm-pit.lost_tick_policy=discard
-global PIIX4_PM.disable_s3=1
-chardev socket,path=/var/run/qemu-server/$vmid.virtser,server,nowait,id=channelser
-device qxl

How do I reduce the CPU usage of KVM?

useprxf
  • 269
  • 1
  • 3
  • 13

2 Answers2

0

Not sure if that helps you, but the software in the virtual environment might lack some acceleration it would require to be more efficient at decoding.

You already have a lot of features added

-cpu core2duo,hv_spinlocks=0xffff,hv_relaxed,hv_time,hv_vapic,+sse4.1,+sse4.2,+x2apic,+pcid,+pdcm,+xtpr,+ht,+ss,+acpi,+ds

If your Win7 guest has no issue with the Xeon chip using the full host cpu might add a few more capabilities.

-cpu host

Also you already have spice/qxl enabled as well as virtio IO in the guest it seems - unfortunately there is no Windows Direct3D code yet for enter link description here

It might also depend a lot what software you use inside your guest - would be nice if you could add that to your question for the next who tries to help.

  • Thanks. I have already tried `-cpu` host, however the CPU usage is still very high. It may be the Real-Time Clock Interrupt which leads to frequent context switch, so I tried some `-clock -rtc` settings, but they don't work at all. – useprxf Jan 20 '17 at 01:34
  • In the past we sometimes had positive effects in some cases by just running the guest as single cpu. In those cases the context switching also moved CPU assignment all too often as well as guest locking being very bad. I doubt it matches your case, as decoding usually is parallelized very well - but with some luck you might end up with a acceptable decoding at just 1 cpu instead of 1.6 as you have now. – Christian Ehrhardt Jan 23 '17 at 07:30
0

I'm getting better results (e.g. less idle CPU usage) by using

/usr/bin/qemu-system-x86_64

instead of qemu-kvm

bebbo
  • 2,830
  • 1
  • 32
  • 37