Skip to content

Commit af5a06b

Browse files
a-darwishPeter Zijlstra
authored andcommitted
hrtimer: Use sequence counter with associated raw spinlock
A sequence counter write side critical section must be protected by some form of locking to serialize writers. A plain seqcount_t does not contain the information of which lock must be held when entering a write side critical section. Use the new seqcount_raw_spinlock_t data type, which allows to associate a raw spinlock with the sequence counter. This enables lockdep to verify that the raw spinlock used for writer serialization is held when the write side critical section is entered. If lockdep is disabled this lock association is compiled out and has neither storage size nor runtime overhead. Signed-off-by: Ahmed S. Darwish <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 5c73b9a commit af5a06b

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

include/linux/hrtimer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ struct hrtimer_clock_base {
159159
struct hrtimer_cpu_base *cpu_base;
160160
unsigned int index;
161161
clockid_t clockid;
162-
seqcount_t seq;
162+
seqcount_raw_spinlock_t seq;
163163
struct hrtimer *running;
164164
struct timerqueue_head active;
165165
ktime_t (*get_time)(void);

kernel/time/hrtimer.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ static const int hrtimer_clock_to_base_table[MAX_CLOCKS] = {
135135
* timer->base->cpu_base
136136
*/
137137
static struct hrtimer_cpu_base migration_cpu_base = {
138-
.clock_base = { { .cpu_base = &migration_cpu_base, }, },
138+
.clock_base = { {
139+
.cpu_base = &migration_cpu_base,
140+
.seq = SEQCNT_RAW_SPINLOCK_ZERO(migration_cpu_base.seq,
141+
&migration_cpu_base.lock),
142+
}, },
139143
};
140144

141145
#define migration_base migration_cpu_base.clock_base[0]
@@ -1998,8 +2002,11 @@ int hrtimers_prepare_cpu(unsigned int cpu)
19982002
int i;
19992003

20002004
for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
2001-
cpu_base->clock_base[i].cpu_base = cpu_base;
2002-
timerqueue_init_head(&cpu_base->clock_base[i].active);
2005+
struct hrtimer_clock_base *clock_b = &cpu_base->clock_base[i];
2006+
2007+
clock_b->cpu_base = cpu_base;
2008+
seqcount_raw_spinlock_init(&clock_b->seq, &cpu_base->lock);
2009+
timerqueue_init_head(&clock_b->active);
20032010
}
20042011

20052012
cpu_base->cpu = cpu;

0 commit comments

Comments
 (0)