KVM源代碼框架


自己通過看代碼總結的內核中包含kvm的文件夾:

(1)Linux-3.17.4\Documentation\virtual\kvm\

(2)Linux-3.17.4\include\

(3)Linux-3.17.4\drivers\s390\kvm\

(4)Linux-3.17.4\virt\kvm\

(5)Linux-3.17.4\arch\*\kvm\   (*號代表以下處理器體系架構:x86、tile、s390、powerpc、mips、ia64、arm64、arm)  先研究x86體系架構。

(6)linux-3.17.4\arch\x86\include\asm

注:因為每個文件都含有makefile,所以就不列舉makefile文件了。

(1)  Linux-3.17.4\Documentation\virtual\kvm\下面為文檔介紹,主要介紹了KVM中的使用的一些技術,對其中一部分數據結構和方法進行說明。

(2)  Linux-3.17.4\include\kvm\中有2個文件:代碼總共行數:4957

Arm_arch_timer.h:KVM定時器相關的函數      代碼行數:103

Arm_vgic.h:虛擬通用中斷控制器相關的數據結構和函數     代碼行數:314

 

1)linux-3.17.4\include\trace\events\kvm.h: 代碼行數:322

一些跟蹤事件函數的聲明

其中一段代碼:

#define kvm_trace_exit_reason                                        \

       ERSN(UNKNOWN), ERSN(EXCEPTION), ERSN(IO), ERSN(HYPERCALL),  \

       ERSN(DEBUG), ERSN(HLT), ERSN(MMIO), ERSN(IRQ_WINDOW_OPEN),       \

       ERSN(SHUTDOWN), ERSN(FAIL_ENTRY), ERSN(INTR), ERSN(SET_TPR),       \

       ERSN(TPR_ACCESS), ERSN(S390_SIEIC), ERSN(S390_RESET), ERSN(DCR),\

       ERSN(NMI), ERSN(INTERNAL_ERROR), ERSN(OSI), ERSN(PAPR_HCALL),      \

      ERSN(S390_UCONTROL), ERSN(WATCHDOG), ERSN(S390_TSCH)

2)linux-3.17.4\include\linux\kvm_host.h:      代碼行數:1101

非常重要的頭文件

/*

 * The bit 16 ~ bit 31 of kvm_memory_region::flags are internally used

 * in kvm, other bits are visible for userspace which are defined in

 * include/linux/kvm_h.

 */

3)linux-3.17.4\include\linux\kvm_para.h:      代碼行數:27

一個函數:static inline int kvm_para_has_feature(unsigned int feature)

4)linux-3.17.4\include\linux\kvm_types.h:    代碼行數:79

/*

 * Address types:

*  gva - guest virtual address

 *  gpa - guest physical address

 *  gfn - guest frame number

 *  hva - host virtual address

 *  hpa - host physical address

 *  hfn - host frame number

 */

 

5)linux-3.17.4\include\uapi\linux\kvm.h: 代碼行數:1186

 Userspace interface for /dev/kvm - kernel based virtual machine

/*The bit 0 ~ bit 15 of kvm_memory_region::flags are visible for userspace,

 * other bits are reserved for kvm internal use which are defined in

 * include/linux/kvm_host.h.*/

6)linux-3.17.4\include\uapi\linux\kvm_para.h:      代碼行數:33

/*

 * This header file provides a method for making a hypercall to the host

 * Architectures should define:

 * - kvm_hypercall0, kvm_hypercall1...

 * - kvm_arch_para_features

 * - kvm_para_available

 */

 

/* Return values for hypercalls */

/*

 * hypercalls use architecture specific

 */

 

7)linux-3.17.4\include\uapi\asm-generic\kvm_para.h: 代碼行數:0

/*

 * There isn't anything here, but the file must not be empty or(否則) patch

 * will delete it.

 */

8)linux-3.17.4\include\asm-generic\kvm_para.h: 代碼行數:27

This function is used by architectures that support kvm to avoid issuing false soft lockup messages.

Uapi可能是user api的意思

 

 (3)Linux-3.17.4\drivers\s390\kvm\文件夾下有2個文件:代碼總共行數:1765

Kvm_virtio.c: 功能是 virtio for kvm on s390    代碼行數:513

Virtio_ccw.c:  功能是ccw based virtio transport      代碼行數:1252

virtio 是對半虛擬化 hypervisor 中的一組通用模擬設備的抽象。

重點看第(4)和(5)部分

(4)Linux-3.17.4\virt\kvm\  與體系結構無關的代碼   代碼總共行數:10629

包含一個名為arm的文件夾和15個文件。

 

assigned-dev.c 代碼行數:1027

功能:Kernel-based Virtual Machine - device assignment support

async_pf.c和async_pf.h:   代碼行數:228

kvm asynchronous fault support  KVM支持異步故障

coalesced_mmio.c和coalesced_mmio.h:     代碼行數:183+39

KVM  coalesced(合並) MMIO

MMIO(Memory mapping I/O)即內存映射I/O,它是PCI規范的一部分,I/O設備被放置在內存空間而不是I/O空間。

eventfd.c: 代碼行數:931

kvm eventfd support - use eventfd objects to signal various KVM events

ioapic.c和ioapic.h:       代碼行數:646+103

apic: Advanced Programmable Interrupt Controller高級可編程中斷控制器.

Iodev.h: 對io設備的操作頭文件 代碼行數:71

Iommu.c : 代碼行數:361

 input/output memory management unit。Device的IOMMU類似於CPU的MMU。

MMU是Memory Management Unit的縮寫,中文名是內存管理單元,它是中央處理器(CPU)中用來管理虛擬存儲器、物理存儲器的控制線路,同時也負責虛擬地址映射為物理地址,以及提供硬件機制的內存訪問授權,多用戶多進程操作系統。

Irq_comm.c:   代碼行數:370

Common API for in kernel interrupt controllers .

irqchip.c:   代碼行數:215

Common API for in kernel interrupt controllers

This file is derived from virt/kvm/irq_comm.c.

      IRQ全稱為Interrupt Request,即是“中斷請求”的意思,IRQ的作用就是在我們所用的電腦中,執行硬件中斷請求的動作。

Kconfig: KVM common configuration items and defaults

Kvm_main.c:     代碼行數:3279

Kernel-based Virtual Machine driver for Linux.This module enables machines with Intel VT-x extensions to run virtual machines without emulation or binary translation.

Vfio.c: 代碼行數:278

 VFIO-KVM bridge pseudo device

VFIO是一套用戶態驅動框架,它提供兩種基本服務:(1)向用戶態提供訪問硬件設備的接口(2) 向用戶態提供配置IOMMU的接口

 

arm文件夾中包含4個文件。

 arch_timer.c:KVM定時器  代碼行數:318

Vgic:virtual generic interrupt controller,其它3個文件功能就是主要描述它的。V2和v3是第二第三個版本。 代碼行數:2070+264+246

(5) Linux-3.17.4\arch\x86\kvm\   與體系結構相關的代碼 代碼總共行數:39246

包含25個文件

 

 

Cupid.c和cpuid.h: 代碼行數:795+107

 CPU ID 指用戶計算機當今的信息處理器的信息。

 Kernel-based Virtual Machine driver for Linux

    cpuid support routines

derived from arch/x86/kvm/x86.c

emulate.c: 代碼行數:5068

Generic x86 (32-bit and 64-bit) instruction decoder and emulator.

      Linux coding style, mod r/m decoder, segment base fixes, real-mode privileged instructions

I8254.c和i8254.h: 代碼行數:778+66

8253/8254 interval timer emulation,就是定時器仿真。Based on QEMU and Xen.

I8259.c:     代碼行數:665

8259 interrupt controller emulation,中斷控制器仿真。Port from Qemu.

irq.c:    代碼行數:130

API for in kernel interrupt controller

irq.h:    代碼行數:107

 in kernel interrupt controller related definitions

Kconfig: KVM configuration;  source "virt/kvm/Kconfig"

Kvm_cache_regs.h: 代碼行數:103

Lapic.c和Lapic.h:   代碼行數:1937+174

Local APIC virtualization。apic: Advanced Programmable Interrupt Controller高級可編程中斷控制器

Mmu.c和mmu.h: 代碼行數:4608 + 182

Kernel-based Virtual Machine driver for Linux

* This module enables machines with Intel VT-x extensions to run virtual machines without emulation or binary translation.

* MMU support

Mmu_audit.c: Audit code for KVM MMU   代碼行數:300

Mmutrace.h:     代碼行數:334

paging_tmpl.h: 代碼行數:993

Kernel-based Virtual Machine driver for Linux;MMU support;

pmu.c: 代碼行數:573

Kernel-based Virtual Machine -- Performance Monitoring Unit support, 性能監視單元支持

svm.c:       代碼行數:4424

Kernel-based Virtual Machine driver for Linux; AMD SVM support;svm:安全虛擬機

Trace.h:     代碼行數:862

Tss.h:        代碼行數:60

Vmx.c: 代碼行數:9132

Kernel-based Virtual Machine driver for Linux;

X86.c和x86.h: 代碼行數:7676 + 172

 * Kernel-based Virtual Machine driver for Linux

 * derived from drivers/kvm/kvm_main.c

(6)linux-3.17.4\arch\x86\include\asm下面有4個頭文件代碼總共行數:1663

 

kvm_emulate.h:      代碼行數:428

Generic x86 (32-bit and 64-bit) instruction decoder and emulator. Copyright (c) 2005 Keir Fraser. From: xen-unstable 10676:af9809f51f81a3c43f276f00c81a52ef558afda4

kvm_guest.h:          代碼行數:7

#ifndef _ASM_X86_KVM_GUEST_H//如果沒有定義~

#define _ASM_X86_KVM_GUEST_H//則定義~,且編譯以下代碼

int kvm_setup_vsyscall_timeinfo(void);

#endif /* _ASM_X86_KVM_GUEST_H */

kvm_host.h:           代碼行數:1096

This header defines architecture specific interfaces, x86 version

kvm_para.h:           代碼行數:132

共有代碼:58260行(只包含x86架構)。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM