Book Image

Mastering KVM Virtualization

Book Image

Mastering KVM Virtualization

Overview of this book

A robust datacenter is essential for any organization – but you don’t want to waste resources. With KVM you can virtualize your datacenter, transforming a Linux operating system into a powerful hypervisor that allows you to manage multiple OS with minimal fuss. This book doesn’t just show you how to virtualize with KVM – it shows you how to do it well. Written to make you an expert on KVM, you’ll learn to manage the three essential pillars of scalability, performance and security – as well as some useful integrations with cloud services such as OpenStack. From the fundamentals of setting up a standalone KVM virtualization platform, and the best tools to harness it effectively, including virt-manager, and kimchi-project, everything you do is built around making KVM work for you in the real-world, helping you to interact and customize it as you need it. With further guidance on performance optimization for Microsoft Windows and RHEL virtual machines, as well as proven strategies for backup and disaster recovery, you’ll can be confident that your virtualized data center is working for your organization – not hampering it. Finally, the book will empower you to unlock the full potential of cloud through KVM. Migrating your physical machines to the cloud can be challenging, but once you’ve mastered KVM, it’s a little easie.
Table of Contents (22 chapters)
Mastering KVM Virtualization
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Execution flow of vCPU


Finally, we are into the vCPU execution flow which helps us to put everything together and understand what happens under the hood.

I hope you didn't forget that the QEMU creates a posix thread for a vCPU of the guest and ioctl(), which is responsible for running a CPU and has the KVM_RUN arg (#define KVM_RUN_IO(KVMIO, 0x80)). vCPU thread executes ioctl(.., KVM_RUN, ...) to run the guest code. As these are posix threads, the Linux kernel can schedule these threads as with any other process/thread in the system.

Let us see how it all works:

Qemu-kvm User Space:
kvm_init_vcpu ()
    kvm_arch_init_vcpu()
       qemu_init_vcpu()
          qemu_kvm_start_vcpu()
             qemu_kvm_cpu_thread_fn()
    while (1) {
        if (cpu_can_run(cpu)) {
                r = kvm_cpu_exec(cpu);
                      }
        }

kvm_cpu_exec (CPUState *cpu)
    ->       run_ret = kvm_vcpu_ioctl(cpu, KVM_RUN, 0);

According to the underlying architecture and hardware, different structures...