Run the "add_timer_on" and "apiadd_timer_on" commands in the kernel timer mechanism.

Source: Internet
Author: User

Run the "add_timer_on" and "apiadd_timer_on" commands in the kernel timer mechanism.

Add_timer_on

Add_timer_on is used to start a timer on the cpu specified by the parameter. the source code analysis is as follows: From this function, we can know that every cpu has a list of timer. if you do not specify the cpu when calling add_timer, it is actually running on the current cpu. Void add_timer_on (struct timer_list * timer, int cpu) {struct timer_base * new_base, * base; unsigned long flags; # If the callback function after the timer has been pending or timer expires is null, the current callstackBUG_ON (timer_pending (timer) is printed through BUG_ON |! Timer-> function); # obtain the timer_base pointer new_base = get_timer_cpu_base (timer-> flags, cpu) on the cpu specified by the parameter./** If @ timer was on a different CPU, it shoshould be migrated with the * old base locked to prevent other operations proceeding with the * wrong base locked. see lock_timer_base (). */# Lock base = lock_timer_base (timer, & flags); if (base! = New_base) {timer-> flags | = TIMER_MIGRATING; raw_spin_unlock (& base-> lock); base = new_base; raw_spin_lock (& base-> lock ); WRITE_ONCE (timer-> flags, (timer-> flags &~ TIMER_BASEMASK) | cpu) ;}# the base time may not be accurate if the cpu is in idle due to NOHZ or has just been out of idle, therefore, the system checks whether to adjust forward_timer_base (base); debug_activate (timer, timer-> expires); # Add the timeinternal_add_timer (base, timer) to the timer_base of the cpu specified by the parameter ); # unlock raw_spin_unlock_irqrestore (& base-> lock, flags );}

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.