LINUX device driver time flow delay execution-2

xiaoxiao2021-03-06  43

About short delay: Delayed by using Jiffies, only the kernel function can only be used: udelay (unsigned long); mdelay (unsigned long msecs); the former is specified by the software cycle, the latter calls the former to delay millisecond . The udelay function can only be used to get a shorter time delay, because the accuracy of the loops_per_second value is only 8 bits, so when calculating longer delays, a considerable error will accumulate. Although the maximum allowable delay is nearly 1 second (because longer delays are overflow), the maximum value of the recommended UDElay function is taken 1000 microseconds (1 milliseconds). A function MDElay can be used when the delay is greater than 11 milliseconds. Special attention is that udelay is a busy wait function (so MDELAY is also), can't run other tasks in the latency period, so it is very careful, especially MDELAY, unless there is no other way, try to avoid use. MDELAY does not exist in Linux 2.0, and the header file sysdep.h makes up this lack. Task is listed: endless continued. . . Nuclear Timer: The kernel maintains a linked list of a two-way Timer_List structure, the kernel traverses 100 every 1 second (a relationship with the specific clock interruption?) Time, each time you have to check the Timer_List structure on the list. Timeout value, if timeout, call the corresponding registration function (call right now?), Then remove this entry from the list. Note: According to "The Design of Unix Operating System", you can see that in each clock interrupt, you have to check the linked list of the two-way Timer_List structure in each clock, huh. Therefore, the timer is another inset resource, even in a single processor system. Any data structure access to the timer function is protected to prevent concurrent access, and the protection method can use atomic types (chapter 10) or with a spin lock. Be careful to avoid collapse when deleting timers. Consider such a situation: The timer function of a module is running on one processor, at which time related events occurred on another processor (the file is turned off or the module is deleted). As a result, the timer function waits for a state that no longer appears, causing the system to crash. In order to avoid this kind of competition, you should use del_timer_sync in the module to replace DEL_TIMER. If the timer function is capable of restarting your timer (this is a common mode), a "stop timer" flag should be added and set before calling DEL_TIMER_SYNC. Such a timer function can be checked if it is executed, and if it has been set, you will not re-schera yourself with add_timer. There is also a situation that will cause a competitive, modify the timer: first delete the timer first, and add a new to the modification with add_timer. In fact, in this case, MOD_TIMER is a better way to use mod_timer. Manipulation of Time_List structure and timer queue: init_timer (...); add_timer (...), del_timer (...), del_timer_sync (...), etc., please see reprint 2

转载请注明原文地址:https://www.9cbs.com/read-112432.html

New Post(0)