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 );