概述
TSC即(Time Stamp Counter或Time Source Cycles)
1 用法
/**
* cyc2ns - converts clocksource cycles to nanoseconds
* @cs: Pointer to clocksource
* @cycles: Cycles
*
* Uses the clocksource and ntp ajdustment to convert cycle_ts to nanoseconds.
*
* XXX - This could use some mult_lxl_ll() asm optimization
*/
static inline s64 cyc2ns(struct clocksource *cs, cycle_t cycles)
{
u64 ret = (u64)cycles;
ret = (ret * cs->mult) >> cs->shift;
return ret;
}
2 动机
为什么不 cycles *NSEC_PER_SEC / freq?
1. convert the clock cycles to ns
ns = cyc *
NSEC_PER_SEC / freq (freq is clock freq of the counter)
= use the
scaling math. (please refer to arch/x86/kernel/tsc.c)
= (cyc * mult)
>> shift (refer t
最后
以上就是深情哈密瓜为你收集整理的linux cpu tsc,linux的TSC计算原理mult和shift-clocksource_cyc2ns的全部内容,希望文章能够帮你解决linux cpu tsc,linux的TSC计算原理mult和shift-clocksource_cyc2ns所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复