Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A brief talk on Linux kernel timer

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

The timer in the software sense finally depends on the hardware timer. The kernel detects whether each timer expires after the occurrence of the clock interrupt, and the timer processing function after expiration will be executed in the bottom half as a soft interrupt. In essence, the clock interrupt handler replaces TIMER_SOFTIRQ soft interrupts and runs all timers that expire on the current processor.

To sum up, it is still the process of soft interrupt.

a. Register the soft interrupt handler

/ * / linux/kernel.timer.c*/void _ init init_timers (void)-- > open_softirq (TIMER_SOFTIRQ, run_timer_softirq, NULL)

b. Add timer_list to a linked list

Void add_timer (struct timer_list * timer)

c. Trigger soft interrupt handler function

Void irq_exit (void)-> tick_nohz_stop_sched_tick ();-> raise_softirq_irqoff (TIMER_SOFTIRQ)

d. Call soft interrupt handling function

Static void run_timer_softirq (struct softirq_action * h)

-- > _ _ run_timers (base)

-- > iterate through the timer handler in the timer_list where the execution time arrives

In Linux device driver programming, a set of functions and data structures provided in the Linux kernel can be used to complete timing trigger work or complete some periodic transactions. This set of functions and data structures make it unnecessary for drivers to worry about the kernel and hardware behavior of specific software timers in most cases.

1) an instance of timer_list structure corresponds to a timer, which is defined as follows:

Struct timer_list {struct list_head entry, / * timer list * / unsigned long expires, / * timer expiration time * / void (* function) (unsigned long), / * timer handler * / unsigned long data,/* is passed as parameters to timer handler * / struct timer_base_s * base,.}

Instantiate struct timer_list my_timer

2) initialize timer

Void init_timer (struct timer_list * timer); TIMER_INITIALIZER (_ function, _ expires, _ data) DEFINE_TIMER (_ name, _ function, _ expires, _ data) setup_timer ()

3) add timer

Void add_timer (struct timer_list * timer)

4) delete timer

Int del_timer (struct timer_list * timer)

5) modify the expire of the timer

Int mod_timer (struct timer_list * timer, unsigned long expires)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report