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.

    Wednesday, October 16, 2013

    Binary Tree

    Data Structure


    Binary Tree Construction


    • Recursive
    • Iterative

    Pre-Order


    • Recursive
    • Iterative

    In-Order


    • Recursive
    • Iterative

    Post-Order


    • Recursive
    • Iterative

    Monday, October 14, 2013

    Maximum Depth of Binary Tree

    Question


    Given a binary tree, find its maximum depth.
    The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

    Solution


    Use recursive method to solve this problem. Retrieve the left part of binary tree and then the right part of binary tree.
    • If the node is empty then return 0
    • If the node is not empty then retrieve left part then retrieve right part. The return value will be (the max path length between left and right) + 1.

    Code


    SeaBIOS - Interface_init

    Sunday, October 13, 2013

    SeaBIOS - Source Code Study (2)

    QEMU_PREINIT(void)



    • qemu_detect(void)

    dopost()


    In this function, besides the qemu_preinit(). It will be responsible to allocate memory, init serial port, make BIOS writable, and start the main function in qemu: maininit()

    maininit(): most important entrypoint for SeaBIOS