Skip to content

Commit b14bca9

Browse files
Peter ZijlstraKAGA-KOKO
authored andcommitted
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 <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 627ef5a commit b14bca9

File tree

1 file changed

+29
-43
lines changed

1 file changed

+29
-43
lines changed

kernel/time/hrtimer.c

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -652,21 +652,24 @@ static inline int hrtimer_hres_active(void)
652652
return __hrtimer_hres_active(this_cpu_ptr(&hrtimer_bases));
653653
}
654654

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-
*/
660655
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)
662658
{
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;
664665

665-
expires_next = hrtimer_update_next_event(cpu_base);
666+
if (expires_next > cpu_base->expires_next)
667+
return;
666668

667669
if (skip_equal && expires_next == cpu_base->expires_next)
668670
return;
669671

672+
cpu_base->next_timer = next_timer;
670673
cpu_base->expires_next = expires_next;
671674

672675
/*
@@ -689,7 +692,23 @@ hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal)
689692
if (!__hrtimer_hres_active(cpu_base) || cpu_base->hang_detected)
690693
return;
691694

692-
tick_program_event(cpu_base->expires_next, 1);
695+
tick_program_event(expires_next, 1);
696+
}
697+
698+
/*
699+
* Reprogram the event source with checking both queues for the
700+
* next event
701+
* Called with interrupts disabled and base->lock held
702+
*/
703+
static void
704+
hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal)
705+
{
706+
ktime_t expires_next;
707+
708+
expires_next = hrtimer_update_next_event(cpu_base);
709+
710+
__hrtimer_reprogram(cpu_base, skip_equal, cpu_base->next_timer,
711+
expires_next);
693712
}
694713

695714
/* High resolution timer related functions */
@@ -835,40 +854,7 @@ static void hrtimer_reprogram(struct hrtimer *timer, bool reprogram)
835854
if (base->cpu_base != cpu_base)
836855
return;
837856

838-
/*
839-
* If the hrtimer interrupt is running, then it will
840-
* reevaluate the clock bases and reprogram the clock event
841-
* device. The callbacks are always executed in hard interrupt
842-
* context so we don't need an extra check for a running
843-
* callback.
844-
*/
845-
if (cpu_base->in_hrtirq)
846-
return;
847-
848-
if (expires >= cpu_base->expires_next)
849-
return;
850-
851-
/* Update the pointer to the next expiring timer */
852-
cpu_base->next_timer = timer;
853-
cpu_base->expires_next = expires;
854-
855-
/*
856-
* If hres is not active, hardware does not have to be
857-
* programmed yet.
858-
*
859-
* If a hang was detected in the last timer interrupt then we
860-
* do not schedule a timer which is earlier than the expiry
861-
* which we enforced in the hang detection. We want the system
862-
* to make progress.
863-
*/
864-
if (!__hrtimer_hres_active(cpu_base) || cpu_base->hang_detected)
865-
return;
866-
867-
/*
868-
* Program the timer hardware. We enforce the expiry for
869-
* events which are already in the past.
870-
*/
871-
tick_program_event(expires, 1);
857+
__hrtimer_reprogram(cpu_base, true, timer, expires);
872858
}
873859

874860
/*

0 commit comments

Comments
 (0)