Showing posts with label qemu. Show all posts
Showing posts with label qemu. Show all posts

Saturday, November 9, 2013

QEMU Source Code Study - KVM_RUN

QEMU Part




Like KVM_VCPU_CREATE(), kvm_cpu_exec() is also called by function "qemu_kvm_cpu_thread_fn(...)". For the execution process of qemu_kvm_cpu_thread_fn(...), please check the KVM_VCPU_CREATE() post.

kvm_vcpu_exec()


kvm_arch_pre_run(cpu, run)

struct kvm_run


KVM Part




kvm_vcpu_ioctl(...)

kvm_arch_vcpu_ioctl(filp, ioctl, arg)

vcpu_enter_guest(kvm_vcpu *vcpu)

vmx_vcpu_run( kvm_vcpu *vcpu)

vmx_handle_exit()

static int (*const kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu)

Friday, November 1, 2013

QEMU Source Code Study (3) - KVM_CREATE_VCPU

x86_cpu_register_types() ----> type_register_static(&x86_cpu_type_info) ----> TypeInfo x86_cpu_type_info.class_init = x86_cpu_common_class_init ----> x86_cpu_common_class_init(ObjectClass *oc, void *data) ----> dc->realize = x86_cpu_realizefn ----> x86_cpu_realizefn(DeviceState *dev, Error **error) ----> qemu_init_vcpu(cpu) ----> qemu_kvm_start_vcpu(cpu) ----> qemu_thread_create(cpu->thread, qemu_kvm_cpu_thread_fn, cpu) ----> nqemu_kvm_cpu_thread_fn(arg) ----> kvm_cpu_exec(cpu) ----> kvm_vcpu_ioctl(cpu, KVM_RUN, 0);


How to execute these object?


QEMU Part



kvm_init_vcpu(...)


KVM Part



kvm_vm_ioctl()


kvm_vm_ioctl_create_vcpu(kvm, id)


kvm_x86_ops


vmx_create_vcpu

Monday, October 28, 2013

QEMU Source Code Study (2) - KVM_init

At first, main() in vl.c will call configure_accelerator()




QEMU Part



configure_accelerator()


  • accel_list[]

  • kvm_init()


  • KVMState
  • kvm_ioctl(KVMState *s, int type, ...)



  • KVM Part



    Register ioctl handler


    vmx_init() -> kvm_init(...) -> misc_register(kvm_dev) -> kvm.&kvm_chardev_ops
  • kvm_dev
  • kvm_chardev_ops

  • KVM API




    The "/dev/kvm" ioctl handler is as follows:
  • KVM_GET_API_VERSION
  • This API just return the API version of KVM. The handler just return he version of KVM. This parameter is defined in ./include/uapi/linux/kvm.h
  • KVM_CREATE_VM
  • This API is used by QEMU to ask KVM create VM. "KVM_CREATE_VM" definition is the same as KVM_GET_API_VERSION.

    Tuesday, October 1, 2013

    QEMU Source Code Study - 1




  • The entry point of QEMU is int main in vl.c
  • MODULE_INIT_TYPE (Code1-1)
  • Four types Module Definition
  • module_init()
  • register_module_init()
  • module_call_init(...)
  • TypeInfo
  • The basic parameter used to restore QEMU Object.