In Linux driver development, delay functions are often used: Msleep,mdelay/udelay.
Although both Msleep and Mdelay have a delaying effect, they are different.
1.) for the module itself
Mdelay is a busy wait function and cannot run other tasks during the delay. The time of the delay is accurate. It's how long it takes to wait and how much time you really wait.
Msleep is a hibernate function that does not involve busy waiting. If you are Msleep (10), the actual delay time, most of which is more than 10ms, is an indefinite time value.
2.) for the system:
Mdelay () Consumes CPU resources, causing other features to not use CPU resources at this time.
Msleep () does not take up CPU resources, and other modules can use CPU resources at this time.
The delay function is busy waiting, consuming CPU time, while the sleep function causes the invoked process to hibernate.
3.) Udelay () Mdelay () Ndelay () Difference:
Udelay (); Mdelay (); Ndelay (); The principle of implementation is essentially busy waiting, Ndelay and Mdelay are all derived from Udelay.
Implementations of these functions often encounter compiler warnings implicit declaration of function ' Udelay ', which is often caused by improper use of header files.
Udelay () is defined in Include/asm-***/delay.h, and Mdelay and ndelay are defined in Include/linux/delay.h.
Udelay generally apply to a relatively small delay, if you fill the number greater than 2000, the system will think you this is a wrong delay function, so if you need more than 2ms delay need to use the Mdelay function.
4.) Msleep,ssleep Distinction:
Dormant units different
5.) The unit of the second
MS is milliseconds = 0.001 seconds
US is microsecond =0.000001 sec
NS is nanosecond =0.000000001 sec