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

Commit e99472f0 authored by Shashank Mittal's avatar Shashank Mittal Committed by Tingwei Zhang
Browse files

coresight: enable stm logging for trace events, marker and printk



Dup ftrace event traffic and writes to trace_marker file from
userspace to STM. Also dup trace printk traffic to STM. This
allows Linux tracing and log data to be correlated with other
data transported over STM.

Change-Id: Ie9a2e1a8c9ea542226f387e9207f3d736d9187ab
Signed-off-by: default avatarPratik Patel <pratikp@codeaurora.org>
[spjoshi@codeaurora.org: 3.18 code fixup]
Signed-off-by: default avatarSarangdhar Joshi <spjoshi@codeaurora.org>
[mittals@codeaurora.org: 4.4 code fixup]
Signed-off-by: default avatarShashank Mittal <mittals@codeaurora.org>
[sadesai@codeaurora.org: 4.8 code fixup]
Signed-off-by: default avatarSatyajit Desai <sadesai@codeaurora.org>
Signed-off-by: default avatarRama Aparna Mallavarapu <aparnam@codeaurora.org>
Signed-off-by: default avatarTingwei Zhang <tingwei@codeaurora.org>
parent 2aa23d3a
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
#include <linux/hardirq.h>
#include <linux/perf_event.h>
#include <linux/tracepoint.h>
#include <linux/coresight-stm.h>

struct trace_array;
struct trace_buffer;
@@ -216,8 +217,12 @@ struct trace_event_buffer {
void *trace_event_buffer_reserve(struct trace_event_buffer *fbuffer,
				  struct trace_event_file *trace_file,
				  unsigned long len);

#ifdef CONFIG_CORESIGHT_QGKI
void trace_event_buffer_commit(struct trace_event_buffer *fbuffer,
			       unsigned long len);
#else
void trace_event_buffer_commit(struct trace_event_buffer *fbuffer);
#endif

enum {
	TRACE_EVENT_FL_FILTERED_BIT,
+32 −0
Original line number Diff line number Diff line
@@ -693,6 +693,37 @@ static inline notrace int trace_event_get_offsets_##call( \
#define __perf_task(t)	(t)

#undef DECLARE_EVENT_CLASS
#ifdef CONFIG_CORESIGHT_QGKI
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
									\
static notrace void							\
trace_event_raw_event_##call(void *__data, proto)			\
{									\
	struct trace_event_file *trace_file = __data;			\
	struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
	struct trace_event_buffer fbuffer;				\
	struct trace_event_raw_##call *entry;				\
	int __data_size;						\
									\
	if (trace_trigger_soft_disabled(trace_file))			\
		return;							\
									\
	__data_size = trace_event_get_offsets_##call(&__data_offsets, args); \
									\
	entry = trace_event_buffer_reserve(&fbuffer, trace_file,	\
				 sizeof(*entry) + __data_size);		\
									\
	if (!entry)							\
		return;							\
									\
	tstruct								\
									\
	{ assign; }							\
									\
	trace_event_buffer_commit(&fbuffer,				\
				  sizeof(*entry) + __data_size);	\
}
#else
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
									\
static notrace void							\
@@ -721,6 +752,7 @@ trace_event_raw_event_##call(void *__data, proto) \
									\
	trace_event_buffer_commit(&fbuffer);				\
}
#endif
/*
 * The ftrace_test_probe is compiled out, it is only here as a build time check
 * to make sure that if the tracepoint handling changes, the ftrace probe will
+18 −2
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@
#include <linux/trace.h>
#include <linux/sched/clock.h>
#include <linux/sched/rt.h>
#include <linux/coresight-stm.h>

#include "trace.h"
#include "trace_output.h"
@@ -2578,15 +2579,26 @@ int tracepoint_printk_sysctl(struct ctl_table *table, int write,
	return ret;
}

#ifdef CONFIG_CORESIGHT_QGKI
void trace_event_buffer_commit(struct trace_event_buffer *fbuffer,
			       unsigned long len)
{
	if (static_key_false(&tracepoint_printk_key.key))
		output_printk(fbuffer);
	event_trigger_unlock_commit(fbuffer->trace_file, fbuffer->buffer,
				    fbuffer->event, fbuffer->entry,
				    fbuffer->flags, fbuffer->pc, len);
}
#else
void trace_event_buffer_commit(struct trace_event_buffer *fbuffer)
{
	if (static_key_false(&tracepoint_printk_key.key))
		output_printk(fbuffer);

	event_trigger_unlock_commit(fbuffer->trace_file, fbuffer->buffer,
				    fbuffer->event, fbuffer->entry,
				    fbuffer->flags, fbuffer->pc);
}
#endif
EXPORT_SYMBOL_GPL(trace_event_buffer_commit);

/*
@@ -3194,6 +3206,7 @@ __trace_array_vprintk(struct ring_buffer *buffer,

	memcpy(&entry->buf, tbuffer, len + 1);
	if (!call_filter_check_discard(call, entry, buffer, event)) {
		stm_log(OST_ENTITY_TRACE_PRINTK, entry->buf, len + 1);
		__buffer_unlock_commit(buffer, event);
		ftrace_trace_stack(&global_trace, buffer, flags, 6, pc, NULL);
	}
@@ -6426,8 +6439,11 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
	if (entry->buf[cnt - 1] != '\n') {
		entry->buf[cnt] = '\n';
		entry->buf[cnt + 1] = '\0';
	} else
		stm_log(OST_ENTITY_TRACE_MARKER, entry->buf, cnt + 2);
	} else {
		entry->buf[cnt] = '\0';
		stm_log(OST_ENTITY_TRACE_MARKER, entry->buf, cnt + 1);
	}

	__buffer_unlock_commit(buffer, event);

+24 −1
Original line number Diff line number Diff line
@@ -1426,11 +1426,34 @@ __event_trigger_test_discard(struct trace_event_file *file,
 * @entry: The event itself
 * @irq_flags: The state of the interrupts at the start of the event
 * @pc: The state of the preempt count at the start of the event.
 * @len: The length of the payload data required for stm logging.
 *
 * This is a helper function to handle triggers that require data
 * from the event itself. It also tests the event against filters and
 * if the event is soft disabled and should be discarded.
 */
#ifdef CONFIG_CORESIGHT_QGKI
static inline void
event_trigger_unlock_commit(struct trace_event_file *file,
			    struct ring_buffer *buffer,
			    struct ring_buffer_event *event,
			    void *entry, unsigned long irq_flags, int pc,
			    unsigned long len)
{
	enum event_trigger_type tt = ETT_NONE;

	if (!__event_trigger_test_discard(file, buffer, event, entry, &tt)) {
		if (len)
			stm_log(OST_ENTITY_FTRACE_EVENTS, entry, len);

		trace_buffer_unlock_commit(file->tr, buffer, event,
						irq_flags, pc);
	}

	if (tt)
		event_triggers_post_call(file, tt);
}
#else
static inline void
event_trigger_unlock_commit(struct trace_event_file *file,
			    struct ring_buffer *buffer,
@@ -1445,7 +1468,7 @@ event_trigger_unlock_commit(struct trace_event_file *file,
	if (tt)
		event_triggers_post_call(file, tt);
}

#endif
/**
 * event_trigger_unlock_commit_regs - handle triggers and finish event commit
 * @file: The file pointer assoctiated to the event
+5 −1
Original line number Diff line number Diff line
@@ -3384,9 +3384,13 @@ function_test_events_call(unsigned long ip, unsigned long parent_ip,
	entry	= ring_buffer_event_data(event);
	entry->ip			= ip;
	entry->parent_ip		= parent_ip;

#ifdef CONFIG_CORESIGHT_QGKI
	event_trigger_unlock_commit(&event_trace_file, buffer, event,
				    entry, flags, pc, 0);
#else
	event_trigger_unlock_commit(&event_trace_file, buffer, event,
				    entry, flags, pc);
#endif
 out:
	atomic_dec(&per_cpu(ftrace_test_event_disable, cpu));
	preempt_enable_notrace();
Loading