Linux Kernel development and Linux kernel development
The timer hardware of the time difference measurement system generates clock interruptions at a fixed frequency, and the interval between which the interruption is always determined by the HZ constant, usually between 50 and ~ Between 1200, x86 is 1000 by default, HZ can be configured according to different kernels.
In Linux, jiffies (unsigned long) is used to count clock interruptions. The value of jiffies is greater than 1 when a clock interruption occurs. Therefore, jiffies records the total number of clock interruptions since the system is started. During the driver development process, clock interruption is often used to calculate the time interval of different events.
For inaccurate latency requirements, you can use a while loop to calculate the latency.
// Delay: 10 seconds
unsigned long j = jiffies + 10 * HZ;while(jiffies < j){// do something.}The kernel timer is used to control the execution of each function at a certain time point in the future. The kernel timer can only be executed once after it is registered. If the timer is deleted before the time point when the target function is executed, the target function cannot be executed.
The data structure used by the kernel timer (timing events of different kernels are connected in the form of a two-way linked list ):
Struct timer_list {struct list_head entry; // unsigned long expires; // Delay Time struct tvec_base * base; void (* function) (unsigned long); // target function, when the scheduled time arrives, the unsigned long data will be called; // The data carried by the target function ......};
- Init_timer (struct timer_list * timer) // initialize the timer event
- Void add_timer (struct timer_list * timer) // Add a scheduled event
- Int del_timer (struct timer_list * timer) // deletes a scheduled event.
Example:
#include <linux/module.h>#include <linux/init.h>MODULE_LICENSE("GPL");MODULE_AUTHOR("Jack Chen");MODULE_DESCRIPTION("Hello World");MODULE_ALIAS("A simple module");MODULE_VERSION("V1.0");struct timer_list timer;static void _function(int data){printk("<3> time is up data:%d\n",data);}static int timer_init(){init_timer(&timer);timer.expires = jiffies + 5*HZ;timer.function = _function;timer.data = 10;add_timer(&timer);return 0;}static void timer_exit(){del_timer(&timer);}module_init(timer_init);module_exit(timer_exit);
Linux Kernel development books
The three most classic types:
Design and Implementation of Linux kernel version 2 by Robert Love
Deep understanding of Linux kernel
Scenario Analysis
Let's take a look at shen, which focuses on principles, and Linux kernel design and implementation. You 'd better read the operating system principles book first. After reading it several times, you can view the situation analysis. It is best to view it in "deep. The two documents show that "deep" is the outline and "Emotion" is the object. Finally, go deep into the code.
We are paying less attention to the Chinese New Year ~
Linux Kernel Development
I saw a book 21 days to learn linux programming in Xinhua bookstore a few days ago. Although it is a bit exaggerated, it only takes 210 days to multiply the number by 10. I believe you can do it if you work hard enough!