2023-09 Monthly Archive
KVM Address Space
Why x86 KVM has 2 address spaces?
// include/linux/kvm_host.h
#define KVM_ADDRESS_SPACE_NUM 1
// arch/x86/include/asm/kvm_host.h
# define KVM_ADDRESS_SPACE_NUM 2
How to resolve conflicts when applying patches
git am --reject --whitespace=fix
这样会生成一个 reg 文件。
Userspace and memory page
用户态程序好像并不需要有分页的概念,用户态程序的视角里地址空间是连续的,并且粒度是字节而不是页。
Get self's thread id (SPID, TID)
pid_t tid = gettid();
info_report("tid: %d", tid);
How to see a process's thread
ps -T -p <pid>
Query enabled capabilities in HMP during live migration (QEMU)
In QMP:
info migrate_capabilities
Exit reason / vcpu->run->exit_reason
/ exit type (KVM)
有两种 Exit reasons:
- 第一种是从 non-root mode exit 到 root mode (KVM) 的 exit reason(SDM-defined, APPENDIX C VMX BASIC EXIT REASONS)。
- 第二种是从 KVM exit 到 Userspace (QEMU) 的 exit reason。
第一种 reason 的定义都是以 EXIT_REASON_*
开头的。第二种 reason 的定义都是以 KVM_EXIT_*
开头的,且存放在 vcpu->run->exit_reason
里面返回给 QEMU。
See thread's CPU utilization
top -H
Current folder size / 查看当前文件夹大小
du -sh
查看当前文件下各个文件的大小:
du -h –max-depth=1 *
Bulk stage QEMU
From ChatGPT:
QEMU live migration consists of several stages, one of which is the "bulk stage." In the context of QEMU and live migration, the bulk stage is when the majority of the virtual machine's memory and state data is transferred from the source host to the destination host. This is a critical phase in live migration, as it involves copying the VM's active memory pages and ensuring that the destination host has an up-to-date replica of the VM's state.
During the bulk stage, QEMU tries to minimize downtime and ensure that the VM remains operational on the source host while transferring as much data as possible to the destination host. Once the bulk stage is complete and the destination host has caught up with the source host's state, the migration enters the "incremental stage," where any remaining changes are synchronized before the final cutover to the destination host.
The bulk stage is a crucial step in ensuring a smooth and seamless live migration of virtual machines between hosts in virtualized environments.
QEMU debug thread "debug-threads"
This causes the naming of individual QEMU threads to be helpful; e.g. "CPU/KVM 0" or "migration". This allows libvirt to identify the purpose of each individual QEMU thread (vCPU number, iothread, etc.).
QEMU trace event / tracing
A file trace-events
must exist in the directory that contains the source code file you are going to trace. 比如:
bsd-user/trace-events
migration/trace-events
backends/trace-events
hw/tpm/trace-events
hw/pci/trace-events
hw/ssi/trace-events
hw/xen/trace-events
//...
io/trace-events
ui/trace-events
trace-events
这个文件长这个样子:
# See docs/devel/tracing.rst for syntax documentation.
# savevm.c
qemu_loadvm_state_section(unsigned int section_type) "%d"
qemu_loadvm_state_section_command(int ret) "%d"
# ...
loadvm_handle_cmd_packaged(unsigned int length) "%u"
如果要使用,在启动 QEMU cmdline 的时候需要指定 trace point:
--trace "kvm_*" --trace "virtio_*"
QEMU trace backend
Before answering what is a "trace-backend" , let me ask you a question: Where do you want the traces be printed? Stdout, a files or anywhere? trace-backend answers this question, it specifies where the trace go.
./configure --enable-trace-backends=simple,dtrace
[Tracing in QEMU. Do you know how to print information in… | by Michael Zhao | Medium](https://michael2012z.medium.com/tracing-in-qemu-8df4e4beaf1b) |
To see all the backends:
"simple" Trace backend
生成一个二进制的 log 文件。如果要分析这个二进制文件,需要借助第三方的工具:
./scripts/simpletrace.py build/trace/trace-events-all trace-12345
可以在 QEMU HMP monitor 里打开/关闭/flush/ trace file 或者设置 trace file 的名字。
trace-file on|off|flush|set <path>
After exiting the virtual machine, a new file was generated in my working directory: trace-<pid>
.