Skip to content

Commit b750586

Browse files
a-darwishPeter Zijlstra
authored andcommitted
sched: tasks: Use sequence counter with associated 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_spinlock_t data type, which allows to associate a spinlock with the sequence counter. This enables lockdep to verify that the 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 cd29f22 commit b750586

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

include/linux/sched.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ struct task_struct {
10501050
/* Protected by ->alloc_lock: */
10511051
nodemask_t mems_allowed;
10521052
/* Seqence number to catch updates: */
1053-
seqcount_t mems_allowed_seq;
1053+
seqcount_spinlock_t mems_allowed_seq;
10541054
int cpuset_mem_spread_rotor;
10551055
int cpuset_slab_spread_rotor;
10561056
#endif

init/init_task.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ struct task_struct init_task
154154
.trc_holdout_list = LIST_HEAD_INIT(init_task.trc_holdout_list),
155155
#endif
156156
#ifdef CONFIG_CPUSETS
157-
.mems_allowed_seq = SEQCNT_ZERO(init_task.mems_allowed_seq),
157+
.mems_allowed_seq = SEQCNT_SPINLOCK_ZERO(init_task.mems_allowed_seq,
158+
&init_task.alloc_lock),
158159
#endif
159160
#ifdef CONFIG_RT_MUTEXES
160161
.pi_waiters = RB_ROOT_CACHED,

kernel/fork.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2032,7 +2032,7 @@ static __latent_entropy struct task_struct *copy_process(
20322032
#ifdef CONFIG_CPUSETS
20332033
p->cpuset_mem_spread_rotor = NUMA_NO_NODE;
20342034
p->cpuset_slab_spread_rotor = NUMA_NO_NODE;
2035-
seqcount_init(&p->mems_allowed_seq);
2035+
seqcount_spinlock_init(&p->mems_allowed_seq, &p->alloc_lock);
20362036
#endif
20372037
#ifdef CONFIG_TRACE_IRQFLAGS
20382038
p->irq_events = 0;

0 commit comments

Comments
 (0)