QEMU的时间
文章目录
- 0x1 时间的种类
- 0x11 QEMU_CLOCK_REALTIME: Real time clock
- 0x12 QEMU_CLOCK_VIRTUAL: virtual clock
- 0x13 QEMU_CLOCK_HOST: host clock
- 0x14 QEMU_CLOCK_VIRTUAL_RT: realtime clock used for icount warp
- 0x2 使用
- 0x21 获取时间
0x1 时间的种类
// timer.h
typedef enum {
QEMU_CLOCK_REALTIME = 0,
QEMU_CLOCK_VIRTUAL = 1,
QEMU_CLOCK_HOST = 2,
QEMU_CLOCK_VIRTUAL_RT = 3,
QEMU_CLOCK_MAX
} QEMUClockType;
0x11 QEMU_CLOCK_REALTIME: Real time clock
The real time clock should be used only for stuff which does not change the virtual machine state,
as it runs even if the virtual machine is stopped.
不受虚拟系统的影响,随时间流逝而累加计数
0x12 QEMU_CLOCK_VIRTUAL: virtual clock
QEMU_CLOCK_VIRTUAL: virtual clock
The virtual clock only runs during the emulation.
It stops when the virtual machine is stopped.
虚拟时钟,记录GuestOS的时间滴答
0x13 QEMU_CLOCK_HOST: host clock
QEMU_CLOCK_HOST: host clock
The host clock should be used for device models that emulate accurate real time sources.
It will continue to run when the virtual machine is suspended,
and it will reflect system time changes the host may undergo (e.g. due to NTP).
HostOs的时间,类似墙上时钟,修改宿主机系统时间会改变这个时间
0x14 QEMU_CLOCK_VIRTUAL_RT: realtime clock used for icount warp
Outside icount mode, this clock is the same as @QEMU_CLOCK_VIRTUAL.
In icount mode, this clock counts nanoseconds while the virtual machine is running.
It is used to increase @QEMU_CLOCK_VIRTUAL while the CPUs are sleeping and thus not executing instructions.
在非icount模式下和QEMU_CLOCK_VIRTUAL相同,
在icount模式下于与QEMU_CLOCK_VIRTUAL不同的是在虚拟cpu休眠的时候该值也会累加
0x2 使用
0x21 获取时间
int64_t qemu_clock_get_ns(QEMUClockType type)