Kernel timer and tasklet

Source: Internet
Author: User

 

1. A kernel timer is a data structure that instructs the kernel to execute a user-defined function using a user-defined parameter at a user-defined time. this implementation is located in <Linux/Timer. h> and kernel/Timer. c
2. In fact, the kernel timer is implemented as a result of "software interruption.
3. The Kernel provides many functions for the driver to declare, register, and remove kernel timers.
1) timer_list: in the Linux kernel, an instance of the timer_list struct corresponds to a timer.
# Include <Linux/Timer. h>
Struct timer_list
{
/*...*/
Unsigned long expires;/* timer expiration time jiffies */
Void (* function) (unsigned long);/* timer processing function */
Unsigned long data;/* the timer processing function is input as the parameter */
};
This expires field indicates the jiffies value that the timer expects to run. At that time, this function is called to use data as a parameter. This structure must be initialized before use.
Define a timer named my_timer
Struct timer_list my_timer;
2) initialize the timer
Void init_timer (struct timer_list * timer );
The init_timer () function initializes the next of the entry of timer_list to null, and assigns a value to the base pointer.
3) Add a timer.
Void add_timer (struct timer_list * timer );
Register the kernel timer and add the timer to the kernel dynamic timer linked list.
4) Delete the timer
Int del_timer (struct timer_list * timer );
Delete the timer. del_timer_sync () is the synchronous version of del_timer (). When deleting a timer, you must wait until it is processed. The call of this function cannot occur in the interrupt context.
5) modify the timer expire
Int mod_timer (struct timer_list * timer, unsigned long expires );
Update the time-out time of a timer and use a common task of the time-out timer (again, the off-motor float timer is a typical example ). mod_timer can also be called on a non-active timer, where you can normally use add_timer.
------------------------------------------------------------------------------
1. A tasket, like a kernel timer, is a kernel mechanism for executing asynchronous tasks in the context of a "Soft Interrupt" (in atomic mode) during hardware interruption.
2. A tasklet exists as a time structure, which must be initialized before use. initialization can be performed by calling a specific function or defining a declaration structure by using some macros:
# Include <Linux/interrupt. h>
Struct tasklet_struct {
/*...*/
Void (* func) (unsigned long );
Unsigned long data;
};
Void tasklet_init (struct tasklet_struct * t,
Void (* func) (unsigned long), unsigned long data );
Declare_tasklet (name, func, data );
Declare_tasklet_disabled (name, func, data );
3. tasklet features
1) A tasklet can be disabled and then re-enabled; it will not execute until it is enabled for the same number of times as it is disabled.
2) Like a timer, A tasklet can register its own
3) A tasklet can be scheduled to run with a normal or high priority.
4) The taslet may run immediately. If the system is not overloaded, it will never be later than the next clock.
5) A tasklet may be concurrent with other tasklet, but it is strictly serialized to itself.
3. Disable the specified tasklet.
Void tasklet_disable (struct tasklet_struct * t );
This function prohibits the specified tasklet. tasklet from being scheduled by tasklet_schedule, but its execution is delayed until the tasklet is re-enabled.
4. disable this tasklet.
Void tasklet_disable_nosync (struct tasklet_struct * t );
This tasklet is disabled, but it does not wait for any currently running function to exit.
5. Enable a previously disabled tasklet
Void tasklet_enable (struct tasklet_struct * t );
6. Schedule tasklet execution
Void tasklet_schedule (struct tasklet_struct * t );
If a tasklet is scheduled again, it only runs once before it has the opportunity to run.

 

 

 

 

 

 

 

 

 

 

 

 

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.