我正在运行一台带有Intel(R)Xeon(R)CPU E3-1230 v2(共8核)的KVM主机。使用VLC播放器播放1080p视频时,KVM进程的perf stat
结果如下。
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
VM guest虚拟机消耗的CPU过多。我想知道为什么结果的频率是1.98GHz,而实际的CPU频率是3.3GHz(cpufreq调控器设置为性能)。此外,上下文切换和CPU迁移非常频繁。唯一正在运行的应用程序是VLC。
该过程的perf kvm --host --guest stat
结果是:
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
qemu-kvm的配置是(省略了一些设备和chardev选项):
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
如何降低KVM的CPU使用率?
答案 0 :(得分:0)
不确定这是否对您有所帮助,但虚拟环境中的软件可能缺少一些加速,这需要更高效的解码。
您已经添加了很多功能
-cpu core2duo,hv_spinlocks=0xffff,hv_relaxed,hv_time,hv_vapic,+sse4.1,+sse4.2,+x2apic,+pcid,+pdcm,+xtpr,+ht,+ss,+acpi,+ds
如果您的Win7 guest虚拟机使用完整主机cpu的Xeon芯片没有问题,可能会增加一些功能。
-cpu host
此外,您已经在guest虚拟机中启用了spice / qxl以及virtio IO - 遗憾的是,enter link description here还没有Windows Direct3D代码
它可能也很大程度上取决于您在客人中使用的软件 - 如果您可以将其添加到您的问题中,那么下一位尝试提供帮助的人就会很好。
答案 1 :(得分:0)
通过使用,我得到了更好的结果(例如,空闲的CPU使用率更低)
/usr/bin/qemu-system-x86_64
代替qemu-kvm