Skip to content

Commit f3e3620

Browse files
namhyungIngo Molnar
authored andcommitted
locking/percpu-rwsem: Trigger contention tracepoints only if contended
We mistakenly always fire lock contention tracepoints in the writer path, while it should be conditional on the trylock result. Signed-off-by: Namhyung Kim <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Waiman Long <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f22f713 commit f3e3620

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

kernel/locking/percpu-rwsem.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ static bool readers_active_check(struct percpu_rw_semaphore *sem)
223223

224224
void __sched percpu_down_write(struct percpu_rw_semaphore *sem)
225225
{
226+
bool contended = false;
227+
226228
might_sleep();
227229
rwsem_acquire(&sem->dep_map, 0, 0, _RET_IP_);
228-
trace_contention_begin(sem, LCB_F_PERCPU | LCB_F_WRITE);
229230

230231
/* Notify readers to take the slow path. */
231232
rcu_sync_enter(&sem->rss);
@@ -234,8 +235,11 @@ void __sched percpu_down_write(struct percpu_rw_semaphore *sem)
234235
* Try set sem->block; this provides writer-writer exclusion.
235236
* Having sem->block set makes new readers block.
236237
*/
237-
if (!__percpu_down_write_trylock(sem))
238+
if (!__percpu_down_write_trylock(sem)) {
239+
trace_contention_begin(sem, LCB_F_PERCPU | LCB_F_WRITE);
238240
percpu_rwsem_wait(sem, /* .reader = */ false);
241+
contended = true;
242+
}
239243

240244
/* smp_mb() implied by __percpu_down_write_trylock() on success -- D matches A */
241245

@@ -247,7 +251,8 @@ void __sched percpu_down_write(struct percpu_rw_semaphore *sem)
247251

248252
/* Wait for all active readers to complete. */
249253
rcuwait_wait_event(&sem->writer, readers_active_check(sem), TASK_UNINTERRUPTIBLE);
250-
trace_contention_end(sem, 0);
254+
if (contended)
255+
trace_contention_end(sem, 0);
251256
}
252257
EXPORT_SYMBOL_GPL(percpu_down_write);
253258

0 commit comments

Comments
 (0)