@@ -226,9 +226,24 @@ cycle_t ftrace_now(int cpu)
226226 return ts ;
227227}
228228
229+ /**
230+ * tracing_is_enabled - Show if global_trace has been disabled
231+ *
232+ * Shows if the global trace has been enabled or not. It uses the
233+ * mirror flag "buffer_disabled" to be used in fast paths such as for
234+ * the irqsoff tracer. But it may be inaccurate due to races. If you
235+ * need to know the accurate state, use tracing_is_on() which is a little
236+ * slower, but accurate.
237+ */
229238int tracing_is_enabled (void )
230239{
231- return tracing_is_on ();
240+ /*
241+ * For quick access (irqsoff uses this in fast path), just
242+ * return the mirror variable of the state of the ring buffer.
243+ * It's a little racy, but we don't really care.
244+ */
245+ smp_rmb ();
246+ return !global_trace .buffer_disabled ;
232247}
233248
234249/*
@@ -341,6 +356,23 @@ unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
341356 TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE |
342357 TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS | TRACE_ITER_FUNCTION ;
343358
359+ void tracer_tracing_on (struct trace_array * tr )
360+ {
361+ if (tr -> trace_buffer .buffer )
362+ ring_buffer_record_on (tr -> trace_buffer .buffer );
363+ /*
364+ * This flag is looked at when buffers haven't been allocated
365+ * yet, or by some tracers (like irqsoff), that just want to
366+ * know if the ring buffer has been disabled, but it can handle
367+ * races of where it gets disabled but we still do a record.
368+ * As the check is in the fast path of the tracers, it is more
369+ * important to be fast than accurate.
370+ */
371+ tr -> buffer_disabled = 0 ;
372+ /* Make the flag seen by readers */
373+ smp_wmb ();
374+ }
375+
344376/**
345377 * tracing_on - enable tracing buffers
346378 *
@@ -349,15 +381,7 @@ unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
349381 */
350382void tracing_on (void )
351383{
352- if (global_trace .trace_buffer .buffer )
353- ring_buffer_record_on (global_trace .trace_buffer .buffer );
354- /*
355- * This flag is only looked at when buffers haven't been
356- * allocated yet. We don't really care about the race
357- * between setting this flag and actually turning
358- * on the buffer.
359- */
360- global_trace .buffer_disabled = 0 ;
384+ tracer_tracing_on (& global_trace );
361385}
362386EXPORT_SYMBOL_GPL (tracing_on );
363387
@@ -551,6 +575,23 @@ void tracing_snapshot_alloc(void)
551575EXPORT_SYMBOL_GPL (tracing_snapshot_alloc );
552576#endif /* CONFIG_TRACER_SNAPSHOT */
553577
578+ void tracer_tracing_off (struct trace_array * tr )
579+ {
580+ if (tr -> trace_buffer .buffer )
581+ ring_buffer_record_off (tr -> trace_buffer .buffer );
582+ /*
583+ * This flag is looked at when buffers haven't been allocated
584+ * yet, or by some tracers (like irqsoff), that just want to
585+ * know if the ring buffer has been disabled, but it can handle
586+ * races of where it gets disabled but we still do a record.
587+ * As the check is in the fast path of the tracers, it is more
588+ * important to be fast than accurate.
589+ */
590+ tr -> buffer_disabled = 1 ;
591+ /* Make the flag seen by readers */
592+ smp_wmb ();
593+ }
594+
554595/**
555596 * tracing_off - turn off tracing buffers
556597 *
@@ -561,15 +602,7 @@ EXPORT_SYMBOL_GPL(tracing_snapshot_alloc);
561602 */
562603void tracing_off (void )
563604{
564- if (global_trace .trace_buffer .buffer )
565- ring_buffer_record_off (global_trace .trace_buffer .buffer );
566- /*
567- * This flag is only looked at when buffers haven't been
568- * allocated yet. We don't really care about the race
569- * between setting this flag and actually turning
570- * on the buffer.
571- */
572- global_trace .buffer_disabled = 1 ;
605+ tracer_tracing_off (& global_trace );
573606}
574607EXPORT_SYMBOL_GPL (tracing_off );
575608
@@ -579,14 +612,25 @@ void disable_trace_on_warning(void)
579612 tracing_off ();
580613}
581614
615+ /**
616+ * tracer_tracing_is_on - show real state of ring buffer enabled
617+ * @tr : the trace array to know if ring buffer is enabled
618+ *
619+ * Shows real state of the ring buffer if it is enabled or not.
620+ */
621+ int tracer_tracing_is_on (struct trace_array * tr )
622+ {
623+ if (tr -> trace_buffer .buffer )
624+ return ring_buffer_record_is_on (tr -> trace_buffer .buffer );
625+ return !tr -> buffer_disabled ;
626+ }
627+
582628/**
583629 * tracing_is_on - show state of ring buffers enabled
584630 */
585631int tracing_is_on (void )
586632{
587- if (global_trace .trace_buffer .buffer )
588- return ring_buffer_record_is_on (global_trace .trace_buffer .buffer );
589- return !global_trace .buffer_disabled ;
633+ return tracer_tracing_is_on (& global_trace );
590634}
591635EXPORT_SYMBOL_GPL (tracing_is_on );
592636
@@ -3958,7 +4002,7 @@ static int tracing_wait_pipe(struct file *filp)
39584002 *
39594003 * iter->pos will be 0 if we haven't read anything.
39604004 */
3961- if (!tracing_is_enabled () && iter -> pos )
4005+ if (!tracing_is_on () && iter -> pos )
39624006 break ;
39634007 }
39644008
@@ -5631,15 +5675,10 @@ rb_simple_read(struct file *filp, char __user *ubuf,
56315675 size_t cnt , loff_t * ppos )
56325676{
56335677 struct trace_array * tr = filp -> private_data ;
5634- struct ring_buffer * buffer = tr -> trace_buffer .buffer ;
56355678 char buf [64 ];
56365679 int r ;
56375680
5638- if (buffer )
5639- r = ring_buffer_record_is_on (buffer );
5640- else
5641- r = 0 ;
5642-
5681+ r = tracer_tracing_is_on (tr );
56435682 r = sprintf (buf , "%d\n" , r );
56445683
56455684 return simple_read_from_buffer (ubuf , cnt , ppos , buf , r );
@@ -5661,11 +5700,11 @@ rb_simple_write(struct file *filp, const char __user *ubuf,
56615700 if (buffer ) {
56625701 mutex_lock (& trace_types_lock );
56635702 if (val ) {
5664- ring_buffer_record_on ( buffer );
5703+ tracer_tracing_on ( tr );
56655704 if (tr -> current_trace -> start )
56665705 tr -> current_trace -> start (tr );
56675706 } else {
5668- ring_buffer_record_off ( buffer );
5707+ tracer_tracing_off ( tr );
56695708 if (tr -> current_trace -> stop )
56705709 tr -> current_trace -> stop (tr );
56715710 }
0 commit comments