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.