In the development of Linux driver, the delay function is often used: Msleep,mdelay/udelay.
Although both Msleep and mdelay have delayed effects, they are different.
1.) for the module itself
Mdelay is a busy wait function and cannot run other tasks during the delay process. The time for this delay is accurate. Is how much time you will actually wait for.
Msleep is a sleep function, and it does not involve busy waiting. If you are Msleep (10), then the delay in fact, most of the time is more than 10ms, is a variable time value.
2.) for the system:
Mdelay () Consumes CPU resources, causing other functions to not use CPU resources at this time.
Msleep () does not occupy CPU resources, and other modules can use CPU resources at this time.
The delay function is busy while waiting, consuming CPU time, while the sleep function causes the calling process to hibernate.
3.) Udelay () Mdelay () Ndelay () Difference:
Udelay (); Mdelay (); Ndelay (); The principle of implementation is essentially busy waiting, Ndelay and Mdelay are derived from Udelay.
The 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 applies to a relatively small delay, if you fill the number greater than 2000, the system will consider you this is a wrong delay function, so if you need more than 2ms delay needs to use the Mdelay function.
4.) Msleep,ssleep Differences:
Sleep units are different
5.) Units of seconds
MS is milliseconds = 0.001 seconds
US is microsecond =0.000001 sec
NS is nanosecond =0.000000001 s
The difference between Mdelay () and Msleep () in Linux