Kernel timing mechanism API timer_setup, mechanism apitimer_setup

Source: Internet
Author: User

Kernel timing mechanism API timer_setup, mechanism apitimer_setup

Timer_setup (timer, callback, flags) is used to prepare for the first use of timer. Generally, it is used with add_timer as follows: static void prb_setup_retire_blk_timer (struct packet_sock * po) {struct tpacket_kbdq_core * pkc; pkc = GET_PBDQC_FROM_RB (& po-> rx_ring); timer_setup (& pks-> retire_blk_timer, primary, 0); pk-> Primary = jiffies ;} the source code analysis is as follows: # define timer_setup (timer, callback, flags) \__ init_timer (timer), (callback), (flags )) it turns out to be a macro # ifdef CONFIG_LOCKDEP # define _ init_timer (_ timer, _ fn, _ flags) \ do {\ static struct lock_class_key _ key; \ init_timer_key (_ timer), (_ fn), (_ flags), # _ timer, & __key) ;\} while (0) # define _ init_timer_on_stack (_ timer, _ fn, _ flags) \ do {\ static struct lock_class_key _ key; \ init_timer_on_stack_key (_ timer), (_ fn ), (_ flags), \# _ timer, & __ key) ;\} while (0) # else # define _ init_timer (_ timer, _ fn, _ flags) \ init_timer_key (_ timer), (_ fn), (_ flags), NULL, NULL) # define _ init_timer_on_stack (_ timer, _ fn, _ flags) \ init_timer_on_stack_key (_ timer), (_ fn), (_ flags), NULL, NULL) # endifconfig_lockedp is used to detect deadlocks. Commonly Used debug, it is assumed that this macro is not enabled, so the init_timer_keyvoid init_timer_key (struct timer_list * timer, void (* func) (struct timer_list *), unsigned int flags, const char * name, struct lock_class_key * key) {# If dimensions is not enabled, debug_init is nulldebug_init (timer); # This function is mainly called to initialize timerdo_init_timer (timer, func, flags, name, key);} static void do_init_timer (struct timer_list * timer, void (* func) (struct timer_list *), unsigned int flags, const char * name, struct lock_class_key * key) {# If pprev is null, it indicates that the timer is in pending state. Of course, pending is required when the timer is created. After all, # timer-> entry has not been started yet. pprev = NULL; # The callback function timer to be executed when the time expires-> function = func; # It seems that the current cpu idtimer is saved in flags-> flags = flags | raw_smp_processor_id (); lockdep_init_map (& timer-> lockdep_map, name, key, 0);} To sum up, it looks like timer_setup (timer, callback, flags) it mainly uses callback and flags to assign values to timer_list * timer, but does not include creating this pointer.

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.