当前位置:   article > 正文

QEMU KVM Libvirt手册(7): 硬件虚拟化

sangfor standard pc(i440fx+piix,1996)

在openstack中,如果我们启动一个虚拟机,我们会看到非常复杂的参数

qemu-system-x86_64
-enable-kvm
-name instance-00000024
-S
-machine pc-i440fx-trusty,accel=kvm,usb=off
-cpu SandyBridge,+erms,+smep,+fsgsbase,+pdpe1gb,+rdrand,+f16c,+osxsave,+dca,+pcid,+pdcm,+xtpr,+tm2,+est,+smx,+vmx,+ds_cpl,+monitor,+dtes64,+pbe,+tm,+ht,+ss,+acpi,+ds,+vme
-m 2048 -realtime mlock=off
-smp 1,sockets=1,cores=1,threads=1
-uuid 1f8e6f7e-5a70-4780-89c1-464dc0e7f308
-smbios type=1,manufacturer=OpenStack Foundation,product=OpenStack Nova,version=2014.1,serial=80590690-87d2-e311-b1b0-a0481cabdfb4,uuid=1f8e6f7e-5a70-4780-89c1-464dc0e7f308
-no-user-config
-nodefaults
-chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/instance-00000024.monitor,server,nowait
-mon chardev=charmonitor,id=monitor,mode=control
-rtc base=utc,driftfix=slew
-global kvm-pit.lost_tick_policy=discard
-no-hpet
-no-shutdown
-boot strict=on
-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2
-drive file=/var/lib/nova/instances/1f8e6f7e-5a70-4780-89c1-464dc0e7f308/disk,if=none,id=drive-virtio-disk0,format=qcow2,cache=none
-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1
-netdev tap,fd=32,id=hostnet0,vhost=on,vhostfd=37
-device virtio-net-pci,netdev=hostnet0,id=net0,mac=fa:16:3e:d1:2d:99,bus=pci.0,addr=0x3
-chardev file,id=charserial0,path=/var/lib/nova/instances/1f8e6f7e-5a70-4780-89c1-464dc0e7f308/console.log
-device isa-serial,chardev=charserial0,id=serial0
-chardev pty,id=charserial1
-device isa-serial,chardev=charserial1,id=serial1
-device usb-tablet,id=input0
-vnc 0.0.0.0:12
-k en-us
-device cirrus-vga,id=video0,bus=pci.0,addr=0x2
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5

这节我们会一一解析

QEMU会模拟多种Processor architectures, 常用的是PC (x86 or x86_64 processor), Mac99 PowerMac (PowerPC processor), Sun4u/Sun4v (64-bit Sparc processor), MIPS magnum (64-bit MIPS processor)

通过下面的命令我们可以列出支持的PC bus architecture

744px-Computer_system_bus.svg

 

# qemu-system-x86_64 --machine ?
Supported machines are:
pc-0.13              Standard PC (i440FX + PIIX, 1996)
pc-i440fx-2.0        Standard PC (i440FX + PIIX, 1996)
pc-1.0               Standard PC (i440FX + PIIX, 1996)
pc-q35-1.7           Standard PC (Q35 + ICH9, 2009)
pc-1.1               Standard PC (i440FX + PIIX, 1996)
q35                  Standard PC (Q35 + ICH9, 2009) (alias of pc-q35-2.0)
pc-q35-2.0           Standard PC (Q35 + ICH9, 2009)
pc-i440fx-1.4        Standard PC (i440FX + PIIX, 1996)
pc-i440fx-1.5        Standard PC (i440FX + PIIX, 1996)
pc-0.14              Standard PC (i440FX + PIIX, 1996)
pc-0.15              Standard PC (i440FX + PIIX, 1996)
xenfv                Xen Fully-virtualized PC
pc-q35-1.4           Standard PC (Q35 + ICH9, 2009)
isapc                ISA-only PC
pc-0.10              Standard PC (i440FX + PIIX, 1996)
pc                   Ubuntu 14.04 PC (i440FX + PIIX, 1996) (alias of pc-i440fx-trusty)
pc-i440fx-trusty     Ubuntu 14.04 PC (i440FX + PIIX, 1996) (default)
pc-1.2               Standard PC (i440FX + PIIX, 1996)
pc-0.11              Standard PC (i440FX + PIIX, 1996)
pc-i440fx-1.7        Standard PC (i440FX + PIIX, 1996)
pc-i440fx-1.6        Standard PC (i440FX + PIIX, 1996)
none                 empty machine
xenpv                Xen Para-virtualized PC
pc-q35-1.5           Standard PC (Q35 + ICH9, 2009)
pc-q35-1.6           Standard PC (Q35 + ICH9, 2009)
pc-0.12              Standard PC (i440FX + PIIX, 1996)
pc-1.3               Standard PC (i440FX + PIIX, 1996)

默认的是pc-i440fx-trusty,所以在上面的参数中我们可以看到

-machine pc-i440fx-trusty,accel=kvm,usb=off

在x86 architecture下,很多硬件都可以被模拟

SeaBIOS (from QEMU 0.12.0), PC BIOS from the Bochs project (up QEMU 0.11)
Plex86/Bochs LGPL VGA BIOS
Symmetric multiprocessor system (SMP) for up to 255 CPUs
PC bus: PCI or ISA system (i440FX Host PCI Bridge and PCI to ISA Bridge PIIX3)
Two PCI IDE interfaces with support for up to four (virtual) hard drives or CD / DVD-ROMs
two floppy disk drives
CD or DVD drive
Graphics card (Cirrus CLGD 5446 PCI VGA card or standard VGA graphics card with Bochs VESA BIOS Extension)
2 mouse and keyboard
PCI UHCI USB controller and a virtual USB hub
PCI-/ISA-Netzwerkadapter
Network cards (Intel e1000 and others)
Parallel port
Serial ports
Sound card (Creative Sound Blaster 16, ENSONIQ AudioPCI ES1370 PCI, Intel 82801AA AC97, Adlib OPL2 Yamaha
YM3812, Gravis Ultrasound GF1, CS4231A)
Supervisor Mode Execution Prevention (SMEP) from Intel
Functionalities of VIA CPUs.

CPU

下面的命令可以列出支持的CPU

# qemu-system-x86_64 --cpu ?
x86           qemu64  QEMU Virtual CPU version 2.0.0                 
x86           phenom  AMD Phenom(tm) 9550 Quad-Core Processor        
x86         core2duo  Intel(R) Core(TM)2 Duo CPU     T7700  @ 2.40GHz
x86            kvm64  Common KVM processor                           
x86           qemu32  QEMU Virtual CPU version 2.0.0                 
x86            kvm32  Common 32-bit KVM processor                    
x86          coreduo  Genuine Intel(R) CPU           T2600  @ 2.16GHz
x86              486                                                 
x86          pentium                                                 
x86         pentium2                                                 
x86         pentium3                                                 
x86           athlon  QEMU Virtual CPU version 2.0.0                 
x86             n270  Intel(R) Atom(TM) CPU N270   @ 1.60GHz         
x86           Conroe  Intel Celeron_4x0 (Conroe/Merom Class Core 2)  
x86           Penryn  Intel Core 2 Duo P9xxx (Penryn Class Core 2)   
x86          Nehalem  Intel Core i7 9xx (Nehalem Class Core i7)      
x86         Westmere  Westmere E56xx/L56xx/X56xx (Nehalem-C)         
x86      SandyBridge  Intel Xeon E312xx (Sandy Bridge)               
x86          Haswell  Intel Core Processor (Haswell)                 
x86       Opteron_G1  AMD Opteron 240 (Gen 1 Class Opteron)          
x86       Opteron_G2  AMD Opteron 22xx (Gen 2 Class Opteron)         
x86       Opteron_G3  AMD Opteron 23xx (Gen 3 Class Opteron)         
x86       Opteron_G4  AMD Opteron 62xx class CPU                     
x86       Opteron_G5  AMD Opteron 63xx class CPU                     
x86             host  KVM processor with all supported host features (only available in KVM mode)

Recognized CPUID flags:
  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
  hypervisor rdrand f16c avx osxsave xsave aes tsc-deadline popcnt movbe x2apic sse4.2|sse4_2 sse4.1|sse4_1 dca pcid pdcm xtpr cx16 fma cid ssse3 tm2 est smx vmx ds_cpl monitor dtes64 pclmulqdq|pclmuldq pni|sse3
  smap adx rdseed rtm invpcid erms bmi2 smep avx2 hle bmi1 fsgsbase
  3dnow 3dnowext lm|i64 rdtscp pdpe1gb fxsr_opt|ffxsr mmxext nx|xd syscall
  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
  pmm-en pmm phe-en phe ace2-en ace2 xcrypt-en xcrypt xstore-en xstore
  kvm_pv_unhalt kvm_pv_eoi kvm_steal_time kvm_asyncpf kvmclock kvm_mmu kvm_nopiodelay kvmclock
  pfthreshold pause_filter decodeassists flushbyasid vmcb_clean tsc_scale nrip_save svm_lock lbrv npt

所以我们的参数中有下面的CPU设置及添加的flag

-cpu SandyBridge,+erms,+smep,+fsgsbase,+pdpe1gb,+rdrand,+f16c,+osxsave,+dca,+pcid,+pdcm,+xtpr,+tm2,+est,+smx,+vmx,+ds_cpl,+monitor,+dtes64,+pbe,+tm,+ht,+ss,+acpi,+ds,+vme

SMP对称多处理器

对称多处理"(Symmetrical Multi-Processing)简称SMP,是指在一个计算机上汇集了一组处理器(多CPU),各CPU之间共享内存子系统以及总线结构。
在这种架构中,一台电脑不再由单个CPU组成,而同时由多个处理器运行操作系统的单一复本,并共享内存和一台计算机的其他资源。虽然同时使用多个CPU,但是从管理的角度来看,它们的表现就像一台单机一样。系统将任务队列对称地分布于多个CPU之上,从而极大地提高了整个系统的数据处理能力。所有的处理器都可以平等地访问内存、I/O和外部中断。在对称多处理系统中,系统资源被系统中所有CPU共享,工作负载能够均匀地分配到所有可用处理器之上。

QEMU and KVM 可以最多模拟SMP到255个CPU.

我们的参数中有

-smp 1,sockets=1,cores=1,threads=1

qemu仿真了一个具有1个vcpu,一个socket,一个core,一个threads的处理器。

socket, core, threads是什么概念呢

(1)socket就是主板上插cpu的槽的数目,也即管理员说的”路“
(2)core就是我们平时说的”核“,即双核,4核等
(3)thread就是每个core的硬件线程数,即超线程

具体例子,某个服务器是:2路4核超线程(一般默认为2个线程),那么,通过cat /proc/cpuinfo看到的是2*4*2=16个processor,很多人也习惯成为16核了!

如果使用KVM hardware-assisted virtualization,也即nova-compute.conf中的libvirt_type=kvm,也即BIOS中VD-T是打开的,则参数中accel=kvm

如果不使用hardware-assisted virtualization,也即nova-compute.conf中的libvirt_type=qemu,用的是纯模拟,则有参数accel = tcg,-no-kvm

When you install Microsoft Windows as a guest operating system, the KVM hardware-assisted virtualization should be disabled. After installation, the KVM hardware-assisted virtualization can be enabled on all Windows versions.

其他硬件

还模拟了其他的设备,可以使用默认配置,如果不使用默认配置,则有参数-nodefaults

在monitor中,用下面的命令可以打印出所有的device

virsh # qemu-monitor-command instance-00000024 --hmp "info qtree"
bus: main-system-bus
  type System
  dev: kvm-ioapic, id ""
    gpio-in 24
    gsi_base = 0 (0)
    irq 0
    mmio 00000000fec00000/0000000000001000
  dev: i440FX-pcihost, id ""
    pci-hole64-size = 18446744073709551615 (16 EiB)
    short_root_bus = 0 (0)
    irq 0
    bus: pci.0
      type PCI
      dev: virtio-balloon-pci, id "balloon0"
        indirect_desc = true
        event_idx = true
        class = 255 (0xff)
        addr = 05.0
        romfile = ""
        rombar = 1 (0x1)
        multifunction = false
        command_serr_enable = true
        class Class 00ff, addr 00:05.0, pci id 1af4:1002 (sub 1af4:0005)
        bar 0: i/o at 0xc080 [0xc09f]
        bus: virtio-bus
          type virtio-pci-bus
          dev: virtio-balloon-device, id ""
      dev: cirrus-vga, id "video0"
        vgamem_mb = 8 (0x8)
        addr = 02.0
        romfile = "vgabios-cirrus.bin"
        rombar = 1 (0x1)
        multifunction = false
        command_serr_enable = true
        class VGA controller, addr 00:02.0, pci id 1013:00b8 (sub 1af4:1100)
        bar 0: mem at 0xfc000000 [0xfdffffff]
        bar 1: mem at 0xfebd0000 [0xfebd0fff]
        bar 6: mem at 0xffffffffffffffff [0xfffe]
      dev: virtio-net-pci, id "net0"
        ioeventfd = false
        vectors = 3 (0x3)
        indirect_desc = true
        event_idx = true
        any_layout = true
        csum = true
        guest_csum = true
        gso = true
        guest_tso4 = true
        guest_tso6 = true
        guest_ecn = true
        guest_ufo = true
        host_tso4 = true
        host_tso6 = true
        host_ecn = true
        host_ufo = true
        mrg_rxbuf = true
        status = true
        ctrl_vq = true
        ctrl_rx = true
        ctrl_vlan = true
        ctrl_rx_extra = true
        ctrl_mac_addr = true
        ctrl_guest_offloads = true
        mq = false
        mac = "fa:16:3e:d1:2d:99"
        vlan = <null>
        netdev = "hostnet0"
        bootindex = -1 (0xffffffffffffffff)
        x-txtimer = 150000 (0x249f0)
        x-txburst = 256 (0x100)
        tx = ""
        addr = 03.0
        romfile = "efi-virtio.rom"
        rombar = 1 (0x1)
        multifunction = false
        command_serr_enable = true
        class Ethernet controller, addr 00:03.0, pci id 1af4:1000 (sub 1af4:0001)
        bar 0: i/o at 0xc060 [0xc07f]
        bar 1: mem at 0xfebd1000 [0xfebd1fff]
        bar 6: mem at 0xffffffffffffffff [0x3fffe]
        bus: virtio-bus
          type virtio-pci-bus
          dev: virtio-net-device, id ""
            mac = "fa:16:3e:d1:2d:99"
            vlan = <null>
            netdev = "hostnet0"
            bootindex = -1 (0xffffffffffffffff)
            x-txtimer = 150000 (0x249f0)
            x-txburst = 256 (0x100)
            tx = ""
      dev: virtio-blk-pci, id "virtio-disk0"
        class = 0 (0)
        ioeventfd = true
        vectors = 2 (0x2)
        x-data-plane = false
        indirect_desc = true
        event_idx = true
        drive = "drive-virtio-disk0"
        logical_block_size = 512 (0x200)
        physical_block_size = 512 (0x200)
        min_io_size = 0 (0)
        opt_io_size = 0 (0)
        bootindex = 1 (0x1)
        discard_granularity = 4294967295 (0xffffffff)
        cyls = 0 (0)
        heads = 0 (0)
        secs = 0 (0)
        serial = ""
        config-wce = true
        scsi = false
        x-iothread = ""
        addr = 04.0
        romfile = ""
        rombar = 1 (0x1)
        multifunction = false
        command_serr_enable = true
        class SCSI controller, addr 00:04.0, pci id 1af4:1001 (sub 1af4:0002)
        bar 0: i/o at 0xc000 [0xc03f]
        bar 1: mem at 0xfebd2000 [0xfebd2fff]
        bus: virtio-bus
          type virtio-pci-bus
          dev: virtio-blk-device, id ""
            drive = "drive-virtio-disk0"
            logical_block_size = 512 (0x200)
            physical_block_size = 512 (0x200)
            min_io_size = 0 (0)
            opt_io_size = 0 (0)
            bootindex = 1 (0x1)
            discard_granularity = 4294967295 (0xffffffff)
            cyls = 16383 (0x3fff)
            heads = 16 (0x10)
            secs = 63 (0x3f)
            serial = ""
            config-wce = true
            scsi = false
            x-iothread = ""
      dev: piix3-usb-uhci, id "usb"
        masterbus = ""
        firstport = 0 (0)
        bandwidth = 1280 (0x500)
        maxframes = 128 (0x80)
        addr = 01.2
        romfile = ""
        rombar = 1 (0x1)
        multifunction = false
        command_serr_enable = true
        class USB controller, addr 00:01.2, pci id 8086:7020 (sub 1af4:1100)
        bar 4: i/o at 0xc040 [0xc05f]
        bus: usb.0
          type usb-bus
          dev: usb-tablet, id "input0"
            usb_version = 2 (0x2)
            port = ""
            serial = ""
            full-path = true
            msos-desc = true
            addr 0.2, port 1, speed 12, name QEMU USB Tablet, attached
      dev: PIIX4_PM, id ""
        smb_io_base = 45312 (0xb100)
        disable_s3 = 0 (0)
        disable_s4 = 0 (0)
        s4_val = 2 (0x2)
        acpi-pci-hotplug-with-bridge-support = true
        addr = 01.3
        romfile = ""
        rombar = 1 (0x1)
        multifunction = false
        command_serr_enable = true
        class Bridge, addr 00:01.3, pci id 8086:7113 (sub 1af4:1100)
        bus: i2c
          type i2c-bus
          dev: smbus-eeprom, id ""
            address = 87 (0x57)
          dev: smbus-eeprom, id ""
            address = 86 (0x56)
          dev: smbus-eeprom, id ""
            address = 85 (0x55)
          dev: smbus-eeprom, id ""
            address = 84 (0x54)
          dev: smbus-eeprom, id ""
            address = 83 (0x53)
          dev: smbus-eeprom, id ""
            address = 82 (0x52)
          dev: smbus-eeprom, id ""
            address = 81 (0x51)
          dev: smbus-eeprom, id ""
            address = 80 (0x50)
      dev: piix3-ide, id ""
        addr = 01.1
        romfile = ""
        rombar = 1 (0x1)
        multifunction = false
        command_serr_enable = true
        class IDE controller, addr 00:01.1, pci id 8086:7010 (sub 1af4:1100)
        bar 4: i/o at 0xc0a0 [0xc0af]
        bus: ide.1
          type IDE
        bus: ide.0
          type IDE
      dev: PIIX3, id ""
        addr = 01.0
        romfile = ""
        rombar = 1 (0x1)
        multifunction = true
        command_serr_enable = true
        class ISA bridge, addr 00:01.0, pci id 8086:7000 (sub 1af4:1100)
        bus: isa.0
          type ISA
          dev: isa-serial, id "serial1"
            index = 1 (0x1)
            iobase = 760 (0x2f8)
            irq = 3 (0x3)
            chardev = "charserial1"
            wakeup = 0 (0)
            isa irq 3
          dev: isa-serial, id "serial0"
            index = 0 (0)
            iobase = 1016 (0x3f8)
            irq = 4 (0x4)
            chardev = "charserial0"
            wakeup = 0 (0)
            isa irq 4
          dev: isa-fdc, id ""
            iobase = 1008 (0x3f0)
            irq = 6 (0x6)
            dma = 2 (0x2)
            driveA = ""
            driveB = ""
            bootindexA = -1 (0xffffffffffffffff)
            bootindexB = -1 (0xffffffffffffffff)
            check_media_rate = true
            isa irq 6
          dev: port92, id ""
          dev: vmmouse, id ""
          dev: vmport, id ""
          dev: i8042, id ""
            isa irqs 1,12
          dev: isa-pcspk, id ""
            iobase = 97 (0x61)
          dev: kvm-pit, id ""
            gpio-in 1
            iobase = 64 (0x40)
            lost_tick_policy = "discard"
          dev: mc146818rtc, id ""
            base_year = 0 (0)
            lost_tick_policy = "slew"
            isa irq 8
          dev: kvm-i8259, id ""
            iobase = 160 (0xa0)
            elcr_addr = 1233 (0x4d1)
            elcr_mask = 222 (0xde)
            master = false
          dev: kvm-i8259, id ""
            iobase = 32 (0x20)
            elcr_addr = 1232 (0x4d0)
            elcr_mask = 248 (0xf8)
            master = true
      dev: i440FX, id ""
        addr = 00.0
        romfile = ""
        rombar = 1 (0x1)
        multifunction = false
        command_serr_enable = true
        class Host bridge, addr 00:00.0, pci id 8086:1237 (sub 1af4:1100)
  dev: fw_cfg, id ""
    ctl_iobase = 1296 (0x510)
    data_iobase = 1297 (0x511)
    irq 0
    mmio ffffffffffffffff/0000000000000002
    mmio ffffffffffffffff/0000000000000001
  dev: kvmclock, id ""
    irq 0
  dev: kvmvapic, id ""
    irq 0
  dev: icc-bridge, id ""
    irq 0
    mmio 00000000fee00000/0000000000100000
    bus: icc
      type icc-bus
      dev: kvm-apic, id ""
        id = 0 (0)
        vapic = true
      dev: SandyBridge-x86_64-cpu, id ""
        pmu = false
        hv-spinlocks = -1 (0xffffffffffffffff)
        hv-relaxed = false
        hv-vapic = false
        hv-time = false
        check = false
        enforce = false

SMBIOS

SMBIOS全称System Management BIOS,用于表示x86 architectures的硬件信息

在unix系统上,可以使用下面的命令dmidecode得到,SMBIOS的信息被分为多个table中,称为type

type 0是BIOS信息

# dmidecode --type 0
# dmidecode 2.12
# SMBIOS entry point at 0xcbadeb98
SMBIOS 2.7 present.

Handle 0x0000, DMI type 0, 24 bytes
BIOS Information
        Vendor: Hewlett-Packard
        Version: J61 v03.69
        Release Date: 03/25/2014
        Address: 0xF0000
        Runtime Size: 64 kB
        ROM Size: 16384 kB
        Characteristics:
                PCI is supported
                PNP is supported
                BIOS is upgradeable
                BIOS shadowing is allowed
                Boot from CD is supported
                Selectable boot is supported
                EDD is supported
                Print screen service is supported (int 5h)
                8042 keyboard services are supported (int 9h)
                Serial services are supported (int 14h)
                Printer services are supported (int 17h)
                ACPI is supported
                USB legacy is supported
                BIOS boot specification is supported
                Function key-initiated network boot is supported
                Targeted content distribution is supported
                UEFI is supported
        BIOS Revision: 3.69

type 1是系统信息

# dmidecode --type 1
# dmidecode 2.12
# SMBIOS entry point at 0xcbadeb98
SMBIOS 2.7 present.

Handle 0x0001, DMI type 1, 27 bytes
System Information
        Manufacturer: Hewlett-Packard
        Product Name: HP Z620 Workstation
        Version: Not Specified
        Serial Number: 6CR419WFHT
        UUID: 90065980-D287-11E3-B1B0-A0481CABDFB4
        Wake-up Type: Power Switch
        SKU Number: G2F14UC#AB2
        Family: 103C_53335X G=D

type 2是主板信息

# dmidecode --type 2
# dmidecode 2.12
# SMBIOS entry point at 0xcbadeb98
SMBIOS 2.7 present.

Handle 0x0002, DMI type 2, 15 bytes
Base Board Information
        Manufacturer: Hewlett-Packard
        Product Name: 158A
        Version: 0.00
        Serial Number: 6CR419WFHT
        Asset Tag: 6CR419WFHT
        Features:
                Board is a hosting board
                Board is removable
                Board is replaceable
        Location In Chassis: Not Specified
        Chassis Handle: 0x0003
        Type: Motherboard
        Contained Object Handles: 0

type 3是背板信息

# dmidecode --type 3
# dmidecode 2.12
# SMBIOS entry point at 0xcbadeb98
SMBIOS 2.7 present.

Handle 0x0003, DMI type 3, 22 bytes
Chassis Information
        Manufacturer: Hewlett-Packard
        Type: Mini Tower
        Lock: Not Present
        Version: Not Specified
        Serial Number: 6CR419WFHT
        Asset Tag: 6CR419WFHT
        Boot-up State: Safe
        Power Supply State: Safe
        Thermal State: Safe
        Security Status: Unknown
        OEM Information: 0x00000000
        Height: Unspecified
        Number Of Power Cords: 1
        Contained Elements: 0
        SKU Number: Not Specified

type 4是CPU信息

# dmidecode --type 4
# dmidecode 2.12
# SMBIOS entry point at 0xcbadeb98
SMBIOS 2.7 present.

Handle 0x0004, DMI type 4, 42 bytes
Processor Information
        Socket Designation: CPU0
        Type: Central Processor
        Family: Xeon
        Manufacturer: Intel
        ID: E4 06 03 00 FF FB EB BF
        Signature: Type 0, Family 6, Model 62, Stepping 4
        Flags:
                FPU (Floating-point unit on-chip)
                VME (Virtual mode extension)
                DE (Debugging extension)
                PSE (Page size extension)
                TSC (Time stamp counter)
                MSR (Model specific registers)
                PAE (Physical address extension)
                MCE (Machine check exception)
                CX8 (CMPXCHG8 instruction supported)
                APIC (On-chip APIC hardware supported)
                SEP (Fast system call)
                MTRR (Memory type range registers)
                PGE (Page global enable)
                MCA (Machine check architecture)
                CMOV (Conditional move instruction supported)
                PAT (Page attribute table)
                PSE-36 (36-bit page size extension)
                CLFSH (CLFLUSH instruction supported)
                DS (Debug store)
                ACPI (ACPI supported)
                MMX (MMX technology supported)
                FXSR (FXSAVE and FXSTOR instructions supported)
                SSE (Streaming SIMD extensions)
                SSE2 (Streaming SIMD extensions 2)
                SS (Self-snoop)
                HTT (Multi-threading)
                TM (Thermal monitor supported)
                PBE (Pending break enabled)
        Version: Intel(R) Xeon(R) CPU E5-2680 v2 @ 2.80GHz
        Voltage: 1.0 V
        External Clock: 100 MHz
        Max Speed: 3800 MHz
        Current Speed: 2800 MHz
        Status: Populated, Enabled
        Upgrade: Socket LGA2011
        L1 Cache Handle: 0x0005
        L2 Cache Handle: 0x0006
        L3 Cache Handle: 0x0007
        Serial Number: Not Specified
        Asset Tag: Not Specified
        Part Number: Not Specified
        Core Count: 10
        Core Enabled: 10
        Thread Count: 20
        Characteristics:
                64-bit capable
                Multi-Core
                Hardware Thread
                Execute Protection
                Enhanced Virtualization
                Power/Performance Control

所以我们有参数

-smbios type=1,manufacturer=OpenStack Foundation,product=OpenStack Nova,version=2014.1,serial=80590690-87d2-e311-b1b0-a0481cabdfb4,uuid=1f8e6f7e-5a70-4780-89c1-464dc0e7f308

指定了type 1的信息

RAM

内存的大小在参数中,用-m来指定

-m 2048

If the guest system allocated a large RAM under Linux host system, there may be problems if there is insufficient shared memory type. QEMU then complains about insufficient space in / dev / shm . It is better to expand the file system. For a permanent configuration file is / etc / default / tmpfs (Ubuntu) adapt.
Host ~ # umount / dev / shm
host ~ # mount-t tmpfs-o remount, size = 144m none / dev / shm

guest真正运行态的占用的内存的大小,是用Memory Ballooning来调整

ACPI

The Advanced Configuration and Power Interface (ACPI) is an open industry standard for power management in computers.

ACPI is the default in QEMU.

If there are problems with the guest operating system, you ACPI disabled with the option -no-acpi .

System Clock

系统时间由参数-rtc指定

-rtc [base = utc | localtime | date] [, clock = host | vm] [, driftfix = none | slew]

For problems with the time-drift in Microsoft Windows ACPI HAL option is driftfix = slew apply (only for x86 architectures).

High Precision Event Timer (HPET)是可以更准确的设定时间的

我们的参数中有

-rtc base=utc,driftfix=slew

-no-hpet

USB

USB的好处就是即插即用

参数-usb,可以模拟一个PCI UHCI USB控制器

通过-usbdevice devname,可以添加一个USB device

mouse
    Virtual Mouse. This will override the PS/2 mouse emulation when activated.

tablet
    Pointer device that uses absolute coordinates (like a touchscreen). This means QEMU is able to report the
    mouse position without having to grab the mouse. Also overrides the PS/2 mouse emulation when activated.

disk:[format=format]:file
    Mass storage device based on file. The optional format argument will be used rather than detecting the
    format. Can be used to specifiy "format=raw" to avoid interpreting an untrusted format header.

host:bus.addr
    Pass through the host device identified by bus.addr (Linux only).

host:vendor_id:product_id
    Pass through the host device identified by vendor_id:product_id (Linux only).

serial:[vendorid=vendor_id][,productid=product_id]:dev
    Serial converter to host character device dev, see "-serial" for the available devices.

braille
    Braille device.  This will use BrlAPI to display the braille output on a real or fake device.

net:options
    Network adapter that supports CDC ethernet and RNDIS protocols.

我们在参数里面看到的是

-device usb-tablet,id=input0

通过tablet,鼠标可以在HOST和GUEST机器之间自由的切换

# qemu-monitor-command instance-00000024 --hmp "info usb"
  Device 0.2, Port 1, Speed 12 Mb/s, Product QEMU USB Tablet

PCI

PCI (Peripheral Component Interconnect)是设备总线标准

There are 4 components to the PCI subsytem:

Bus Number 
Device Number
Function Number
Register Number

There are up to 256 available Buses on a PCI system, most commonly all the cards and chips will be located on Bus 0 and Bus 1.
When scanning for hardware, it's a good idea to scan all 256 buses as it won't take that much additional time.
A Device is a physical thing on the PCI bus.  It could be a video card, an ethernet card, a Northbridge, anything.  There is a software maximum of 32 devices that can exist on each bus.  The physical hardware limit is much lower than this due to electrical loading issues, but we won't get into that.
Devices on a motherboard are typically scattered throughout the 32 devices, holes can and will exist. Your software must scan all 32 devices on each bus.

All devices have at least 1 function, function #0.  There are 8 possible functions per device, numbered 0-7.  Any device that has more than 1 function is (hey clever!) called a multi-function device.  Multi-function devices, such as a combination modem+soundcard will usually have 2 uniquely addressable functions, numbered 0 and 1.

Every function of a device has 256 eight-bit registers.  Registers 0-3F are defined by the PCI specification and provide a wealth of information about the particular function.  Registers 40-FF are vendor defined and control the properties of the function itself.  Without vendor specific documentation, these registers should probably be left untouched.

virsh # qemu-monitor-command instance-00000024 --hmp "info pci"
  Bus  0, device   0, function 0:
    Host bridge: PCI device 8086:1237
      id ""
  Bus  0, device   1, function 0:
    ISA bridge: PCI device 8086:7000
      id ""
  Bus  0, device   1, function 1:
    IDE controller: PCI device 8086:7010
      BAR4: I/O at 0xc0a0 [0xc0af].
      id ""
  Bus  0, device   1, function 2:
    USB controller: PCI device 8086:7020
      IRQ 11.
      BAR4: I/O at 0xc040 [0xc05f].
      id "usb"
  Bus  0, device   1, function 3:
    Bridge: PCI device 8086:7113
      IRQ 9.
      id ""
  Bus  0, device   2, function 0:
    VGA controller: PCI device 1013:00b8
      BAR0: 32 bit prefetchable memory at 0xfc000000 [0xfdffffff].
      BAR1: 32 bit memory at 0xfebd0000 [0xfebd0fff].
      BAR6: 32 bit memory at 0xffffffffffffffff [0x0000fffe].
      id "video0"
  Bus  0, device   3, function 0:
    Ethernet controller: PCI device 1af4:1000
      IRQ 11.
      BAR0: I/O at 0xc060 [0xc07f].
      BAR1: 32 bit memory at 0xfebd1000 [0xfebd1fff].
      BAR6: 32 bit memory at 0xffffffffffffffff [0x0003fffe].
      id "net0"
  Bus  0, device   4, function 0:
    SCSI controller: PCI device 1af4:1001
      IRQ 11.
      BAR0: I/O at 0xc000 [0xc03f].
      BAR1: 32 bit memory at 0xfebd2000 [0xfebd2fff].
      id "virtio-disk0"
  Bus  0, device   5, function 0:
    Class 0255: PCI device 1af4:1002
      IRQ 10.
      BAR0: I/O at 0xc080 [0xc09f].
      id "balloon0"

可以看到总线上的设备

这些设备分别对应参数

USB

-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2

显示器

-device cirrus-vga,id=video0,bus=pci.0,addr=0x2

网卡

-device virtio-net-pci,netdev=hostnet0,id=net0,mac=fa:16:3e:d1:2d:99,bus=pci.0,addr=0x3

硬盘

-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1

内存

-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5

显示器

用参数-vga设置,默认为cirrus,它模拟了CL-GD5446 PCI VGA card

声卡

# qemu-system-x86_64 -soundhw ?
Valid sound card names (comma separated):
ac97        Intel 82801AA AC97 Audio
adlib       Yamaha YM3812 (OPL2)
cs4231a     CS4231A
es1370      ENSONIQ AudioPCI ES1370
gus         Gravis Ultrasound GF1
hda         Intel HD Audio
pcspk       PC speaker
sb16        Creative Sound Blaster 16

-soundhw all will enable all of the above

网卡

使用-net参数

The -device option

其实所有的外设都能通过-device来设定

# qemu-system-x86_64 -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 "pci-ohci", bus PCI, desc "Apple USB Controller"
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 "am53c974", bus PCI, desc "AMD Am53c974 PCscsi-PCI SCSI adapter"
name "dc390", bus PCI, desc "Tekram DC-390 SCSI adapter"
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 "isa-fdc", bus ISA
name "isa-ide", bus ISA
name "lsi53c810", bus PCI
name "lsi53c895a", bus PCI, alias "lsi"
name "megasas", bus PCI, desc "LSI MegaRAID SAS 1078"
name "nvme", bus PCI, desc "Non-Volatile Memory Express"
name "piix3-ide", bus PCI
name "piix3-ide-xen", bus PCI
name "piix4-ide", bus PCI
name "pvscsi", bus PCI
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 "usb-uas", bus usb-bus
name "vhost-scsi", bus virtio-bus
name "vhost-scsi-pci", bus PCI
name "virtio-9p-device", bus virtio-bus
name "virtio-9p-pci", bus PCI
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 "i82550", bus PCI, desc "Intel i82550 Ethernet"
name "i82551", bus PCI, desc "Intel i82551 Ethernet"
name "i82557a", bus PCI, desc "Intel i82557A Ethernet"
name "i82557b", bus PCI, desc "Intel i82557B Ethernet"
name "i82557c", bus PCI, desc "Intel i82557C Ethernet"
name "i82558a", bus PCI, desc "Intel i82558A Ethernet"
name "i82558b", bus PCI, desc "Intel i82558B Ethernet"
name "i82559a", bus PCI, desc "Intel i82559A Ethernet"
name "i82559b", bus PCI, desc "Intel i82559B Ethernet"
name "i82559c", bus PCI, desc "Intel i82559C Ethernet"
name "i82559er", bus PCI, desc "Intel i82559ER Ethernet"
name "i82562", bus PCI, desc "Intel i82562 Ethernet"
name "i82801", bus PCI, desc "Intel i82801 Ethernet"
name "ne2k_isa", bus ISA
name "ne2k_pci", bus PCI
name "pcnet", bus PCI
name "rtl8139", bus PCI
name "usb-bt-dongle", bus usb-bus
name "usb-net", bus usb-bus
name "virtio-net-device", bus virtio-bus
name "virtio-net-pci", bus PCI, alias "virtio-net"
name "vmxnet3", bus PCI, desc "VMWare Paravirtualized Ethernet v3"

Input devices:
name "ccid-card-passthru", bus ccid-bus, desc "passthrough smartcard"
name "ipoctal232", bus IndustryPack, desc "GE IP-Octal 232 8-channel RS-232 IndustryPack"
name "isa-parallel", bus ISA
name "isa-serial", bus ISA
name "pci-serial", bus PCI
name "pci-serial-2x", bus PCI
name "pci-serial-4x", bus PCI
name "tpci200", bus PCI, desc "TEWS TPCI200 IndustryPack carrier"
name "usb-braille", bus usb-bus
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 "usb-serial", bus usb-bus
name "usb-tablet", bus usb-bus
name "usb-wacom-tablet", bus usb-bus, desc "QEMU PenPartner Tablet"
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 "isa-cirrus-vga", bus ISA
name "isa-vga", bus ISA
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
name "vmware-svga", bus PCI

Sound devices:
name "AC97", bus PCI, desc "Intel 82801AA AC97 Audio"
name "adlib", bus ISA, desc "Yamaha YM3812 (OPL2)"
name "cs4231a", bus ISA, desc "Crystal Semiconductor CS4231A"
name "ES1370", bus PCI, desc "ENSONIQ AudioPCI ES1370"
name "gus", bus ISA, desc "Gravis Ultrasound GF1"
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)"
name "sb16", bus ISA, desc "Creative Sound Blaster 16"
name "usb-audio", bus usb-bus

Misc devices:
name "i6300esb", bus PCI
name "ib700", bus ISA
name "isa-applesmc", bus ISA
name "isa-debug-exit", bus ISA
name "isa-debugcon", bus ISA
name "ivshmem", bus PCI
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 "pvpanic", bus ISA
name "usb-redir", 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
name "xen-pci-passthrough", bus PCI, desc "Assign an host PCI device with Xen"
name "xen-platform", bus PCI, desc "XEN platform pci device"

Uncategorized devices:
name "i8042", bus ISA
name "xen-pvdevice", bus PCI, desc "Xen PV Device"

Character Devices

Character device (character device) transmit only one character or one byte at a time (serial communication).

使用参数-chardev,每个device都有一个ID,有各种各样的类型type

-chardev null, id = id [, mux = on | off]
-chardev socket, id = id [, host = host ], port = host [, to = to ] [, ipv4] [, ipv6] [, nodelay][, Server] [, nowait] [, telnet] [, mux = on | off] (tcp)
-chardev socket, id = id , path = path [, server] [, nowait] [, telnet], [mux = on | off] (unix)
-chardev udp, id = id [, host = host ], port = port [, localaddr = localaddr ][, Localport = localport ] [, ipv4] [, ipv6] [, mux = on | off]
-chardev msmouse, id = id [, mux = on | off]
-chardev vc, id = id [[, width = width ] [, height = height ]] [[, cols = cols ] [, rows = rows ]][, Mux = on | off]
-chardev file, id = id , path = path [, mux = on | off]
-chardev pipe, id = id , path = path [, mux = on | off]
-chardev pty, id = id [, mux = on | off]
-chardev stdio, id = id [, mux = on | off] [, signal = on | off]
-chardev braille, id = id [, mux = on | off]
-chardev tty, id = id , path = path [, mux = on | off]
-chardev parport, id = id , path = path [, mux = on | off]
-chardev spicevmc, id = id , debug = debug , name = name [, mux = on | off]

在我们的参数中,有下面的设置。

我们可以在monitor中列出所有的chardev

virsh # qemu-monitor-command instance-00000024 --hmp "info chardev"
charserial1: filename=pty:/dev/pts/28
charserial0: filename=file
charmonitor: filename=unix:/var/lib/libvirt/qemu/instance-00000024.monitor,server

第一个chardev是pty

-chardev pty,id=charserial1

-device isa-serial,chardev=charserial1,id=serial1

第二个chardev是file

-chardev file,id=charserial0,path=/var/lib/nova/instances/1f8e6f7e-5a70-4780-89c1-464dc0e7f308/console.log

-device isa-serial,chardev=charserial0,id=serial0

第三个chardev是unix socket

-chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/instance-00000024.monitor,server,nowait

-mon chardev=charmonitor,id=monitor,mode=control

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号