Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

hrtimer: Consolidate reprogramming code

This code is mostly duplicated. The redudant store in the force reprogram
case does no harm and the in hrtimer interrupt condition cannot be true for
the force reprogram invocations.

Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20210713135158.054424875@linutronix.de

authored by

Peter Zijlstra and committed by
Thomas Gleixner
b14bca97 627ef5ae

+29 -43
+29 -43
kernel/time/hrtimer.c
··· 652 652 return __hrtimer_hres_active(this_cpu_ptr(&hrtimer_bases)); 653 653 } 654 654 655 - /* 656 - * Reprogram the event source with checking both queues for the 657 - * next event 658 - * Called with interrupts disabled and base->lock held 659 - */ 660 655 static void 661 - hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal) 656 + __hrtimer_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal, 657 + struct hrtimer *next_timer, ktime_t expires_next) 662 658 { 663 - ktime_t expires_next; 659 + /* 660 + * If the hrtimer interrupt is running, then it will reevaluate the 661 + * clock bases and reprogram the clock event device. 662 + */ 663 + if (cpu_base->in_hrtirq) 664 + return; 664 665 665 - expires_next = hrtimer_update_next_event(cpu_base); 666 + if (expires_next > cpu_base->expires_next) 667 + return; 666 668 667 669 if (skip_equal && expires_next == cpu_base->expires_next) 668 670 return; 669 671 672 + cpu_base->next_timer = next_timer; 670 673 cpu_base->expires_next = expires_next; 671 674 672 675 /* ··· 692 689 if (!__hrtimer_hres_active(cpu_base) || cpu_base->hang_detected) 693 690 return; 694 691 695 - tick_program_event(cpu_base->expires_next, 1); 692 + tick_program_event(expires_next, 1); 693 + } 694 + 695 + /* 696 + * Reprogram the event source with checking both queues for the 697 + * next event 698 + * Called with interrupts disabled and base->lock held 699 + */ 700 + static void 701 + hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal) 702 + { 703 + ktime_t expires_next; 704 + 705 + expires_next = hrtimer_update_next_event(cpu_base); 706 + 707 + __hrtimer_reprogram(cpu_base, skip_equal, cpu_base->next_timer, 708 + expires_next); 696 709 } 697 710 698 711 /* High resolution timer related functions */ ··· 854 835 if (base->cpu_base != cpu_base) 855 836 return; 856 837 857 - /* 858 - * If the hrtimer interrupt is running, then it will 859 - * reevaluate the clock bases and reprogram the clock event 860 - * device. The callbacks are always executed in hard interrupt 861 - * context so we don't need an extra check for a running 862 - * callback. 863 - */ 864 - if (cpu_base->in_hrtirq) 865 - return; 866 - 867 - if (expires >= cpu_base->expires_next) 868 - return; 869 - 870 - /* Update the pointer to the next expiring timer */ 871 - cpu_base->next_timer = timer; 872 - cpu_base->expires_next = expires; 873 - 874 - /* 875 - * If hres is not active, hardware does not have to be 876 - * programmed yet. 877 - * 878 - * If a hang was detected in the last timer interrupt then we 879 - * do not schedule a timer which is earlier than the expiry 880 - * which we enforced in the hang detection. We want the system 881 - * to make progress. 882 - */ 883 - if (!__hrtimer_hres_active(cpu_base) || cpu_base->hang_detected) 884 - return; 885 - 886 - /* 887 - * Program the timer hardware. We enforce the expiry for 888 - * events which are already in the past. 889 - */ 890 - tick_program_event(expires, 1); 838 + __hrtimer_reprogram(cpu_base, true, timer, expires); 891 839 } 892 840 893 841 /*