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

Source: Internet
Author: User
Tags mongodb postgresql redis sleep function


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


Alibaba Cloud Hot Products

Elastic Compute Service (ECS) Dedicated Host (DDH) ApsaraDB RDS for MySQL (RDS) ApsaraDB for PolarDB(PolarDB) AnalyticDB for PostgreSQL (ADB for PG)
AnalyticDB for MySQL(ADB for MySQL) Data Transmission Service (DTS) Server Load Balancer (SLB) Global Accelerator (GA) Cloud Enterprise Network (CEN)
Object Storage Service (OSS) Content Delivery Network (CDN) Short Message Service (SMS) Container Service for Kubernetes (ACK) Data Lake Analytics (DLA)

ApsaraDB for Redis (Redis)

ApsaraDB for MongoDB (MongoDB) NAT Gateway VPN Gateway Cloud Firewall
Anti-DDoS Web Application Firewall (WAF) Log Service DataWorks MaxCompute
Elastic MapReduce (EMR) Elasticsearch

Alibaba Cloud Free Trail

Related Article

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.