@@ -223,9 +223,10 @@ static bool readers_active_check(struct percpu_rw_semaphore *sem)
223
223
224
224
void __sched percpu_down_write (struct percpu_rw_semaphore * sem )
225
225
{
226
+ bool contended = false;
227
+
226
228
might_sleep ();
227
229
rwsem_acquire (& sem -> dep_map , 0 , 0 , _RET_IP_ );
228
- trace_contention_begin (sem , LCB_F_PERCPU | LCB_F_WRITE );
229
230
230
231
/* Notify readers to take the slow path. */
231
232
rcu_sync_enter (& sem -> rss );
@@ -234,8 +235,11 @@ void __sched percpu_down_write(struct percpu_rw_semaphore *sem)
234
235
* Try set sem->block; this provides writer-writer exclusion.
235
236
* Having sem->block set makes new readers block.
236
237
*/
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 );
238
240
percpu_rwsem_wait (sem , /* .reader = */ false);
241
+ contended = true;
242
+ }
239
243
240
244
/* smp_mb() implied by __percpu_down_write_trylock() on success -- D matches A */
241
245
@@ -247,7 +251,8 @@ void __sched percpu_down_write(struct percpu_rw_semaphore *sem)
247
251
248
252
/* Wait for all active readers to complete. */
249
253
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 );
251
256
}
252
257
EXPORT_SYMBOL_GPL (percpu_down_write );
253
258
0 commit comments