Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 12883efb authored by Steven Rostedt (Red Hat)'s avatar Steven Rostedt (Red Hat) Committed by Steven Rostedt
Browse files

tracing: Consolidate max_tr into main trace_array structure



Currently, the way the latency tracers and snapshot feature works
is to have a separate trace_array called "max_tr" that holds the
snapshot buffer. For latency tracers, this snapshot buffer is used
to swap the running buffer with this buffer to save the current max
latency.

The only items needed for the max_tr is really just a copy of the buffer
itself, the per_cpu data pointers, the time_start timestamp that states
when the max latency was triggered, and the cpu that the max latency
was triggered on. All other fields in trace_array are unused by the
max_tr, making the max_tr mostly bloat.

This change removes the max_tr completely, and adds a new structure
called trace_buffer, that holds the buffer pointer, the per_cpu data
pointers, the time_start timestamp, and the cpu where the latency occurred.

The trace_array, now has two trace_buffers, one for the normal trace and
one for the max trace or snapshot. By doing this, not only do we remove
the bloat from the max_trace but the instances of traces can now use
their own snapshot feature and not have just the top level global_trace have
the snapshot feature and latency tracers for itself.

Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent 22cffc2b
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -8,6 +8,7 @@
#include <linux/perf_event.h>
#include <linux/perf_event.h>


struct trace_array;
struct trace_array;
struct trace_buffer;
struct tracer;
struct tracer;
struct dentry;
struct dentry;


@@ -67,6 +68,7 @@ struct trace_entry {
struct trace_iterator {
struct trace_iterator {
	struct trace_array	*tr;
	struct trace_array	*tr;
	struct tracer		*trace;
	struct tracer		*trace;
	struct trace_buffer	*trace_buffer;
	void			*private;
	void			*private;
	int			cpu_file;
	int			cpu_file;
	struct mutex		mutex;
	struct mutex		mutex;
+2 −2
Original line number Original line Diff line number Diff line
@@ -72,7 +72,7 @@ static void trace_note(struct blk_trace *bt, pid_t pid, int action,
	bool blk_tracer = blk_tracer_enabled;
	bool blk_tracer = blk_tracer_enabled;


	if (blk_tracer) {
	if (blk_tracer) {
		buffer = blk_tr->buffer;
		buffer = blk_tr->trace_buffer.buffer;
		pc = preempt_count();
		pc = preempt_count();
		event = trace_buffer_lock_reserve(buffer, TRACE_BLK,
		event = trace_buffer_lock_reserve(buffer, TRACE_BLK,
						  sizeof(*t) + len,
						  sizeof(*t) + len,
@@ -218,7 +218,7 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
	if (blk_tracer) {
	if (blk_tracer) {
		tracing_record_cmdline(current);
		tracing_record_cmdline(current);


		buffer = blk_tr->buffer;
		buffer = blk_tr->trace_buffer.buffer;
		pc = preempt_count();
		pc = preempt_count();
		event = trace_buffer_lock_reserve(buffer, TRACE_BLK,
		event = trace_buffer_lock_reserve(buffer, TRACE_BLK,
						  sizeof(*t) + pdu_len,
						  sizeof(*t) + pdu_len,
+270 −216

File changed.

Preview size limit exceeded, changes collapsed.

+30 −7
Original line number Original line Diff line number Diff line
@@ -167,16 +167,37 @@ struct trace_array_cpu {


struct tracer;
struct tracer;


struct trace_buffer {
	struct trace_array		*tr;
	struct ring_buffer		*buffer;
	struct trace_array_cpu __percpu	*data;
	cycle_t				time_start;
	int				cpu;
};

/*
/*
 * The trace array - an array of per-CPU trace arrays. This is the
 * The trace array - an array of per-CPU trace arrays. This is the
 * highest level data structure that individual tracers deal with.
 * highest level data structure that individual tracers deal with.
 * They have on/off state as well:
 * They have on/off state as well:
 */
 */
struct trace_array {
struct trace_array {
	struct ring_buffer	*buffer;
	struct list_head	list;
	struct list_head	list;
	char			*name;
	char			*name;
	int			cpu;
	struct trace_buffer	trace_buffer;
#ifdef CONFIG_TRACER_MAX_TRACE
	/*
	 * The max_buffer is used to snapshot the trace when a maximum
	 * latency is reached, or when the user initiates a snapshot.
	 * Some tracers will use this to store a maximum trace while
	 * it continues examining live traces.
	 *
	 * The buffers for the max_buffer are set up the same as the trace_buffer
	 * When a snapshot is taken, the buffer of the max_buffer is swapped
	 * with the buffer of the trace_buffer and the buffers are reset for
	 * the trace_buffer so the tracing can continue.
	 */
	struct trace_buffer	max_buffer;
#endif
	int			buffer_disabled;
	int			buffer_disabled;
	struct trace_cpu	trace_cpu;	/* place holder */
	struct trace_cpu	trace_cpu;	/* place holder */
#ifdef CONFIG_FTRACE_SYSCALLS
#ifdef CONFIG_FTRACE_SYSCALLS
@@ -189,7 +210,6 @@ struct trace_array {
	int			clock_id;
	int			clock_id;
	struct tracer		*current_trace;
	struct tracer		*current_trace;
	unsigned int		flags;
	unsigned int		flags;
	cycle_t			time_start;
	raw_spinlock_t		start_lock;
	raw_spinlock_t		start_lock;
	struct dentry		*dir;
	struct dentry		*dir;
	struct dentry		*options;
	struct dentry		*options;
@@ -198,7 +218,6 @@ struct trace_array {
	struct list_head	systems;
	struct list_head	systems;
	struct list_head	events;
	struct list_head	events;
	struct task_struct	*waiter;
	struct task_struct	*waiter;
	struct trace_array_cpu __percpu	*data;
};
};


enum {
enum {
@@ -345,9 +364,11 @@ struct tracer {
	struct tracer		*next;
	struct tracer		*next;
	struct tracer_flags	*flags;
	struct tracer_flags	*flags;
	bool			print_max;
	bool			print_max;
	bool			enabled;
#ifdef CONFIG_TRACER_MAX_TRACE
	bool			use_max_tr;
	bool			use_max_tr;
	bool			allocated_snapshot;
	bool			allocated_snapshot;
	bool			enabled;
#endif
};
};




@@ -493,8 +514,8 @@ trace_buffer_iter(struct trace_iterator *iter, int cpu)


int tracer_init(struct tracer *t, struct trace_array *tr);
int tracer_init(struct tracer *t, struct trace_array *tr);
int tracing_is_enabled(void);
int tracing_is_enabled(void);
void tracing_reset(struct trace_array *tr, int cpu);
void tracing_reset(struct trace_buffer *buf, int cpu);
void tracing_reset_online_cpus(struct trace_array *tr);
void tracing_reset_online_cpus(struct trace_buffer *buf);
void tracing_reset_current(int cpu);
void tracing_reset_current(int cpu);
void tracing_reset_all_online_cpus(void);
void tracing_reset_all_online_cpus(void);
int tracing_open_generic(struct inode *inode, struct file *filp);
int tracing_open_generic(struct inode *inode, struct file *filp);
@@ -674,6 +695,8 @@ trace_array_vprintk(struct trace_array *tr,
		    unsigned long ip, const char *fmt, va_list args);
		    unsigned long ip, const char *fmt, va_list args);
int trace_array_printk(struct trace_array *tr,
int trace_array_printk(struct trace_array *tr,
		       unsigned long ip, const char *fmt, ...);
		       unsigned long ip, const char *fmt, ...);
int trace_array_printk_buf(struct ring_buffer *buffer,
			   unsigned long ip, const char *fmt, ...);
void trace_printk_seq(struct trace_seq *s);
void trace_printk_seq(struct trace_seq *s);
enum print_line_t print_trace_line(struct trace_iterator *iter);
enum print_line_t print_trace_line(struct trace_iterator *iter);


+4 −4
Original line number Original line Diff line number Diff line
@@ -28,7 +28,7 @@ static void tracing_stop_function_trace(void);
static int function_trace_init(struct trace_array *tr)
static int function_trace_init(struct trace_array *tr)
{
{
	func_trace = tr;
	func_trace = tr;
	tr->cpu = get_cpu();
	tr->trace_buffer.cpu = get_cpu();
	put_cpu();
	put_cpu();


	tracing_start_cmdline_record();
	tracing_start_cmdline_record();
@@ -44,7 +44,7 @@ static void function_trace_reset(struct trace_array *tr)


static void function_trace_start(struct trace_array *tr)
static void function_trace_start(struct trace_array *tr)
{
{
	tracing_reset_online_cpus(tr);
	tracing_reset_online_cpus(&tr->trace_buffer);
}
}


/* Our option */
/* Our option */
@@ -76,7 +76,7 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
		goto out;
		goto out;


	cpu = smp_processor_id();
	cpu = smp_processor_id();
	data = per_cpu_ptr(tr->data, cpu);
	data = per_cpu_ptr(tr->trace_buffer.data, cpu);
	if (!atomic_read(&data->disabled)) {
	if (!atomic_read(&data->disabled)) {
		local_save_flags(flags);
		local_save_flags(flags);
		trace_function(tr, ip, parent_ip, flags, pc);
		trace_function(tr, ip, parent_ip, flags, pc);
@@ -107,7 +107,7 @@ function_stack_trace_call(unsigned long ip, unsigned long parent_ip,
	 */
	 */
	local_irq_save(flags);
	local_irq_save(flags);
	cpu = raw_smp_processor_id();
	cpu = raw_smp_processor_id();
	data = per_cpu_ptr(tr->data, cpu);
	data = per_cpu_ptr(tr->trace_buffer.data, cpu);
	disabled = atomic_inc_return(&data->disabled);
	disabled = atomic_inc_return(&data->disabled);


	if (likely(disabled == 1)) {
	if (likely(disabled == 1)) {
Loading