Skip to content

Commit 2287d86

Browse files
Sebastian Andrzej SiewiorKAGA-KOKO
authored andcommitted
timers: Make the cpu base lock raw
The timers cpu base lock could not be converted to a raw spinlock becaue the lock held time was non-deterministic due to cascading and long lasting timer wheel traversals. The rework of the timer wheel to the new non-cascading model removed also the wheel traversals and the lock held times are deterministic now. This allows to make the lock raw and thereby unbreaks NOHz* on preempt-RT. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Link: http://lkml.kernel.org/r/20170627161538.30257-1-bigeasy@linutronix.de Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent f5b8167 commit 2287d86

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

‎kernel/time/timer.c‎

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ EXPORT_SYMBOL(jiffies_64);
195195
#endif
196196

197197
struct timer_base {
198-
spinlock_t lock;
198+
raw_spinlock_t lock;
199199
struct timer_list *running_timer;
200200
unsigned long clk;
201201
unsigned long next_expiry;
@@ -913,10 +913,10 @@ static struct timer_base *lock_timer_base(struct timer_list *timer,
913913

914914
if (!(tf & TIMER_MIGRATING)) {
915915
base = get_timer_base(tf);
916-
spin_lock_irqsave(&base->lock, *flags);
916+
raw_spin_lock_irqsave(&base->lock, *flags);
917917
if (timer->flags == tf)
918918
return base;
919-
spin_unlock_irqrestore(&base->lock, *flags);
919+
raw_spin_unlock_irqrestore(&base->lock, *flags);
920920
}
921921
cpu_relax();
922922
}
@@ -986,9 +986,9 @@ __mod_timer(struct timer_list *timer, unsigned long expires, bool pending_only)
986986
/* See the comment in lock_timer_base() */
987987
timer->flags |= TIMER_MIGRATING;
988988

989-
spin_unlock(&base->lock);
989+
raw_spin_unlock(&base->lock);
990990
base = new_base;
991-
spin_lock(&base->lock);
991+
raw_spin_lock(&base->lock);
992992
WRITE_ONCE(timer->flags,
993993
(timer->flags & ~TIMER_BASEMASK) | base->cpu);
994994
}
@@ -1013,7 +1013,7 @@ __mod_timer(struct timer_list *timer, unsigned long expires, bool pending_only)
10131013
}
10141014

10151015
out_unlock:
1016-
spin_unlock_irqrestore(&base->lock, flags);
1016+
raw_spin_unlock_irqrestore(&base->lock, flags);
10171017

10181018
return ret;
10191019
}
@@ -1106,16 +1106,16 @@ void add_timer_on(struct timer_list *timer, int cpu)
11061106
if (base != new_base) {
11071107
timer->flags |= TIMER_MIGRATING;
11081108

1109-
spin_unlock(&base->lock);
1109+
raw_spin_unlock(&base->lock);
11101110
base = new_base;
1111-
spin_lock(&base->lock);
1111+
raw_spin_lock(&base->lock);
11121112
WRITE_ONCE(timer->flags,
11131113
(timer->flags & ~TIMER_BASEMASK) | cpu);
11141114
}
11151115

11161116
debug_activate(timer, timer->expires);
11171117
internal_add_timer(base, timer);
1118-
spin_unlock_irqrestore(&base->lock, flags);
1118+
raw_spin_unlock_irqrestore(&base->lock, flags);
11191119
}
11201120
EXPORT_SYMBOL_GPL(add_timer_on);
11211121

@@ -1141,7 +1141,7 @@ int del_timer(struct timer_list *timer)
11411141
if (timer_pending(timer)) {
11421142
base = lock_timer_base(timer, &flags);
11431143
ret = detach_if_pending(timer, base, true);
1144-
spin_unlock_irqrestore(&base->lock, flags);
1144+
raw_spin_unlock_irqrestore(&base->lock, flags);
11451145
}
11461146

11471147
return ret;
@@ -1168,7 +1168,7 @@ int try_to_del_timer_sync(struct timer_list *timer)
11681168
if (base->running_timer != timer)
11691169
ret = detach_if_pending(timer, base, true);
11701170

1171-
spin_unlock_irqrestore(&base->lock, flags);
1171+
raw_spin_unlock_irqrestore(&base->lock, flags);
11721172

11731173
return ret;
11741174
}
@@ -1299,13 +1299,13 @@ static void expire_timers(struct timer_base *base, struct hlist_head *head)
12991299
data = timer->data;
13001300

13011301
if (timer->flags & TIMER_IRQSAFE) {
1302-
spin_unlock(&base->lock);
1302+
raw_spin_unlock(&base->lock);
13031303
call_timer_fn(timer, fn, data);
1304-
spin_lock(&base->lock);
1304+
raw_spin_lock(&base->lock);
13051305
} else {
1306-
spin_unlock_irq(&base->lock);
1306+
raw_spin_unlock_irq(&base->lock);
13071307
call_timer_fn(timer, fn, data);
1308-
spin_lock_irq(&base->lock);
1308+
raw_spin_lock_irq(&base->lock);
13091309
}
13101310
}
13111311
}
@@ -1474,7 +1474,7 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
14741474
if (cpu_is_offline(smp_processor_id()))
14751475
return expires;
14761476

1477-
spin_lock(&base->lock);
1477+
raw_spin_lock(&base->lock);
14781478
nextevt = __next_timer_interrupt(base);
14791479
is_max_delta = (nextevt == base->clk + NEXT_TIMER_MAX_DELTA);
14801480
base->next_expiry = nextevt;
@@ -1502,7 +1502,7 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
15021502
if ((expires - basem) > TICK_NSEC)
15031503
base->is_idle = true;
15041504
}
1505-
spin_unlock(&base->lock);
1505+
raw_spin_unlock(&base->lock);
15061506

15071507
return cmp_next_hrtimer_event(basem, expires);
15081508
}
@@ -1590,7 +1590,7 @@ static inline void __run_timers(struct timer_base *base)
15901590
if (!time_after_eq(jiffies, base->clk))
15911591
return;
15921592

1593-
spin_lock_irq(&base->lock);
1593+
raw_spin_lock_irq(&base->lock);
15941594

15951595
while (time_after_eq(jiffies, base->clk)) {
15961596

@@ -1601,7 +1601,7 @@ static inline void __run_timers(struct timer_base *base)
16011601
expire_timers(base, heads + levels);
16021602
}
16031603
base->running_timer = NULL;
1604-
spin_unlock_irq(&base->lock);
1604+
raw_spin_unlock_irq(&base->lock);
16051605
}
16061606

16071607
/*
@@ -1786,16 +1786,16 @@ int timers_dead_cpu(unsigned int cpu)
17861786
* The caller is globally serialized and nobody else
17871787
* takes two locks at once, deadlock is not possible.
17881788
*/
1789-
spin_lock_irq(&new_base->lock);
1790-
spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING);
1789+
raw_spin_lock_irq(&new_base->lock);
1790+
raw_spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING);
17911791

17921792
BUG_ON(old_base->running_timer);
17931793

17941794
for (i = 0; i < WHEEL_SIZE; i++)
17951795
migrate_timer_list(new_base, old_base->vectors + i);
17961796

1797-
spin_unlock(&old_base->lock);
1798-
spin_unlock_irq(&new_base->lock);
1797+
raw_spin_unlock(&old_base->lock);
1798+
raw_spin_unlock_irq(&new_base->lock);
17991799
put_cpu_ptr(&timer_bases);
18001800
}
18011801
return 0;
@@ -1811,7 +1811,7 @@ static void __init init_timer_cpu(int cpu)
18111811
for (i = 0; i < NR_BASES; i++) {
18121812
base = per_cpu_ptr(&timer_bases[i], cpu);
18131813
base->cpu = cpu;
1814-
spin_lock_init(&base->lock);
1814+
raw_spin_lock_init(&base->lock);
18151815
base->clk = jiffies;
18161816
}
18171817
}

0 commit comments

Comments
 (0)