gpt4 book ai didi

c - 如果 jiffies 的分辨率为毫秒,usecs_to_jiffies 如何将 usecs 转换为 jiffies?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:00:14 25 4
gpt4 key购买 nike

来自 here :

The value of HZ varies across kernel versions and hardware platforms. On i386 the situation is as follows: on kernels up to and including 2.4.x, HZ was 100, giving a jiffy value of 0.01 seconds; starting with 2.6.0, HZ was raised to 1000, giving a jiffy of 0.001 seconds. Since kernel 2.6.13, the HZ value is a kernel configuration parameter and can be 100, 250 (the default) or 1000, yielding a jiffies value of, respectively, 0.01, 0.004, or 0.001 seconds. Since kernel 2.6.20, a further frequency is available: 300, a number that divides evenly for the common video frame rates (PAL, 25 HZ; NTSC, 30 HZ).

那么如何将 5usec 转换为 jiffies

extern unsigned long usecs_to_jiffies(const unsigned int u);

它似乎没有用,因为 jiffies 分辨率不够高,无法测量 useconds。

最佳答案

如有疑问,请阅读代码!

在这里(可以找到它的一个版本 here ):

unsigned long usecs_to_jiffies(const unsigned int u)
{
if (u > jiffies_to_usecs(MAX_JIFFY_OFFSET))
return MAX_JIFFY_OFFSET;
#if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
return (u + (USEC_PER_SEC / HZ) - 1) / (USEC_PER_SEC / HZ);
#elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC)
return u * (HZ / USEC_PER_SEC);
#else
return (USEC_TO_HZ_MUL32 * u + USEC_TO_HZ_ADJ32)
>> USEC_TO_HZ_SHR32;
#endif
}

因此,它会做一些事情来检查是否有快捷方式,如果没有其他方法,则使用一些 64 位数学计算出来。

但是 5usec 将是一个 jiffies,无论它运行哪一段代码。

关于c - 如果 jiffies 的分辨率为毫秒,usecs_to_jiffies 如何将 usecs 转换为 jiffies?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14678709/

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