Skip to content

Commit 01fe8a3

Browse files
melverPeter Zijlstra
authored andcommitted
locking/percpu-rwsem: Add percpu_is_write_locked() and percpu_is_read_locked()
Implement simple accessors to probe percpu-rwsem's locked state: percpu_is_write_locked(), percpu_is_read_locked(). Signed-off-by: Marco Elver <elver@google.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Dmitry Vyukov <dvyukov@google.com> Acked-by: Ian Rogers <irogers@google.com> Link: https://lore.kernel.org/r/20220829124719.675715-11-elver@google.com
1 parent f95e5a3 commit 01fe8a3

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

include/linux/percpu-rwsem.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,15 @@ static inline void percpu_up_read(struct percpu_rw_semaphore *sem)
121121
preempt_enable();
122122
}
123123

124+
extern bool percpu_is_read_locked(struct percpu_rw_semaphore *);
124125
extern void percpu_down_write(struct percpu_rw_semaphore *);
125126
extern void percpu_up_write(struct percpu_rw_semaphore *);
126127

128+
static inline bool percpu_is_write_locked(struct percpu_rw_semaphore *sem)
129+
{
130+
return atomic_read(&sem->block);
131+
}
132+
127133
extern int __percpu_init_rwsem(struct percpu_rw_semaphore *,
128134
const char *, struct lock_class_key *);
129135

kernel/locking/percpu-rwsem.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ EXPORT_SYMBOL_GPL(__percpu_down_read);
192192
__sum; \
193193
})
194194

195+
bool percpu_is_read_locked(struct percpu_rw_semaphore *sem)
196+
{
197+
return per_cpu_sum(*sem->read_count) != 0 && !atomic_read(&sem->block);
198+
}
199+
EXPORT_SYMBOL_GPL(percpu_is_read_locked);
200+
195201
/*
196202
* Return true if the modular sum of the sem->read_count per-CPU variable is
197203
* zero. If this sum is zero, then it is stable due to the fact that if any

0 commit comments

Comments
 (0)