gpt4 book ai didi

c - 为什么 Linux 内核中有 ktime_get 的粗略变体?

转载 作者:行者123 更新时间:2023-11-30 19:59:24 25 4
gpt4 key购买 nike

我正在浏览以下链接:

https://www.kernel.org/doc/html/latest/core-api/timekeeping.html

我们有粗略 (ktime_get_coarse()) 和非粗略 (ktime_get()) 版本。

我们应该使用哪一个以及何时使用?

它说粗略版本比非粗略版本更快。

非粗略版本是否读取硬件计数器?

最佳答案

问:

Which one should we use and when?

您的链接似乎对此进行了很好的描述。
答:

These are quicker than the non-coarse versions, but less accurate.

因此,如果您需要快速且不关心准确性 - 请使用粗略(100HZ 时的误差最多为 10 毫秒,1000HZ 时的误差最多为 1 毫秒)。如果优先考虑准确性,则使用非粗略 API。

<小时/>

问:

Whether the non-coarse versions reads the hardware counter or not?

答:
ktime_get() (与 ktime_get_coarse() 不同)最终调用 timekeeping_get_delta()它读取时钟源 tk_clock_read() :

static inline u64 tk_clock_read(const struct tk_read_base *tkr)
{
struct clocksource *clock = READ_ONCE(tkr->clock);

return clock->read(clock);
}

在内部调用适当的回调以供硬件计时器读取。
您可以在源中通过时钟源 grep 搜索此类回调:grep -rnI 'read =' drivers/clocksource
例如。 here设置为tpu_clocksource_read() .

关于c - 为什么 Linux 内核中有 ktime_get 的粗略变体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60166052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com