Skip to content

Commit eb27926

Browse files
anna-marialxingomolnar
authored andcommitted
hrtimer: Make hrtimer_cpu_base.next_timer handling unconditional
hrtimer_cpu_base.next_timer stores the pointer to the next expiring timer in a CPU base. This pointer cannot be dereferenced and is solely used to check whether a hrtimer which is removed is the hrtimer which is the first to expire in the CPU base. If this is the case, then the timer hardware needs to be reprogrammed to avoid an extra interrupt for nothing. Again, this is conditional functionality, but there is no compelling reason to make this conditional. As a preparation, hrtimer_cpu_base.next_timer needs to be available unconditonally. Aside of that the upcoming support for softirq based hrtimers requires access to this pointer unconditionally as well, so our motivation is not entirely simplicity based. Make the update of hrtimer_cpu_base.next_timer unconditional and remove the #ifdef cruft. The impact on CONFIG_HIGH_RES_TIMERS=n && CONFIG_NOHZ=n is marginal as it's just a store on an already dirtied cacheline. No functional change. 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-17-anna-maria@linutronix.de Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 07a9a7e commit eb27926

2 files changed

Lines changed: 4 additions & 12 deletions

File tree

‎include/linux/hrtimer.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ enum hrtimer_base_type {
164164
* @hres_active: State of high resolution mode
165165
* @in_hrtirq: hrtimer_interrupt() is currently executing
166166
* @hang_detected: The last hrtimer interrupt detected a hang
167-
* @next_timer: Pointer to the first expiring timer
168167
* @nr_events: Total number of hrtimer interrupt events
169168
* @nr_retries: Total number of hrtimer interrupt retries
170169
* @nr_hangs: Total number of hrtimer interrupt hangs
171170
* @max_hang_time: Maximum time spent in hrtimer_interrupt
172171
* @expires_next: absolute time of the next event, is required for remote
173172
* hrtimer enqueue
173+
* @next_timer: Pointer to the first expiring timer
174174
* @clock_base: array of clock bases for this cpu
175175
*
176176
* Note: next_timer is just an optimization for __remove_hrtimer().
@@ -186,13 +186,13 @@ struct hrtimer_cpu_base {
186186
#ifdef CONFIG_HIGH_RES_TIMERS
187187
unsigned int in_hrtirq : 1,
188188
hang_detected : 1;
189-
struct hrtimer *next_timer;
190189
unsigned int nr_events;
191190
unsigned short nr_retries;
192191
unsigned short nr_hangs;
193192
unsigned int max_hang_time;
194193
#endif
195194
ktime_t expires_next;
195+
struct hrtimer *next_timer;
196196
struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES];
197197
} ____cacheline_aligned;
198198

‎kernel/time/hrtimer.c‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -459,21 +459,13 @@ __next_base(struct hrtimer_cpu_base *cpu_base, unsigned int *active)
459459
while ((base = __next_base((cpu_base), &(active))))
460460

461461
#if defined(CONFIG_NO_HZ_COMMON) || defined(CONFIG_HIGH_RES_TIMERS)
462-
static inline void hrtimer_update_next_timer(struct hrtimer_cpu_base *cpu_base,
463-
struct hrtimer *timer)
464-
{
465-
#ifdef CONFIG_HIGH_RES_TIMERS
466-
cpu_base->next_timer = timer;
467-
#endif
468-
}
469-
470462
static ktime_t __hrtimer_get_next_event(struct hrtimer_cpu_base *cpu_base)
471463
{
472464
struct hrtimer_clock_base *base;
473465
unsigned int active = cpu_base->active_bases;
474466
ktime_t expires, expires_next = KTIME_MAX;
475467

476-
hrtimer_update_next_timer(cpu_base, NULL);
468+
cpu_base->next_timer = NULL;
477469
for_each_active_base(base, cpu_base, active) {
478470
struct timerqueue_node *next;
479471
struct hrtimer *timer;
@@ -483,7 +475,7 @@ static ktime_t __hrtimer_get_next_event(struct hrtimer_cpu_base *cpu_base)
483475
expires = ktime_sub(hrtimer_get_expires(timer), base->offset);
484476
if (expires < expires_next) {
485477
expires_next = expires;
486-
hrtimer_update_next_timer(cpu_base, timer);
478+
cpu_base->next_timer = timer;
487479
}
488480
}
489481
/*

0 commit comments

Comments
 (0)