kvm搭建完成了,那么问题来了,到底是什么原理
kvm中到底是怎么模拟的CPU和内存?
收到了大量的
这里有一个裸的调用kvm接口的实例,超赞:
使用kvm的API来实现Emulator Demo,同样赞:
//-----2017.12.17 打开tracepoint,这是研究kvm的好方法:
qemu-system-x86-10102 [001] d... 13485.390144: kvm_entry: vcpu 0 qemu-system-x86-10102 [001] .N.. 13485.393300: kvm_exit: reason EXTERNAL_INTERRUPT rip 0x4009b2 info 0 800000ef qemu-system-x86-10102 [001] d... 13485.393301: kvm_fpu: unload qemu-system-x86-10102 [001] .... 13485.401393: kvm_ple_window: vcpu 0: ple_window 4096 (shrink 4096) qemu-system-x86-10102 [001] .... 13485.401398: kvm_fpu: load qemu-system-x86-10102 [001] .... 13485.401399: kvm_apic_accept_irq: apicid 0 vec 239 (Fixed|edge) qemu-system-x86-10102 [001] .... 13485.401400: kvm_inj_virq: irq 239 qemu-system-x86-10102 [001] d... 13485.401401: kvm_entry: vcpu 0 qemu-system-x86-10102 [001] .... 13485.401419: kvm_eoi: apicid 0 vector 239 qemu-system-x86-10102 [001] .... 13485.401419: kvm_pv_eoi: apicid 0 vector 239 qemu-system-x86-10102 [001] .... 13485.401420: kvm_exit: reason MSR_WRITE rip 0xffffffff81064508 info 0 0 qemu-system-x86-10102 [001] .... 13485.401421: kvm_apic: apic_write APIC_TMICT = 0xafd2 qemu-system-x86-10102 [001] .... 13485.401422: kvm_msr: msr_write 838 = 0xafd2 qemu-system-x86-10102 [001] d... 13485.401422: kvm_entry: vcpu 0 qemu-system-x86-10102 [001] .... 13485.402142: kvm_exit: reason EXTERNAL_INTERRUPT rip 0x4009b2 info 0 800000ef qemu-system-x86-10102 [001] .... 13485.402142: kvm_apic_accept_irq: apicid 0 vec 239 (Fixed|edge) qemu-system-x86-10102 [001] .... 13485.402143: kvm_inj_virq: irq 239 qemu-system-x86-10102 [001] d... 13485.402143: kvm_entry: vcpu 0 qemu-system-x86-10102 [001] .... 13485.402146: kvm_eoi: apicid 0 vector 239 qemu-system-x86-10102 [001] .... 13485.402146: kvm_pv_eoi: apicid 0 vector 239 qemu-system-x86-10102 [001] .... 13485.402146: kvm_exit: reason MSR_WRITE rip 0xffffffff81064508 info 0 0 qemu-system-x86-10102 [001] .... 13485.402146: kvm_apic: apic_write APIC_TMICT = 0x3cee0 qemu-system-x86-10102 [001] .... 13485.402146: kvm_msr: msr_write 838 = 0x3cee0 qemu-system-x86-10102 [001] d... 13485.402147: kvm_entry: vcpu 0 qemu-system-x86-10102 [001] .N.. 13485.403339: kvm_exit: reason EXTERNAL_INTERRUPT rip 0x4009b2 info 0 800000ef qemu-system-x86-10102 [001] d... 13485.403341: kvm_fpu: unload qemu-system-x86-10102 [001] .... 13485.403521: kvm_ple_window: vcpu 0: ple_window 4096 (shrink 4096) qemu-system-x86-10102 [001] .... 13485.403523: kvm_fpu: load qemu-system-x86-10102 [001] d... 13485.403523: kvm_entry: vcpu 0 qemu-system-x86-10102 [001] .N.. 13485.404571: kvm_exit: reason EXTERNAL_INTERRUPT rip 0x4009b2 info 0 800000ef qemu-system-x86-10102 [001] d... 13485.404573: kvm_fpu: unload qemu-system-x86-10102 [001] .... 13485.406671: kvm_ple_window: vcpu 0: ple_window 4096 (shrink 4096) qemu-system-x86-10102 [001] .... 13485.406676: kvm_fpu: load qemu-system-x86-10102 [001] .... 13485.406677: kvm_apic_accept_irq: apicid 0 vec 239 (Fixed|edge) qemu-system-x86-10102 [001] .... 13485.406679: kvm_inj_virq: irq 239 qemu-system-x86-10102 [001] d... 13485.406680: kvm_entry: vcpu 0 qemu-system-x86-10102 [001] .... 13485.406702: kvm_eoi: apicid 0 vector 239 qemu-system-x86-10102 [001] .... 13485.406703: kvm_pv_eoi: apicid 0 vector 239 qemu-system-x86-10102 [001] .... 13485.406704: kvm_exit: reason MSR_WRITE rip 0xffffffff81064508 info 0 0 qemu-system-x86-10102 [001] .... 13485.406706: kvm_apic: apic_write APIC_TMICT = 0x34720 qemu-sys
神秘的kvm,服务器端直接运行在,guest按理说也是要有中断的:
39839 __apic_accept_irq ([kvm])
3aa20 kvm_apic_local_deliver ([kvm])
3ac7d kvm_inject_apic_timer_irqs ([kvm])
3824e kvm_inject_pending_timer_irqs ([kvm])
1ebfe kvm_arch_vcpu_ioctl_run ([kvm])
610d kvm_vcpu_ioctl ([kvm])
4200ff do_vfs_ioctl ([kernel.kallsyms])
420369 sys_ioctl ([kernel.kallsyms])
a244f2 entry_SYSCALL_64_fastpath ([kernel.kallsyms])
关键函数是
kvm是如何模拟时钟中断的?
kvm_create_pit create_pit_timer
kvm_create_
有专门的一章,是讨论中断的虚拟化;
还要个超有意思的函数是:kvm_msr事件,