http://blog.csdn.net/hzpeterchen/article/details/8090385
因笔者工作在嵌入式平台上(非x386),下面给出的结论仅在arm平台上测试过。
1. 在原子上下文,延迟应该少于100微秒。
使用udelay
2. 在非原子上下文延迟的使用
0-100us: 使用udelay
100us以上: 使用usleep_range
20ms以上且不要求精确: 使用msleep
msleep不精确,完全可以用usleep_range代替。
可以参考的文档:Documentation/timers/timers-howto.txt
下面是在Freescale i.mx6Q (arm Cortex A9, 1.0Ghz, Qual-core)平台上的测试结果,
使用的内核版本是: 3.7.0-rc1+
10us delaycompare: udelay:10:usleep_range:31
100us delaycompare: udelay:99:usleep_range:119
1ms delaycompare: mdelay:998: msleep10429: usleep_range:1017
5ms delaycompare: mdelay:5004: msleep18480: usleep_range:5017
10ms delaycompare: mdelay:9991: msleep19431: usleep_range:10020
20ms delaycompare: mdelay:19987: msleep24205: usleep_range:20019
25ms delaycompare: mdelay:24995: msleep39140: usleep_range:25021
10us delaycompare: udelay:10:usleep_range:31
100us delaycompare: udelay:100:usleep_range:119
1ms delaycompare: mdelay:998: msleep10404: usleep_range:1017
5ms delaycompare: mdelay:5003: msleep18486: usleep_range:5017
10ms delaycompare: mdelay:9993: msleep19455: usleep_range:10027
20ms delaycompare: mdelay:19990: msleep24168: usleep_range:20021
25ms delaycompare: mdelay:25004: msleep39137: usleep_range:25020
10us delaycompare: udelay:10:usleep_range:31
100us delaycompare: udelay:100:usleep_range:119
1ms delaycompare: mdelay:998: msleep10340: usleep_range:1017
5ms delaycompare: mdelay:5005: msleep18480: usleep_range:5016
10ms delaycompare: mdelay:9990: msleep19427: usleep_range:10014
20ms delaycompare: mdelay:19999: msleep24205: usleep_range:20013
25ms delaycompare: mdelay:24996: msleep39144: usleep_range:25024
10us delaycompare: udelay:10:usleep_range:33
100us delaycompare: udelay:100:usleep_range:116
1ms delaycompare: mdelay:998: msleep10387: usleep_range:1014
5ms delaycompare: mdelay:5007: msleep18484: usleep_range:5013
10ms delaycompare: mdelay:9997: msleep19454: usleep_range:10024
20ms delaycompare: mdelay:19990: msleep24179: usleep_range:20020
25ms delaycompare: mdelay:24997: msleep39140: usleep_range:25018
10us delaycompare: udelay:10:usleep_range:35
100us delaycompare: udelay:100:usleep_range:119
1ms delaycompare: mdelay:998: msleep10330: usleep_range:1017
5ms delaycompare: mdelay:5005: msleep18482: usleep_range:5016
10ms delaycompare: mdelay:9991: msleep19433: usleep_range:10021
20ms delaycompare: mdelay:19989: msleep24203: usleep_range:20020
25ms delaycompare: mdelay:24993: msleep39145: usleep_range:25022
10us delaycompare: udelay:10:usleep_range:31
100us delaycompare: udelay:100:usleep_range:120
1ms delaycompare: mdelay:998: msleep10383: usleep_range:1017
5ms delaycompare: mdelay:5004: msleep18486: usleep_range:5017
10ms delaycompare: mdelay:9994: msleep19451: usleep_range:10023
20ms delaycompare: mdelay:19991: msleep24171: usleep_range:20022
25ms delaycompare: mdelay:24998: msleep39141: usleep_range:25020