kvmclock / KVM PV Clock / KVM Paravirtual Clocksource driver


时间的一种保持方式是通过时钟中断计数,进而换算得到,这种方式在虚拟机里有问题,因为时钟中断不能准时到达guest os。

另外一种方式,如模拟HPET,guest os当需要的时候会去读当前的时间,这种方式会使得虚拟机频繁的退出,严重影响性能。


kvmclock是一个半虚拟化的时钟,guest感知。guest向hypervisor询问时间,同时保证时钟的稳定和准确。默认情况下guest os会使用kvmclock,如fedora17


# cat  /sys/devices/system/clocksource/clocksource0/current_clocksource
kvm-clock


kvmclock原理

guest注册内存页,里面包含kvmclock数据,该页在guest整个生命周期内存在,hypervisor会持续写这个页。


有个结构体pvclock_vcpu_time_info


其中,

pvclock_vcpu_time_info.tsc_to_system_mul   存放当前一nanoseconds多少个counter值,cpu频率调整后该值也会变

pvclock_vcpu_time_info.system_time 最近一次从host读到的时间,通过当前注册的时钟源读取

pvclock_vcpu_time_info.tsc_timestamp: the guest-visible tsc (result of rdtsc + tsc_offset) of   this cpu at the moment we recorded system_time. Note that some time is inevitably spent between system_time and tsc_timestamp measurements. Guests can subtract this quantity from the current value of tsc to obtain a delta to be added to system_time



Glauber Costa曾爆出kvmclock在smp上存在同步问题,并做了fix

问题

http://www.novell.com/support/kb/doc.php?id=7008698

http://article.gmane.org/gmane.comp.emulators.kvm.devel/51604/

http://s19n.net/articles/2011/kvm_clock.html



就此来看,pvclock只是半虚拟化了tsc,其他的时钟还是存在性能问题


参考:

https://lkml.org/lkml/2010/4/15/355

http://rwmj.wordpress.com/2010/10/15/kvm-pvclock/

http://www.linux-kvm.org/page/KVMClock

https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Administration_Guide/sect-Virtualization-Tips_and_tricks-Libvirt_Managed_Timers.html


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值