码迷,mamicode.com
首页 > 其他好文 > 详细

kvm

时间:2016-07-31 13:10:26      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:

硬件,os,内核模块,用户空间工具

 

[root@localhost ~]# yum install pciutils

[root@localhost ~]# lscpu;lspci

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    2
Core(s) per socket:    2
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 60
Model name:            Intel(R) Core(TM) i3-4170 CPU @ 3.70GHz
Stepping:              3
CPU MHz:               3700.000
BogoMIPS:              7399.71
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              3072K
NUMA node0 CPU(s):     0-3

00:00.0 Host bridge: Intel Corporation 4th Gen Core Processor DRAM Controller (rev 06) 00:02.0 VGA compatible controller: Intel Corporation 4th Generation Core Processor Family Integrated Graphics Controller (rev 06) 00:03.0 Audio device: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor HD Audio Controller (rev 06) 00:14.0 USB controller: Intel Corporation 9 Series Chipset Family USB xHCI Controller 00:16.0 Communication controller: Intel Corporation 9 Series Chipset Family ME Interface #1 00:19.0 Ethernet controller: Intel Corporation Ethernet Connection I217-V 00:1a.0 USB controller: Intel Corporation 9 Series Chipset Family USB EHCI Controller #2 00:1b.0 Audio device: Intel Corporation 9 Series Chipset Family HD Audio Controller 00:1c.0 PCI bridge: Intel Corporation 9 Series Chipset Family PCI Express Root Port 1 (rev d0) 00:1c.3 PCI bridge: Intel Corporation 9 Series Chipset Family PCI Express Root Port 4 (rev d0) 00:1d.0 USB controller: Intel Corporation 9 Series Chipset Family USB EHCI Controller #1 00:1f.0 ISA bridge: Intel Corporation 9 Series Chipset Family H97 Controller 00:1f.2 RAID bus controller: Intel Corporation SATA Controller [RAID mode] 00:1f.3 SMBus: Intel Corporation 9 Series Chipset Family SMBus Controller 02:00.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev 41)

 

[root@localhost ~]# cat /etc/centos-release
CentOS Linux release 7.2.1511 (Core)

[root@localhost ~]# lsmod |grep kvm
kvm_intel             162153  3
kvm                   525259  1 kvm_intel
[root@localhost ~]# ll /lib/modules/3.10.0-327.el7.x86_64/kernel/arch/x86/kvm/
total 1180
-rw-r--r--. 1 root root 104261 Nov 20  2015 kvm-amd.ko
-rw-r--r--. 1 root root 271245 Nov 20  2015 kvm-intel.ko
-rw-r--r--. 1 root root 824605 Nov 20  2015 kvm.ko

[root@localhost ~]# yum install bridge-utils qemu-kvm
[root@localhost ~]# rpm -qa|grep kvm
qemu-kvm-common-1.5.3-105.el7_2.4.x86_64
qemu-kvm-1.5.3-105.el7_2.4.x86_64

[root@localhost ~]# /usr/libexec/qemu-kvm -version
QEMU emulator version 1.5.3 (qemu-kvm-1.5.3-105.el7_2.4), Copyright (c) 2003-2008 Fabrice Bellard

[root@localhost lib]# /usr/libexec/qemu-kvm -device ?

Controller/Bridge/Hub devices:
name "i82801b11-bridge", bus PCI
name "ioh3420", bus PCI, desc "Intel IOH device id 3420 PCIE Root Port"
name "pci-bridge", bus PCI, desc "Standard PCI Bridge"
name "usb-host", bus usb-bus
name "usb-hub", bus usb-bus
name "x3130-upstream", bus PCI, desc "TI X3130 Upstream Port of PCI Express Switch"
name "xio3130-downstream", bus PCI, desc "TI X3130 Downstream Port of PCI Express Switch"

USB devices:
name "ich9-usb-ehci1", bus PCI
name "ich9-usb-ehci2", bus PCI
name "ich9-usb-uhci1", bus PCI
name "ich9-usb-uhci2", bus PCI
name "ich9-usb-uhci3", bus PCI
name "ich9-usb-uhci4", bus PCI
name "ich9-usb-uhci5", bus PCI
name "ich9-usb-uhci6", bus PCI
name "nec-usb-xhci", bus PCI
name "piix3-usb-uhci", bus PCI
name "piix4-usb-uhci", bus PCI
name "usb-ehci", bus PCI
name "vt82c686b-usb-uhci", bus PCI

Storage devices:
name "ich9-ahci", bus PCI, alias "ahci"
name "ide-cd", bus IDE, desc "virtual IDE CD-ROM"
name "ide-drive", bus IDE, desc "virtual IDE disk or CD-ROM (legacy)"
name "ide-hd", bus IDE, desc "virtual IDE disk"
name "scsi-block", bus SCSI, desc "SCSI block device passthrough"
name "scsi-cd", bus SCSI, desc "virtual SCSI CD-ROM"
name "scsi-disk", bus SCSI, desc "virtual SCSI disk or CD-ROM (legacy)"
name "scsi-generic", bus SCSI, desc "pass through generic scsi device (/dev/sg*)"
name "scsi-hd", bus SCSI, desc "virtual SCSI disk"
name "usb-bot", bus usb-bus
name "usb-storage", bus usb-bus
name "virtio-blk-device", bus virtio-bus
name "virtio-blk-pci", bus PCI, alias "virtio-blk"
name "virtio-scsi-device", bus virtio-bus
name "virtio-scsi-pci", bus PCI

Network devices:
name "e1000", bus PCI, desc "Intel Gigabit Ethernet"
name "rtl8139", bus PCI
name "virtio-net-device", bus virtio-bus
name "virtio-net-pci", bus PCI, alias "virtio-net"

Input devices:
name "ccid-card-passthru", bus ccid-bus, desc "passthrough smartcard"
name "isa-serial", bus ISA
name "pci-serial", bus PCI
name "usb-ccid", bus usb-bus, desc "CCID Rev 1.1 smartcard reader"
name "usb-kbd", bus usb-bus
name "usb-mouse", bus usb-bus
name "virtconsole", bus virtio-serial-bus
name "virtio-serial-device", bus virtio-bus
name "virtio-serial-pci", bus PCI, alias "virtio-serial"
name "virtserialport", bus virtio-serial-bus

Display devices:
name "cirrus-vga", bus PCI, desc "Cirrus CLGD 54xx VGA"
name "qxl", bus PCI, desc "Spice QXL GPU (secondary)"
name "qxl-vga", bus PCI, desc "Spice QXL GPU (primary, vga compatible)"
name "sga", bus ISA, desc "Serial Graphics Adapter"
name "VGA", bus PCI

Sound devices:
name "AC97", bus PCI, desc "Intel 82801AA AC97 Audio"
name "hda-duplex", bus HDA, desc "HDA Audio Codec, duplex (line-out, line-in)"
name "hda-micro", bus HDA, desc "HDA Audio Codec, duplex (speaker, microphone)"
name "hda-output", bus HDA, desc "HDA Audio Codec, output-only (line-out)"
name "ich9-intel-hda", bus PCI, desc "Intel HD Audio Controller (ich9)"
name "intel-hda", bus PCI, desc "Intel HD Audio Controller (ich6)"

Misc devices:
name "i6300esb", bus PCI
name "ib700", bus ISA
name "isa-debug-exit", bus ISA
name "isa-debugcon", bus ISA
name "kvm-pci-assign", bus PCI, alias "pci-assign", desc "KVM-based PCI passthrough"
name "pc-testdev", bus ISA
name "pci-testdev", bus PCI, desc "PCI Test Device"
name "usb-redir", bus usb-bus
name "usb-tablet", bus usb-bus
name "vfio-pci", bus PCI, desc "VFIO-based PCI device assignment"
name "virtio-balloon-device", bus virtio-bus
name "virtio-balloon-pci", bus PCI, alias "virtio-balloon"
name "virtio-rng-device", bus virtio-bus
name "virtio-rng-pci", bus PCI

Uncategorized devices:
name "pvpanic", bus ISA

 

[root@localhost lib]# /usr/libexec/qemu-kvm -device VGA,?

VGA.vgamem_mb=uint32
VGA.mmio=on/off
VGA.addr=pci-devfn
VGA.romfile=string
VGA.rombar=uint32
VGA.multifunction=on/off
VGA.command_serr_enable=on/off

 

[root@localhost lib]# /usr/libexec/qemu-kvm -device qxl,?

qxl.ram_size=uint32
qxl.vram_size=uint32
qxl.revision=uint32
qxl.debug=uint32
qxl.guestdebug=uint32
qxl.cmdlog=uint32
qxl.ram_size_mb=uint32
qxl.vram_size_mb=uint32
qxl.vram64_size_mb=uint32
qxl.vgamem_mb=uint32
qxl.surfaces=int32
qxl.addr=pci-devfn
qxl.romfile=string
qxl.rombar=uint32
qxl.multifunction=on/off
qxl.command_serr_enable=on/off

 

[root@localhost lib]# /usr/libexec/qemu-kvm -device e1000,?

e1000.mac=macaddr
e1000.vlan=vlan
e1000.netdev=netdev
e1000.bootindex=int32
e1000.autonegotiation=on/off
e1000.addr=pci-devfn
e1000.romfile=string
e1000.rombar=uint32
e1000.multifunction=on/off
e1000.command_serr_enable=on/off

 

日志问题追查

Jul 31 11:02:59 localhost kernel: kvm [1463]: vcpu0 disabled perfctr wrmsr: 0xc2 data 0xffff
Jul 31 11:02:59 localhost kernel: kvm [1463]: vcpu0 unhandled rdmsr: 0x570
cpu标志
[root@localhost ~]# cat /proc/cpuinfo
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm arat pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt

日志中kvm报出来的关于cpu的情况
[root@localhost ~]# tail -20 /var/log/messages-20160731
Jul 31 11:02:59 localhost kernel: kvm [1463]: vcpu0 disabled perfctr wrmsr: 0xc2 data 0xffff
Jul 31 11:02:59 localhost kernel: kvm [1463]: vcpu0 unhandled rdmsr: 0x570

这是kvm支持的cpu特征
[root@localhost ~]# /usr/libexec/qemu-kvm -cpu ?|grep msr
  pbe ia64 tm ht ss sse2 sse fxsr mmx acpi ds clflush pn pse36 pat cmov mca pge mtrr sep apic cx8 mce pae msr tsc pse de vme fpu
  perfctr_nb perfctr_core topoext tbm nodeid_msr tce fma4 lwp wdt skinit xop ibs osvw 3dnowprefetch misalignsse sse4a abm cr8legacy extapic svm cmp_legacy lahf_lm

cpu flag msr概念
Model Specific Register (MSR) as the name implies is model specific and may change from processor model number (n) to processor model number (n+1).
读写方法
MSR 是CPU 的一组64 位寄存器,可以分别通过RDMSR 和WRMSR 两条指令进行读和写的操作,前提要在ECX 中写入MSR 的地址。对于RDMSR 指令,将会返回相应的MSR 中64bit 信息到(EDX:EAX)寄存器中;对于WRMSR 指令,把要写入的信息存入(EDX:EAX)中,执行写指令后,即可将相应的信息存入ECX 指定的MSR 中。MSR 的指令必须执行在level 0 或实模式下。
作用
MSR 总体来是为了设置CPU 的工作环境和标示CPU 的工作状态,包括温度控制,性能监控等,具体来说,分为以下几项:

[root@localhost ~]# lsmod|grep papi
[root@localhost ~]# modprobe papi
modprobe: FATAL: Module papi not found.

[root@localhost ~]# lsmod |grep perfctr
[root@localhost ~]# modprobe perfctr
modprobe: FATAL: Module perfctr not found.

# modprobe perfctr 加载模块
lsmod 显示模块
rmmod perfctr移除模块
若perfctr模块安装成功后,你将看到perfctr模块,并且你可以在 /lib/modules/2.6.19-zkl-perfctr/kernel/drivers/perfctr中看到perfctr模块perfctr.ko

需要使用PAPI得到硬件级的数据,即与微指令相关的数据,
例如 L1/L2 cache miss、TLB miss、Cycle等,而PAPI需要perfctr(Performance-monitoring counters support)模块的支持,
而Linux内核当中默认没有perfctr模块,并且perfctr只在某些内核上被支持,它实际上是内核的一个补丁,需要重新编译内核,打上补丁才能在内核上运行perfctr模块。更多信息参考papi和perfctr的INSTALL文件。

PAPI (Performance Application Programming Interface),它是一套API,通过它可以访问CPU性能计数器的数据,
例如 L1/L2 Cache,CPU Cycle,CPU Instruction,TLB等.
PAPI官网是: http://icl.cs.utk.edu/papi/

[root@localhost ~]# yum search papi
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.hust.edu.cn
 * extras: mirrors.neusoft.edu.cn
 * updates: mirrors.neusoft.edu.cn
=================================================== N/S matched: papi ====================================================
papi-devel.i686 : Header files for the compiling programs with PAPI
papi-devel.x86_64 : Header files for the compiling programs with PAPI
papi-static.i686 : Static libraries for the compiling programs with PAPI
papi-static.x86_64 : Static libraries for the compiling programs with PAPI
papi-testsuite.x86_64 : Set of tests for checking PAPI functionality
papi.i686 : Performance Application Programming Interface
papi.x86_64 : Performance Application Programming Interface
pcp-pmda-papi.x86_64 : Performance Co-Pilot (PCP) metrics for Performance API and hardware counters

 

kvm

标签:

原文地址:http://www.cnblogs.com/createyuan/p/5722766.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!