The jiffies of Linux time management

Source: Internet
Author: User

1, Jiffies

Also known as the Clock tick, is a global variable, its value is initialized to 0 when the system boots, after the clock interrupt initialization completes, each clock interrupt occurs, in the clock interrupt processing routine will be jiffies the value +1.

Jiffies_64: In order to solve the problem of jiffies overflow, it is more important to know the time interval since the start-up through jiffies_64.

2, HZ

Hz indicates how often the clock interrupt occurs. Can be overridden in the configuration file for. config. 1/hz is the time interval for each jiffies+1.

3, through the jiffies can make time comparison and time conversion

4. Time Comparison

32-bit 64-bit

Time_after (A, B) Time_after64 (A, B)

Time_before (A, B) Time_before64 (A, B)

Time_after_eq (A, B) time_after_eq64 (A, B)

Time_before_eq (A, b) time_before_eq64

Time_in_range (a,b,c) time_in_range (a,b,c)

5. Time Conversion

Conversions for A, jiffies and msecs, and Usecs:

unsigned int jiffies_to_msecs (const unsigned long);

unsigned int jiffies_to_usecs (const unsigned long);

unsigned long msecs_to_jiffies (const unsigned int m);

unsigned long usecs_to_jiffies (const unsigned int u);

Conversion of B, jiffies and Timespec, and Timeval

In user space, applications use more time forms, such as seconds and milliseconds, and more jiffes in the kernel.

The kernel defines two kinds of data structures for struct timeval and struct TIMESPEC

struct Timespec {

__kernel_time_t tv_sec;

Long tv_nsec;

}

struct Timeval {

__kernel_time_t tv_sec;

__kernel_suseconds_t tv_usec;

}

Reciprocal Conversion Functions:

unsigned long timespec_to_jiffies (const struct TIMESPEC *value);

void Jiffies_to_timespec (const unsigned long jiffies, struct timespec *value);

unsigned long timeval_to_jiffies (const struct timeval *value);

void Jiffies_to_timeval (const unsigned long jiffies, struct timeval *value);

6, should pay attention to is the jiffies precision question. If Hz = 1000, then the jiffies increase of 1 represents 1ms.

If you want to use a higher precision always, use a different hardware mechanism.

Original link: http://blog.csdn.net/lin2jian4liang4/article/details/49383761

The jiffies of Linux time management

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.