calibrate_delay 在系统启动时有什么作用

what does calibrate_delay function on system boot

由此http://www.embeddedlinux.org.cn/essentiallinuxdevicedrivers/final/ch02lev1sec1.html

它说

During boot, the kernel calculates the number of times the processor can execute an internal delay loop in one jiffy, which is the time interval between two consecutive ticks of the system timer.

来自 Understanding Linux Kernel book 它说

kernel executes the calibrate_delay() function, which determines how many “loops” fit in a tick

我对 jiffie 和 loops_per_jiffie 感到困惑。从CONFIG_HZ我们已经可以知道分辨率了。例如,如果 CONFIG_HZ 是 250,这意味着一个 jiffie 增量将花费 1/250 = 4 ms

谁能解释一下 calibrate_delay() 它实际计算的是什么?

calibrate_delay() 函数以粗略的方式测量 cpu 每秒可以执行多少条指令。该功能在 wiki about BogoMIPS also, and the result of this function is the number of famous BogoMIPS. The source of the function is in init/calibrate.c 中进行了说明。

查看源代码中的 pr_cont(...) 调用,我猜:

1 loops_per_jiffy / (500000/HZ) = 1 BigoMOPS

也就是说:

1 loops_per_jiffy = 500000 / HZ BigoMOPS

所以 loops_per_jiffy 看起来像是一瞬间有 500000 百万条指令的数量。

say i want 1 micro second delay, how i can use this loops_per_jiffie value

阅读源代码。它是为各种架构实施的。 udelay() in x86/lib/delay.c function or udelay() for mips。它看起来等待 number_of_useconds_to_wait * loops_per_jiffy / 1000000 * 4 * HZ [+ 1] 循环(或类似的东西)。