Why udelay and ndelay is not accurate in linux kernel?

前端 未结 3 1245
萌比男神i
萌比男神i 2021-01-15 05:57

I make a function like this

trace_printk(\"111111\");
udelay(4000);
trace_printk(\"222222\");

and the log shows it\'s 4.01 ms , it\'OK

3条回答
  •  攒了一身酷
    2021-01-15 06:22

    As you've already noticed, the nanosecond delay implementation is quite a coarse approximation compared to the millisecond delay, because of the 0x5 constant factor used. 0x10c7 / 0x5 is approximately 859. Using 0x4 would be closer to 1000 (approximately 1073).

    However, using 0x4 would cause the ndelay to be less than the number of nanoseconds requested. In general, delay functions aim to provide a delay at least as long as requested by the user (see here: http://practicepeople.blogspot.jp/2013/08/kernel-programming-busy-waiting-delay.html).

提交回复
热议问题