Skip to content

Commit dbecef6

Browse files
committed
tracing: Add tracer_tracing_disable/enable() functions
Allow a tracer to disable writing to its buffer for a temporary amount of time and re-enable it. The tracer_tracing_disable() will disable writing to the trace array buffer, and requires a tracer_tracing_enable() to re-enable it. The difference between tracer_tracing_disable() and tracer_tracing_off() is that the disable version can nest, and requires as many enable() calls as disable() calls to re-enable the buffer. Where as the off() function can be called multiple times and only requires a singe tracer_tracing_on() to re-enable the buffer. Cc: Jason Wessel <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Daniel Thompson <[email protected]> Reviewed-by: Douglas Anderson <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 1577683 commit dbecef6

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

kernel/trace/trace.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,39 @@ void tracer_tracing_off(struct trace_array *tr)
15821582
smp_wmb();
15831583
}
15841584

1585+
/**
1586+
* tracer_tracing_disable() - temporary disable the buffer from write
1587+
* @tr: The trace array to disable its buffer for
1588+
*
1589+
* Expects trace_tracing_enable() to re-enable tracing.
1590+
* The difference between this and tracer_tracing_off() is that this
1591+
* is a counter and can nest, whereas, tracer_tracing_off() can
1592+
* be called multiple times and a single trace_tracing_on() will
1593+
* enable it.
1594+
*/
1595+
void tracer_tracing_disable(struct trace_array *tr)
1596+
{
1597+
if (WARN_ON_ONCE(!tr->array_buffer.buffer))
1598+
return;
1599+
1600+
ring_buffer_record_disable(tr->array_buffer.buffer);
1601+
}
1602+
1603+
/**
1604+
* tracer_tracing_enable() - counter part of tracer_tracing_disable()
1605+
* @tr: The trace array that had tracer_tracincg_disable() called on it
1606+
*
1607+
* This is called after tracer_tracing_disable() has been called on @tr,
1608+
* when it's safe to re-enable tracing.
1609+
*/
1610+
void tracer_tracing_enable(struct trace_array *tr)
1611+
{
1612+
if (WARN_ON_ONCE(!tr->array_buffer.buffer))
1613+
return;
1614+
1615+
ring_buffer_record_enable(tr->array_buffer.buffer);
1616+
}
1617+
15851618
/**
15861619
* tracing_off - turn off tracing buffers
15871620
*

kernel/trace/trace.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,8 @@ bool tracing_is_disabled(void);
665665
bool tracer_tracing_is_on(struct trace_array *tr);
666666
void tracer_tracing_on(struct trace_array *tr);
667667
void tracer_tracing_off(struct trace_array *tr);
668+
void tracer_tracing_disable(struct trace_array *tr);
669+
void tracer_tracing_enable(struct trace_array *tr);
668670
struct dentry *trace_create_file(const char *name,
669671
umode_t mode,
670672
struct dentry *parent,

0 commit comments

Comments
 (0)