Linux Kernel delay function __oracle

Source: Internet
Author: User
Tags set time

The Linux kernel provides 3 functions for nanosecond, subtle, and millisecond latencies, respectively:

void Ndelay (unsigned long nsecs);

void Udelay (unsigned long usecs);

void Mdelay (unsigned long msecs);

These 3 functions of the delay principle is busy waiting, that is, in the process of delay did not give up the CPU, according to the frequency of the CPU to carry out a certain number of cycles.

In the kernel for the millisecond above the delay, it is best not to use the Mdelay function directly, which will waste CPU resources, for milliseconds above the delay, the kernel provides the following functions:

void msleep (unsigned int millisecs);

unsigned long msleep_interruptible (unsigned int milosecs);

void Ssleep (unsigned int seconds);

Note: The accuracy of msleep similar functions is limited by the system Hz and process scheduling.

1 long delay

In the kernel, an intuitive method of delay is to add the current jiffies of the time set for the delay to the delay time, so that the time of delay can be judged simply by comparing the current jiffies and the set time. For this method, a simple macro is provided in the kernel to determine whether the delay is complete.

Time_after (Jiffies,delay); /* Now if you have not reached the time delay, then return true, otherwise return 0*/

Time_before (jiffies,delay); * If the delay has not been completed, return true, otherwise return 0*/

The following two functions can add the current process to the wait queue to sleep on the waiting queue, and the process will wake up when the timeout occurs:

Sleep_on_timeout (wait_queue_head_t *q, unsigned long timeout);

Interrupt_sleep_on_timeout (wait_queue_head_t *q, unsigned long timeout);

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.