Skip to content

Commit 11a9fe0

Browse files
anna-marialxingomolnar
authored andcommitted
hrtimer: Make hrtimer_reprogramm() unconditional
hrtimer_reprogram() needs to be available unconditionally for softirq based hrtimers. Move the function and all required struct members out of the CONFIG_HIGH_RES_TIMERS #ifdef. There is no functional change because hrtimer_reprogram() is only invoked when hrtimer_cpu_base.hres_active is true. Making it unconditional increases the text size for the CONFIG_HIGH_RES_TIMERS=n case, but avoids replication of that code for the upcoming softirq based hrtimers support. Signed-off-by: Anna-Maria Gleixner <anna-maria@linutronix.de> Cc: Christoph Hellwig <hch@lst.de> Cc: John Stultz <john.stultz@linaro.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: keescook@chromium.org Link: http://lkml.kernel.org/r/20171221104205.7269-18-anna-maria@linutronix.de Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent eb27926 commit 11a9fe0

2 files changed

Lines changed: 65 additions & 70 deletions

File tree

‎include/linux/hrtimer.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ struct hrtimer_cpu_base {
182182
unsigned int cpu;
183183
unsigned int active_bases;
184184
unsigned int clock_was_set_seq;
185-
unsigned int hres_active : 1;
186-
#ifdef CONFIG_HIGH_RES_TIMERS
187-
unsigned int in_hrtirq : 1,
185+
unsigned int hres_active : 1,
186+
in_hrtirq : 1,
188187
hang_detected : 1;
188+
#ifdef CONFIG_HIGH_RES_TIMERS
189189
unsigned int nr_events;
190190
unsigned short nr_retries;
191191
unsigned short nr_hangs;

‎kernel/time/hrtimer.c‎

Lines changed: 62 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -581,68 +581,6 @@ hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal)
581581
tick_program_event(cpu_base->expires_next, 1);
582582
}
583583

584-
/*
585-
* When a timer is enqueued and expires earlier than the already enqueued
586-
* timers, we have to check, whether it expires earlier than the timer for
587-
* which the clock event device was armed.
588-
*
589-
* Called with interrupts disabled and base->cpu_base.lock held
590-
*/
591-
static void hrtimer_reprogram(struct hrtimer *timer,
592-
struct hrtimer_clock_base *base)
593-
{
594-
struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);
595-
ktime_t expires = ktime_sub(hrtimer_get_expires(timer), base->offset);
596-
597-
WARN_ON_ONCE(hrtimer_get_expires_tv64(timer) < 0);
598-
599-
/*
600-
* If the timer is not on the current cpu, we cannot reprogram
601-
* the other cpus clock event device.
602-
*/
603-
if (base->cpu_base != cpu_base)
604-
return;
605-
606-
/*
607-
* If the hrtimer interrupt is running, then it will
608-
* reevaluate the clock bases and reprogram the clock event
609-
* device. The callbacks are always executed in hard interrupt
610-
* context so we don't need an extra check for a running
611-
* callback.
612-
*/
613-
if (cpu_base->in_hrtirq)
614-
return;
615-
616-
/*
617-
* CLOCK_REALTIME timer might be requested with an absolute
618-
* expiry time which is less than base->offset. Set it to 0.
619-
*/
620-
if (expires < 0)
621-
expires = 0;
622-
623-
if (expires >= cpu_base->expires_next)
624-
return;
625-
626-
/* Update the pointer to the next expiring timer */
627-
cpu_base->next_timer = timer;
628-
629-
/*
630-
* If a hang was detected in the last timer interrupt then we
631-
* do not schedule a timer which is earlier than the expiry
632-
* which we enforced in the hang detection. We want the system
633-
* to make progress.
634-
*/
635-
if (cpu_base->hang_detected)
636-
return;
637-
638-
/*
639-
* Program the timer hardware. We enforce the expiry for
640-
* events which are already in the past.
641-
*/
642-
cpu_base->expires_next = expires;
643-
tick_program_event(expires, 1);
644-
}
645-
646584
/*
647585
* Retrigger next event is called after clock was set
648586
*
@@ -703,15 +641,72 @@ static inline int hrtimer_is_hres_enabled(void) { return 0; }
703641
static inline void hrtimer_switch_to_hres(void) { }
704642
static inline void
705643
hrtimer_force_reprogram(struct hrtimer_cpu_base *base, int skip_equal) { }
706-
static inline int hrtimer_reprogram(struct hrtimer *timer,
707-
struct hrtimer_clock_base *base)
708-
{
709-
return 0;
710-
}
711644
static inline void retrigger_next_event(void *arg) { }
712645

713646
#endif /* CONFIG_HIGH_RES_TIMERS */
714647

648+
/*
649+
* When a timer is enqueued and expires earlier than the already enqueued
650+
* timers, we have to check, whether it expires earlier than the timer for
651+
* which the clock event device was armed.
652+
*
653+
* Called with interrupts disabled and base->cpu_base.lock held
654+
*/
655+
static void hrtimer_reprogram(struct hrtimer *timer,
656+
struct hrtimer_clock_base *base)
657+
{
658+
struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);
659+
ktime_t expires = ktime_sub(hrtimer_get_expires(timer), base->offset);
660+
661+
WARN_ON_ONCE(hrtimer_get_expires_tv64(timer) < 0);
662+
663+
/*
664+
* If the timer is not on the current cpu, we cannot reprogram
665+
* the other cpus clock event device.
666+
*/
667+
if (base->cpu_base != cpu_base)
668+
return;
669+
670+
/*
671+
* If the hrtimer interrupt is running, then it will
672+
* reevaluate the clock bases and reprogram the clock event
673+
* device. The callbacks are always executed in hard interrupt
674+
* context so we don't need an extra check for a running
675+
* callback.
676+
*/
677+
if (cpu_base->in_hrtirq)
678+
return;
679+
680+
/*
681+
* CLOCK_REALTIME timer might be requested with an absolute
682+
* expiry time which is less than base->offset. Set it to 0.
683+
*/
684+
if (expires < 0)
685+
expires = 0;
686+
687+
if (expires >= cpu_base->expires_next)
688+
return;
689+
690+
/* Update the pointer to the next expiring timer */
691+
cpu_base->next_timer = timer;
692+
693+
/*
694+
* If a hang was detected in the last timer interrupt then we
695+
* do not schedule a timer which is earlier than the expiry
696+
* which we enforced in the hang detection. We want the system
697+
* to make progress.
698+
*/
699+
if (cpu_base->hang_detected)
700+
return;
701+
702+
/*
703+
* Program the timer hardware. We enforce the expiry for
704+
* events which are already in the past.
705+
*/
706+
cpu_base->expires_next = expires;
707+
tick_program_event(expires, 1);
708+
}
709+
715710
/*
716711
* Clock realtime was set
717712
*

0 commit comments

Comments
 (0)