我是靠谱客的博主 深情哈密瓜,这篇文章主要介绍linux cpu tsc,linux的TSC计算原理mult和shift-clocksource_cyc2ns,现在分享给大家,希望可以做个参考。

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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(59)

评论列表共有 0 条评论

立即
投稿
返回
顶部