The difference between Mdelay () and Msleep () in Linux

Source: Internet
Author: User
Tags sleep function

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.