void tracing_reset_all_online_cpus(void)
{
	struct trace_array *tr;

	list_for_each_entry(tr, &ftrace_trace_arrays, list) {
		if (!tr->clear_trace)
			continue;
		tr->clear_trace = false;
		tracing_reset_online_cpus(&tr->trace_buffer);
#ifdef CONFIG_TRACER_MAX_TRACE
		tracing_reset_online_cpus(&tr->max_buffer);
#endif
	}
}

struct trace_iterator *tracepoint_print_iter;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};

static const struct file_operations tracing_fops = {
	.open		= tracing_open,
	.read		= seq_read,
	.write		= tracing_write_stub,
	.llseek		= tracing_lseek,
	.release	= tracing_release,
};


static void saved_tgids_stop(struct seq_file *m, void *v)
{
}

tracing: Fix possible double free on failure of allocating trace buffer

Jing Xia and Chunyan Zhang reported that on failing to allocate part of the
tracing buffer, memory is freed, but the pointers that point to them are not
initialized back to NULL, and later paths may try to free the freed memory
again. Jing and Chunyan fixed one of the locations that does this, but
missed a spot.

Link: http://lkml.kernel.org/r/20171226071253.8968-1-chunyan.zhang@spreadtrum.com

Cc: stable@vger.kernel.org
Fixes: 737223fbca3b1 ("tracing: Consolidate buffer allocation code")
Reported-by: Jing Xia <jing.xia@spreadtrum.com>
Reported-by: Chunyan Zhang <chunyan.zhang@spreadtrum.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

static bool __read_mostly

struct trace_iterator *tracepoint_print_iter;

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static DEFINE_MUTEX(trace_eval_mutex);

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

static bool selftests_can_run;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static atomic_t trace_record_taskinfo_disabled

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static DEFINE_SPINLOCK(tracepoint_iter_lock);


static int tracing_clock_show(struct seq_file *m, void *v)
{
	struct trace_array *tr = m->private;
	int i;

	for (i = 0; i < ARRAY_SIZE(trace_clocks); i++)
		seq_printf(m,
			"%s%s%s%s", i ? " " : "",
			i == tr->clock_id ? "[" : "", trace_clocks[i].name,
			i == tr->clock_id ? "]" : "");
	seq_putc(m, '\n');

	return 0;
}

static bool __read_mostly

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static DEFINE_MUTEX(trace_eval_mutex);

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

static bool selftests_can_run;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static atomic_t trace_record_taskinfo_disabled

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;


int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
	size_t cnt, loff_t *ppos)
{
	char ch;
	size_t read = 0;
	ssize_t ret;

	if (!*ppos)
		trace_parser_clear(parser);

	ret = get_user(ch, ubuf++);
	if (ret)
		goto out;

	read++;
	cnt--;

	/*
	 * The parser is not finished with the last write,
	 * continue reading the user input without skipping spaces.
	 */
	if (!parser->cont) {
		/* skip white space */
		while (cnt && isspace(ch)) {
			ret = get_user(ch, ubuf++);
			if (ret)
				goto out;
			read++;
			cnt--;
		}

		/* only spaces were written */
		if (isspace(ch)) {
			*ppos += read;
			ret = read;
			goto out;
		}

		parser->idx = 0;
	}

	/* read the non-space input */
	while (cnt && !isspace(ch)) {
		if (parser->idx < parser->size - 1)
			parser->buffer[parser->idx++] = ch;
		else {
			ret = -EINVAL;
			goto out;
		}
		ret = get_user(ch, ubuf++);
		if (ret)
			goto out;
		read++;
		cnt--;
	}

	/* We either got finished input or we have to wait for another call. */
	if (isspace(ch)) {
		parser->buffer[parser->idx] = 0;
		parser->cont = false;
	} else if (parser->idx < parser->size - 1) {
		parser->cont = true;
		parser->buffer[parser->idx++] = ch;
	} else {
		ret = -EINVAL;
		goto out;
	}

	*ppos += read;
	ret = read;

out:
	return ret;
}

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static int buffers_allocated;


static int tracing_saved_tgids_open(struct inode *inode, struct file *filp)
{
	if (tracing_disabled)
		return -ENODEV;

	return seq_open(filp, &tracing_saved_tgids_seq_ops);
}


tracing_total_entries_read(struct file *filp, char __user *ubuf,
				size_t cnt, loff_t *ppos)
{
	struct trace_array *tr = filp->private_data;
	char buf[64];
	int r, cpu;
	unsigned long size = 0, expanded_size = 0;

	mutex_lock(&trace_types_lock);
	for_each_tracing_cpu(cpu) {
		size += per_cpu_ptr(tr->trace_buffer.data, cpu)->entries >> 10;
		if (!ring_buffer_expanded)
			expanded_size += trace_buf_size >> 10;
	}
	if (ring_buffer_expanded)
		r = sprintf(buf, "%lu\n", size);
	else
		r = sprintf(buf, "%lu (expanded: %lu)\n", size, expanded_size);
	mutex_unlock(&trace_types_lock);

	return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
}

bool ring_buffer_expanded;

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

#define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}


ftrace_snapshot_init(struct ftrace_probe_ops *ops, struct trace_array *tr,
		     unsigned long ip, void *init_data, void **data)
{
	struct ftrace_func_mapper *mapper = *data;

	if (!mapper) {
		mapper = allocate_ftrace_func_mapper();
		if (!mapper)
			return -ENOMEM;
		*data = mapper;
	}

	return ftrace_func_mapper_add_ip(mapper, ip, init_data);
}

struct trace_iterator *tracepoint_print_iter;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

#define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};


int tracer_tracing_is_on(struct trace_array *tr)
{
	if (tr->trace_buffer.buffer)
		return ring_buffer_record_is_on(tr->trace_buffer.buffer);
	return !tr->buffer_disabled;
}

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static int buffers_allocated;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};


static void buffer_spd_release(struct splice_pipe_desc *spd, unsigned int i)
{
	struct buffer_ref *ref =
		(struct buffer_ref *)spd->partial[i].private;

	if (--ref->ref)
		return;

	ring_buffer_free_read_page(ref->buffer, ref->cpu, ref->page);
	kfree(ref);
	spd->partial[i].private = 0;
}

static bool __read_mostly

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static DEFINE_MUTEX(trace_eval_mutex);

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

static bool selftests_can_run;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static atomic_t trace_record_taskinfo_disabled

static int trace_buffered_event_ref;


static void trace_iterator_increment(struct trace_iterator *iter)
{
	struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, iter->cpu);

	iter->idx++;
	if (buf_iter)
		ring_buffer_read(buf_iter, NULL);
}


static void print_lat_help_header(struct seq_file *m)
{
	seq_puts(m, "#                  _------=> CPU#            \n"
		    "#                 / _-----=> irqs-off        \n"
		    "#                | / _----=> need-resched    \n"
		    "#                || / _---=> hardirq/softirq \n"
		    "#                ||| / _--=> preempt-depth   \n"
		    "#                |||| /     delay            \n"
		    "#  cmd     pid   ||||| time  |   caller      \n"
		    "#     \\   /      |||||  \\    |   /         \n");
}


static int __init set_ftrace_dump_on_oops(char *str)
{
	if (*str++ != '=' || !*str) {
		ftrace_dump_on_oops = DUMP_ALL;
		return 1;
	}

	if (!strcmp("orig_cpu", str)) {
		ftrace_dump_on_oops = DUMP_ORIG;
                return 1;
        }

        return 0;
}

static bool __read_mostly

int tracepoint_printk;

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

enum ftrace_dump_mode ftrace_dump_on_oops;

int __disable_trace_on_warning;

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static DEFINE_MUTEX(trace_eval_mutex);

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

static bool selftests_can_run;

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static atomic_t trace_record_taskinfo_disabled

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static DEFINE_SPINLOCK(tracepoint_iter_lock);

static DEFINE_MUTEX(tracepoint_printk_mutex);

static DEFINE_MUTEX(ftrace_export_lock);

static struct trace_export __rcu *ftrace_exports_list

static DEFINE_STATIC_KEY_FALSE(ftrace_exports_enabled);

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);


t_next(struct seq_file *m, void *v, loff_t *pos)
{
	struct trace_array *tr = m->private;
	struct tracer *t = v;

	(*pos)++;

	if (t)
		t = get_tracer_for_array(tr, t->next);

	return t;
}


static ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
					  unsigned long size, int cpu_id)
{
	int ret = size;

	mutex_lock(&trace_types_lock);

	if (cpu_id != RING_BUFFER_ALL_CPUS) {
		/* make sure, this cpu is enabled in the mask */
		if (!cpumask_test_cpu(cpu_id, tracing_buffer_mask)) {
			ret = -EINVAL;
			goto out;
		}
	}

	ret = __tracing_resize_ring_buffer(tr, size, cpu_id);
	if (ret < 0)
		ret = -ENOMEM;

out:
	mutex_unlock(&trace_types_lock);

	return ret;
}


add_ftrace_export(struct trace_export **list, struct trace_export *export)
{
	if (*list == NULL)
		ftrace_exports_enable();

	add_trace_export(list, export);
}

struct trace_iterator *tracepoint_print_iter;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};

static const struct file_operations tracing_fops = {
	.open		= tracing_open,
	.read		= seq_read,
	.write		= tracing_write_stub,
	.llseek		= tracing_lseek,
	.release	= tracing_release,
};


static inline int tracing_get_cpu(struct inode *inode)
{
	if (inode->i_cdev) /* See trace_create_cpu_file() */
		return (long)inode->i_cdev - 1;
	return RING_BUFFER_ALL_CPUS;
}


void trace_printk_start_comm(void)
{
	/* Start tracing comms if trace printk is set */
	if (!buffers_allocated)
		return;
	tracing_start_cmdline_record();
}

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int buffers_allocated;


static void t_stop(struct seq_file *m, void *p)
{
	mutex_unlock(&trace_types_lock);
}


static int alloc_snapshot(struct trace_array *tr)
{
	int ret;

	if (!tr->allocated_snapshot) {

		/* allocate spare buffer */
		ret = resize_buffer_duplicate_size(&tr->max_buffer,
				   &tr->trace_buffer, RING_BUFFER_ALL_CPUS);
		if (ret < 0)
			return ret;

		tr->allocated_snapshot = true;
	}

	return 0;
}


int tracing_is_on(void)
{
	return tracer_tracing_is_on(&global_trace);
}

int tracepoint_printk;

static int tracing_disabled = 1;

int __disable_trace_on_warning;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static int trace_buffered_event_ref;

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static int buffers_allocated;

static void
create_trace_option_files(struct trace_array *tr, struct tracer *tracer);

struct ftrace_buffer_info {
	struct trace_iterator	iter;
	void			*spare;
	unsigned int		spare_cpu;
	unsigned int		read;
}

static int tracing_buffers_open(struct inode *inode, struct file *filp);

static int tracing_buffers_release(struct inode *inode, struct file *file);

static ssize_t tracing_buffers_splice_read(struct file *file, loff_t *ppos,
		   struct pipe_inode_info *pipe, size_t len, unsigned int flags);

struct buffer_ref {
	struct ring_buffer	*buffer;
	void			*page;
	int			cpu;
	int			ref;
}

static void
init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer);


static char *get_trace_buf(void)
{
	struct trace_buffer_struct *buffer = this_cpu_ptr(trace_percpu_buffer);

	if (!buffer || buffer->nesting >= 4)
		return NULL;

	buffer->nesting++;

	/* Interrupts must see nesting incremented before we use the buffer */
	barrier();
	return &buffer->buffer[buffer->nesting][0];
}


static void free_trace_buffer(struct trace_buffer *buf)
{
	if (buf->buffer) {
		ring_buffer_free(buf->buffer);
		buf->buffer = NULL;
		free_percpu(buf->data);
		buf->data = NULL;
	}
}


int register_ftrace_export(struct trace_export *export)
{
	if (WARN_ON_ONCE(!export->write))
		return -1;

	mutex_lock(&ftrace_export_lock);

	add_ftrace_export(&ftrace_exports_list, export);

	mutex_unlock(&ftrace_export_lock);

	return 0;
}

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static DEFINE_MUTEX(ftrace_export_lock);

static struct trace_export __rcu *ftrace_exports_list

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static int buffers_allocated;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};


static int __init set_trace_boot_options(char *str)
{
	strlcpy(trace_boot_options_buf, str, MAX_TRACER_SIZE);
	return 0;
}

static bool __read_mostly

int tracepoint_printk;

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static DEFINE_MUTEX(trace_eval_mutex);

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

#define MAX_TRACER_SIZE		100

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

static bool selftests_can_run;

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static atomic_t trace_record_taskinfo_disabled

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static DEFINE_SPINLOCK(tracepoint_iter_lock);

static DEFINE_MUTEX(tracepoint_printk_mutex);

static DEFINE_MUTEX(ftrace_export_lock);

static struct trace_export __rcu *ftrace_exports_list

static DEFINE_STATIC_KEY_FALSE(ftrace_exports_enabled);

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);


tracing_nsecs_read(unsigned long *ptr, char __user *ubuf,
		   size_t cnt, loff_t *ppos)
{
	char buf[64];
	int r;

	r = snprintf(buf, sizeof(buf), "%ld\n",
		     *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr));
	if (r > sizeof(buf))
		r = sizeof(buf);
	return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
}

int tracepoint_printk;

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

#define TRACE_BUF_SIZE_DEFAULT	1441792UL /* 16384 * 88 (sizeof(entry)) */

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static int trace_buffered_event_ref;

#define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static int buffers_allocated;


int call_filter_check_discard(struct trace_event_call *call, void *rec,
			      struct ring_buffer *buffer,
			      struct ring_buffer_event *event)
{
	if (unlikely(call->flags & TRACE_EVENT_FL_FILTERED) &&
	    !filter_match_preds(call->filter, rec)) {
		__trace_event_discard_commit(buffer, event);
		return 1;
	}

	return 0;
}

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static int buffers_allocated;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};


static void __trace_array_put(struct trace_array *this_tr)
{
	WARN_ON(!this_tr->ref);
	this_tr->ref--;
}


trace_function(struct trace_array *tr,
	       unsigned long ip, unsigned long parent_ip, unsigned long flags,
	       int pc)
{
	struct trace_event_call *call = &event_function;
	struct ring_buffer *buffer = tr->trace_buffer.buffer;
	struct ring_buffer_event *event;
	struct ftrace_entry *entry;

	event = __trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry),
					    flags, pc);
	if (!event)
		return;
	entry	= ring_buffer_event_data(event);
	entry->ip			= ip;
	entry->parent_ip		= parent_ip;

	if (!call_filter_check_discard(call, entry, buffer, event)) {
		if (static_branch_unlikely(&ftrace_exports_enabled))
			ftrace_exports(event);
		__buffer_unlock_commit(buffer, event);
	}
}

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

#define TRACE_BUF_SIZE_DEFAULT	1441792UL /* 16384 * 88 (sizeof(entry)) */

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

static DEFINE_STATIC_KEY_FALSE(ftrace_exports_enabled);

#define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static int buffers_allocated;


ssize_t trace_parse_run_command(struct file *file, const char __user *buffer,
				size_t count, loff_t *ppos,
				int (*createfn)(int, char **))
{
	char *kbuf, *buf, *tmp;
	int ret = 0;
	size_t done = 0;
	size_t size;

	kbuf = kmalloc(WRITE_BUFSIZE, GFP_KERNEL);
	if (!kbuf)
		return -ENOMEM;

	while (done < count) {
		size = count - done;

		if (size >= WRITE_BUFSIZE)
			size = WRITE_BUFSIZE - 1;

		if (copy_from_user(kbuf, buffer + done, size)) {
			ret = -EFAULT;
			goto out;
		}
		kbuf[size] = '\0';
		buf = kbuf;
		do {
			tmp = strchr(buf, '\n');
			if (tmp) {
				*tmp = '\0';
				size = tmp - buf + 1;
			} else {
				size = strlen(buf);
				if (done + size < count) {
					if (buf != kbuf)
						break;
					/* This can accept WRITE_BUFSIZE - 2 ('\n' + '\0') */
					pr_warn("Line length is too long: Should be less than %d\n",
						WRITE_BUFSIZE - 2);
					ret = -EINVAL;
					goto out;
				}
			}
			done += size;

			/* Remove comments */
			tmp = strchr(buf, '#');

			if (tmp)
				*tmp = '\0';

			ret = trace_run_command(buf, createfn);
			if (ret)
				goto out;
			buf += size;

		} while (done < count);
	}
	ret = done;

out:
	kfree(kbuf);

	return ret;
}

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

#define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static int buffers_allocated;


int trace_parser_get_init(struct trace_parser *parser, int size)
{
	memset(parser, 0, sizeof(*parser));

	parser->buffer = kmalloc(size, GFP_KERNEL);
	if (!parser->buffer)
		return 1;

	parser->size = size;
	return 0;
}

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

#define TRACE_BUF_SIZE_DEFAULT	1441792UL /* 16384 * 88 (sizeof(entry)) */

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

#define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static int buffers_allocated;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};


init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer)
{
	int cpu;

	trace_create_file("available_tracers", 0444, d_tracer,
			tr, &show_traces_fops);

	trace_create_file("current_tracer", 0644, d_tracer,
			tr, &set_tracer_fops);

	trace_create_file("tracing_cpumask", 0644, d_tracer,
			  tr, &tracing_cpumask_fops);

	trace_create_file("trace_options", 0644, d_tracer,
			  tr, &tracing_iter_fops);

	trace_create_file("trace", 0644, d_tracer,
			  tr, &tracing_fops);

	trace_create_file("trace_pipe", 0444, d_tracer,
			  tr, &tracing_pipe_fops);

	trace_create_file("buffer_size_kb", 0644, d_tracer,
			  tr, &tracing_entries_fops);

	trace_create_file("buffer_total_size_kb", 0444, d_tracer,
			  tr, &tracing_total_entries_fops);

	trace_create_file("free_buffer", 0200, d_tracer,
			  tr, &tracing_free_buffer_fops);

	trace_create_file("trace_marker", 0220, d_tracer,
			  tr, &tracing_mark_fops);

	trace_create_file("trace_marker_raw", 0220, d_tracer,
			  tr, &tracing_mark_raw_fops);

	trace_create_file("trace_clock", 0644, d_tracer, tr,
			  &trace_clock_fops);

	trace_create_file("tracing_on", 0644, d_tracer,
			  tr, &rb_simple_fops);

	create_trace_options_dir(tr);

#if defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER)
	trace_create_file("tracing_max_latency", 0644, d_tracer,
			&tr->max_latency, &tracing_max_lat_fops);
#endif

	if (ftrace_create_function_files(tr, d_tracer))
		WARN(1, "Could not allocate function filter files");

#ifdef CONFIG_TRACER_SNAPSHOT
	trace_create_file("snapshot", 0644, d_tracer,
			  tr, &snapshot_fops);
#endif

	for_each_tracing_cpu(cpu)
		tracing_init_tracefs_percpu(tr, cpu);

	ftrace_init_tracefs(tr, d_tracer);
}

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static int buffers_allocated;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};


static ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt)
{
	int len;

	if (trace_seq_used(s) <= s->seq.readpos)
		return -EBUSY;

	len = trace_seq_used(s) - s->seq.readpos;
	if (cnt > len)
		cnt = len;
	memcpy(buf, s->buffer + s->seq.readpos, cnt);

	s->seq.readpos += cnt;
	return cnt;
}

static bool __read_mostly

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static DEFINE_MUTEX(trace_eval_mutex);

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

static bool selftests_can_run;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static atomic_t trace_record_taskinfo_disabled

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;


unsigned long nsecs_to_usecs(unsigned long nsecs)
{
	return nsecs / 1000;
}

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

unsigned long __read_mostly	tracing_thresh;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

#define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

struct ftrace_buffer_info {
	struct trace_iterator	iter;
	void			*spare;
	unsigned int		spare_cpu;
	unsigned int		read;
}

static ssize_t tracing_buffers_splice_read(struct file *file, loff_t *ppos,
		   struct pipe_inode_info *pipe, size_t len, unsigned int flags);


void tracing_record_cmdline(struct task_struct *task)
{
	tracing_record_taskinfo(task, TRACE_RECORD_CMDLINE);
}

struct trace_iterator *tracepoint_print_iter;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};

static const struct file_operations tracing_fops = {
	.open		= tracing_open,
	.read		= seq_read,
	.write		= tracing_write_stub,
	.llseek		= tracing_lseek,
	.release	= tracing_release,
};


static int tracing_buffers_open(struct inode *inode, struct file *filp)
{
	struct trace_array *tr = inode->i_private;
	struct ftrace_buffer_info *info;
	int ret;

	if (tracing_disabled)
		return -ENODEV;

	if (trace_array_get(tr) < 0)
		return -ENODEV;

	info = kzalloc(sizeof(*info), GFP_KERNEL);
	if (!info) {
		trace_array_put(tr);
		return -ENOMEM;
	}

	mutex_lock(&trace_types_lock);

	info->iter.tr		= tr;
	info->iter.cpu_file	= tracing_get_cpu(inode);
	info->iter.trace	= tr->current_trace;
	info->iter.trace_buffer = &tr->trace_buffer;
	info->spare		= NULL;
	/* Force reading ring buffer for first read */
	info->read		= (unsigned int)-1;

	filp->private_data = info;

	tr->current_trace->ref++;

	mutex_unlock(&trace_types_lock);

	ret = nonseekable_open(inode, filp);
	if (ret < 0)
		trace_array_put(tr);

	return ret;
}

static bool __read_mostly

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static DEFINE_MUTEX(trace_eval_mutex);

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

#define TRACE_BUF_SIZE_DEFAULT	1441792UL /* 16384 * 88 (sizeof(entry)) */

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

static bool selftests_can_run;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;


int tracer_init(struct tracer *t, struct trace_array *tr)
{
	tracing_reset_online_cpus(&tr->trace_buffer);
	return t->init(tr);
}

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static int buffers_allocated;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};


static inline void ftrace_exports_enable(void)
{
	static_branch_enable(&ftrace_exports_enabled);
}

static bool __read_mostly

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

static DEFINE_MUTEX(trace_eval_mutex);

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

static bool selftests_can_run;

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;

static struct saved_cmdlines_buffer *savedcmd;

static atomic_t trace_record_taskinfo_disabled

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static DEFINE_SPINLOCK(tracepoint_iter_lock);

static DEFINE_MUTEX(tracepoint_printk_mutex);

static DEFINE_MUTEX(ftrace_export_lock);

static struct trace_export __rcu *ftrace_exports_list

static DEFINE_STATIC_KEY_FALSE(ftrace_exports_enabled);

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

static struct trace_buffer_struct *trace_percpu_buffer;

static int buffers_allocated;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};


static inline void __ftrace_trace_stack(struct ring_buffer *buffer,
					unsigned long flags,
					int skip, int pc, struct pt_regs *regs)
{
}

static bool __read_mostly

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static DEFINE_MUTEX(trace_eval_mutex);

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

static bool selftests_can_run;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static atomic_t trace_record_taskinfo_disabled

static int trace_buffered_event_ref;


static int trace_panic_handler(struct notifier_block *this,
			       unsigned long event, void *unused)
{
	if (ftrace_dump_on_oops)
		ftrace_dump(ftrace_dump_on_oops);
	return NOTIFY_OK;
}

static bool __read_mostly

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

enum ftrace_dump_mode ftrace_dump_on_oops;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static DEFINE_MUTEX(trace_eval_mutex);

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

static bool selftests_can_run;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;


void tracing_on(void)
{
	tracer_tracing_on(&global_trace);
}

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);


tracing_read_dyn_info(struct file *filp, char __user *ubuf,
		  size_t cnt, loff_t *ppos)
{
	unsigned long *p = filp->private_data;
	char buf[64]; /* Not too big for a shallow stack */
	int r;

	r = scnprintf(buf, 63, "%ld", *p);
	buf[r++] = '\n';

	return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
}