In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
How to analyze the initialization of KVM hardware virtualization in qemu? I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Initialization Analysis of KVM hardware Virtualization in qemu 2014-04-25 14:38:38
Classification: virtualization
1. Pass in the-enable-kvm parameter to enable KVM hardware virtualization support:
In the file qemu-options.hx, the parameter-enable-kvm is defined as follows:
DEF ("enable-kvm", 0, QEMU_OPTION_enable_kvm,\
"- enable-kvm enable KVM full virtualization support\ n", QEMU_ARCH_ALL)
STEXI
@ item-enable-kvm
@ findex-enable-kvm
Enable KVM full virtualization support. This option is only available
If KVM support is enabled when compiling.
ETEXI
Analysis of the corresponding parameters in the 2.main function
Int main (int argc, char * argv, char * * envp)
{
/ * second pass of option parsing * /
Optind = 1
For (;;) {
.
Case QEMU_OPTION_enable_kvm:
Olist = qemu_find_opts ("machine")
Qemu_opts_parse (olist, "accel=kvm", 0)
Break
.
}
.
Os_daemonize ()
.
Configure_accelerator (machine)
.
}
(gdb) p * machine
$46 = {name = 0x555555a17666 "pc-i440fx-2.0", alias = 0x555555a17674 "pc"
Desc = 0x555555a175d8 "Standard PC (i440FX + PIIX, 1996)", init = 0x5555558c2e2c, reset = 0
Hot_add_cpu = 0x5555558c1061, kvm_type = 0, block_default_type = IF_IDE, max_cpus = 255, no_serial = 0
No_parallel = 0, use_virtcon = 0, use_sclp = 0, no_floppy = 0, no_cdrom = 0, no_sdcard = 0, is_default = 1
Default_machine_opts = 0x555555a17677 "firmware=bios-256k.bin", default_boot_order = 0x555555a1768e "cad", compat_props = 0x0
Next = 0x0, hw_version = 0x0}
/ / qemu supports four execution methods: tcg, xen, kvm, and qtest
Static struct {
Const char * opt_name
Const char * name
Int (* available) (void)
Int (* init) (QEMUMachine *)
Bool * allowed
} accel_list [] = {
{"tcg", "tcg", tcg_available, tcg_init, & tcg_allowed}
{"xen", "Xen", xen_available, xen_init, & xen_allowed}
{"kvm", "KVM", kvm_available, kvm_init, & kvm_allowed}
{"qtest", "QTest", qtest_available, qtest_init_accel, & qtest_allowed}
}
/ / parse the parameters and initialize the relevant modules
Static int configure_accelerator (QEMUMachine * machine)
{
Const char * p
Char buf [10]
Int i, ret
Bool accel_initialised = false
Bool init_failed = false
/ / when there is no-enable-kvm parameter, the tcg simulated by software is used by default.
P = qemu_opt_get (qemu_get_machine_opts (), "accel")
If (p = = NULL) {
/ * Use the default "accelerator", tcg * /
P = "tcg"
}
While (! accel_initialised & & * p! ='\ 0') {
If (* p = =':') {
Pendant +
}
P = get_opt_name (buf, sizeof (buf), p,':')
For (I = 0; I)
< ARRAY_SIZE(accel_list); i++) { if (strcmp(accel_list[i].opt_name, buf) == 0) { if (!accel_list[i].available()) { printf("%s not supported for this target\n", accel_list[i].name); continue; } *(accel_list[i].allowed) = true; ret = accel_list[i].init(machine); if (ret < 0) { init_failed = true; fprintf(stderr, "failed to initialize %s: %s\n", accel_list[i].name, strerror(-ret)); *(accel_list[i].allowed) = false; } else { accel_initialised = true; } break; } } if (i == ARRAY_SIZE(accel_list)) { fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf); } } if (!accel_initialised) { if (!init_failed) { fprintf(stderr, "No accelerator found!\n"); } exit(1); } if (init_failed) { fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name); } return !accel_initialised; } 3.kvm_init int kvm_init(QEMUMachine *machine) { ...... s->Fd = qemu_open ("/ dev/kvm", O_RDWR)
If (s-> fd = =-1) {
Fprintf (stderr, "Could not access KVM kernel module:% m\ n")
Ret =-errno
Goto err
}
/ / matches the version of the kvm kernel module. It will not be supported if the version is too old or too new.
Ret = kvm_ioctl (s, KVM_GET_API_VERSION, 0)
If (ret
< KVM_API_VERSION) { if (ret >0) {
Ret =-EINVAL
}
Fprintf (stderr, "kvm version too old\ n")
Goto err
}
If (ret > KVM_API_VERSION) {
Ret =-EINVAL
Fprintf (stderr, "kvm version not supported\ n")
Goto err
}
.
/ * check the vcpu limits * /
Soft_vcpus_limit = kvm_recommended_vcpus (s); / / get the number of vcpu recommended by the kvm kernel
Hard_vcpus_limit = kvm_max_vcpus (s); / / get the maximum number of vcpu available for the kvm kernel
.
Do {
Ret = kvm_ioctl (s, KVM_CREATE_VM, type); / / create a VM
} while (ret = =-EINTR)
.
Ret = kvm_arch_init (s)
If (ret
< 0) { goto err; } ret = kvm_irqchip_create(s); if (ret < 0) { goto err; } kvm_state = s; memory_listener_register(&kvm_memory_listener, &address_space_memory); memory_listener_register(&kvm_io_listener, &address_space_io); s->Many_ioeventfds = kvm_check_many_ioeventfds ()
Cpu_interrupt_handler = kvm_handle_interrupt
Return 0
.
}
After reading the above, have you mastered how to analyze the initialization of KVM hardware virtualization in qemu? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.