Linux Kernel Driver (4): 4. Linux kernel Timer

Source: Internet
Author: User

I. measurement time difference

1. There is a constant "HZ" in the Linux kernel, and Hz is a constant unrelated to the architecture. It is used to configure the number of system interruptions per second. The value range is 50-1200 (meaning 50 to 1200 interruptions per second). The default value is 1000 on the X86 platform.

2. The global variable jiffies (unsigned long ). Every time a clock is interrupted, the global variable jiffies is added with 1. Therefore, jiffies records the number of times a single clock is generated after Linux is started. Drivers often use jiffies to calculate the interval between different events.

Ii. kernel Timer: the timer is used to control the execution of a processing function at a certain time in the future. The processing function is executed only once. After execution, the timer becomes invalid.

1. the kernel timer is organized into a two-way Linked List and described using the struct timer_list structure.

Struct timer_list {struct list_head entry; // The kernel uses unsigned long expires; // The jiffies value for timeout void (* function) (unsigned long); // The timeout processing function unsigned long data; // The parameter struct tvec_base * base used by the timeout processing function; // kernel usage}

Iii. kernel timer operation functions

1. initialize the timer queue structure: void init_timer (struct timer_list * timer );

2. Start the Timer: void add_timer (struct timer_list * timer );

3. Delete the timer before it times out (the system automatically deletes the timer after it times out ). Void del_timer (struct timer_list * timer );

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.