@@ -246,9 +246,24 @@ cycle_t ftrace_now(int cpu)
246246 return ts ;
247247}
248248
249+ /**
250+ * tracing_is_enabled - Show if global_trace has been disabled
251+ *
252+ * Shows if the global trace has been enabled or not. It uses the
253+ * mirror flag "buffer_disabled" to be used in fast paths such as for
254+ * the irqsoff tracer. But it may be inaccurate due to races. If you
255+ * need to know the accurate state, use tracing_is_on() which is a little
256+ * slower, but accurate.
257+ */
249258int tracing_is_enabled (void )
250259{
251- return tracing_is_on ();
260+ /*
261+ * For quick access (irqsoff uses this in fast path), just
262+ * return the mirror variable of the state of the ring buffer.
263+ * It's a little racy, but we don't really care.
264+ */
265+ smp_rmb ();
266+ return !global_trace .buffer_disabled ;
252267}
253268
254269/*
@@ -361,6 +376,23 @@ unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
361376 TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE |
362377 TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS | TRACE_ITER_FUNCTION ;
363378
379+ void tracer_tracing_on (struct trace_array * tr )
380+ {
381+ if (tr -> trace_buffer .buffer )
382+ ring_buffer_record_on (tr -> trace_buffer .buffer );
383+ /*
384+ * This flag is looked at when buffers haven't been allocated
385+ * yet, or by some tracers (like irqsoff), that just want to
386+ * know if the ring buffer has been disabled, but it can handle
387+ * races of where it gets disabled but we still do a record.
388+ * As the check is in the fast path of the tracers, it is more
389+ * important to be fast than accurate.
390+ */
391+ tr -> buffer_disabled = 0 ;
392+ /* Make the flag seen by readers */
393+ smp_wmb ();
394+ }
395+
364396/**
365397 * tracing_on - enable tracing buffers
366398 *
@@ -369,15 +401,7 @@ unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
369401 */
370402void tracing_on (void )
371403{
372- if (global_trace .trace_buffer .buffer )
373- ring_buffer_record_on (global_trace .trace_buffer .buffer );
374- /*
375- * This flag is only looked at when buffers haven't been
376- * allocated yet. We don't really care about the race
377- * between setting this flag and actually turning
378- * on the buffer.
379- */
380- global_trace .buffer_disabled = 0 ;
404+ tracer_tracing_on (& global_trace );
381405}
382406EXPORT_SYMBOL_GPL (tracing_on );
383407
@@ -571,6 +595,23 @@ void tracing_snapshot_alloc(void)
571595EXPORT_SYMBOL_GPL (tracing_snapshot_alloc );
572596#endif /* CONFIG_TRACER_SNAPSHOT */
573597
598+ void tracer_tracing_off (struct trace_array * tr )
599+ {
600+ if (tr -> trace_buffer .buffer )
601+ ring_buffer_record_off (tr -> trace_buffer .buffer );
602+ /*
603+ * This flag is looked at when buffers haven't been allocated
604+ * yet, or by some tracers (like irqsoff), that just want to
605+ * know if the ring buffer has been disabled, but it can handle
606+ * races of where it gets disabled but we still do a record.
607+ * As the check is in the fast path of the tracers, it is more
608+ * important to be fast than accurate.
609+ */
610+ tr -> buffer_disabled = 1 ;
611+ /* Make the flag seen by readers */
612+ smp_wmb ();
613+ }
614+
574615/**
575616 * tracing_off - turn off tracing buffers
576617 *
@@ -581,26 +622,29 @@ EXPORT_SYMBOL_GPL(tracing_snapshot_alloc);
581622 */
582623void tracing_off (void )
583624{
584- if (global_trace .trace_buffer .buffer )
585- ring_buffer_record_off (global_trace .trace_buffer .buffer );
586- /*
587- * This flag is only looked at when buffers haven't been
588- * allocated yet. We don't really care about the race
589- * between setting this flag and actually turning
590- * on the buffer.
591- */
592- global_trace .buffer_disabled = 1 ;
625+ tracer_tracing_off (& global_trace );
593626}
594627EXPORT_SYMBOL_GPL (tracing_off );
595628
629+ /**
630+ * tracer_tracing_is_on - show real state of ring buffer enabled
631+ * @tr : the trace array to know if ring buffer is enabled
632+ *
633+ * Shows real state of the ring buffer if it is enabled or not.
634+ */
635+ int tracer_tracing_is_on (struct trace_array * tr )
636+ {
637+ if (tr -> trace_buffer .buffer )
638+ return ring_buffer_record_is_on (tr -> trace_buffer .buffer );
639+ return !tr -> buffer_disabled ;
640+ }
641+
596642/**
597643 * tracing_is_on - show state of ring buffers enabled
598644 */
599645int tracing_is_on (void )
600646{
601- if (global_trace .trace_buffer .buffer )
602- return ring_buffer_record_is_on (global_trace .trace_buffer .buffer );
603- return !global_trace .buffer_disabled ;
647+ return tracer_tracing_is_on (& global_trace );
604648}
605649EXPORT_SYMBOL_GPL (tracing_is_on );
606650
@@ -4060,7 +4104,7 @@ static int tracing_wait_pipe(struct file *filp)
40604104 *
40614105 * iter->pos will be 0 if we haven't read anything.
40624106 */
4063- if (!tracing_is_enabled () && iter -> pos )
4107+ if (!tracing_is_on () && iter -> pos )
40644108 break ;
40654109 }
40664110
@@ -5772,15 +5816,10 @@ rb_simple_read(struct file *filp, char __user *ubuf,
57725816 size_t cnt , loff_t * ppos )
57735817{
57745818 struct trace_array * tr = filp -> private_data ;
5775- struct ring_buffer * buffer = tr -> trace_buffer .buffer ;
57765819 char buf [64 ];
57775820 int r ;
57785821
5779- if (buffer )
5780- r = ring_buffer_record_is_on (buffer );
5781- else
5782- r = 0 ;
5783-
5822+ r = tracer_tracing_is_on (tr );
57845823 r = sprintf (buf , "%d\n" , r );
57855824
57865825 return simple_read_from_buffer (ubuf , cnt , ppos , buf , r );
@@ -5802,11 +5841,11 @@ rb_simple_write(struct file *filp, const char __user *ubuf,
58025841 if (buffer ) {
58035842 mutex_lock (& trace_types_lock );
58045843 if (val ) {
5805- ring_buffer_record_on ( buffer );
5844+ tracer_tracing_on ( tr );
58065845 if (tr -> current_trace -> start )
58075846 tr -> current_trace -> start (tr );
58085847 } else {
5809- ring_buffer_record_off ( buffer );
5848+ tracer_tracing_off ( tr );
58105849 if (tr -> current_trace -> stop )
58115850 tr -> current_trace -> stop (tr );
58125851 }
0 commit comments