@@ -66,7 +66,8 @@ static struct tracer_flags blk_tracer_flags = {
66
66
};
67
67
68
68
/* Global reference count of probes */
69
- static atomic_t blk_probes_ref = ATOMIC_INIT (0 );
69
+ static DEFINE_MUTEX (blk_probe_mutex );
70
+ static int blk_probes_ref ;
70
71
71
72
static void blk_register_tracepoints (void );
72
73
static void blk_unregister_tracepoints (void );
@@ -329,11 +330,26 @@ static void blk_trace_free(struct blk_trace *bt)
329
330
kfree (bt );
330
331
}
331
332
333
+ static void get_probe_ref (void )
334
+ {
335
+ mutex_lock (& blk_probe_mutex );
336
+ if (++ blk_probes_ref == 1 )
337
+ blk_register_tracepoints ();
338
+ mutex_unlock (& blk_probe_mutex );
339
+ }
340
+
341
+ static void put_probe_ref (void )
342
+ {
343
+ mutex_lock (& blk_probe_mutex );
344
+ if (!-- blk_probes_ref )
345
+ blk_unregister_tracepoints ();
346
+ mutex_unlock (& blk_probe_mutex );
347
+ }
348
+
332
349
static void blk_trace_cleanup (struct blk_trace * bt )
333
350
{
334
351
blk_trace_free (bt );
335
- if (atomic_dec_and_test (& blk_probes_ref ))
336
- blk_unregister_tracepoints ();
352
+ put_probe_ref ();
337
353
}
338
354
339
355
int blk_trace_remove (struct request_queue * q )
@@ -538,8 +554,7 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
538
554
if (cmpxchg (& q -> blk_trace , NULL , bt ))
539
555
goto err ;
540
556
541
- if (atomic_inc_return (& blk_probes_ref ) == 1 )
542
- blk_register_tracepoints ();
557
+ get_probe_ref ();
543
558
544
559
ret = 0 ;
545
560
err :
@@ -1558,9 +1573,7 @@ static int blk_trace_remove_queue(struct request_queue *q)
1558
1573
if (bt == NULL )
1559
1574
return - EINVAL ;
1560
1575
1561
- if (atomic_dec_and_test (& blk_probes_ref ))
1562
- blk_unregister_tracepoints ();
1563
-
1576
+ put_probe_ref ();
1564
1577
blk_trace_free (bt );
1565
1578
return 0 ;
1566
1579
}
@@ -1591,8 +1604,7 @@ static int blk_trace_setup_queue(struct request_queue *q,
1591
1604
if (cmpxchg (& q -> blk_trace , NULL , bt ))
1592
1605
goto free_bt ;
1593
1606
1594
- if (atomic_inc_return (& blk_probes_ref ) == 1 )
1595
- blk_register_tracepoints ();
1607
+ get_probe_ref ();
1596
1608
return 0 ;
1597
1609
1598
1610
free_bt :
0 commit comments