2015-07-22 03:47:48

by Chunyan Zhang

[permalink] [raw]
Subject: [PATCH v4 0/3] Integration of trace events with System Trace IP blocks

IP blocks allowing a variety of trace sources to log debugging
information to a pre-defined area have been introduced on a couple of
architecture [1][2]. These system trace blocks (also known as STM)
typically follow the MIPI STPv2 protocol [3] and provide a system wide
logging facility to any device, running a kernel or not, with access
to the block's log entry port(s). Since each trace message has a
timestamp is it possible to correlate events happening in the entire
system rather than being confined to the logging facility of a single
entity.

This patch is using a very simple "stm_source" introduced in [2] to
duplicate the output of the trace event subsystem to an STM, in this
case coresight STM. That way logging information generated by the
trace event subsystem and gathered in the coresight sink can be used
in conjunction with trace data from other board components, also
collected in the same trace sink. This example is using coresight but
the same would apply to any architecture wishing to do the same.

So, this patch set has to depend on [2] from Alexander Shishkin.


Thanks,
Chunyan

[1]. https://lkml.org/lkml/2015/2/4/729
[2]. https://lkml.org/lkml/2015/7/6/206
[3]. http://mipi.org/specifications/debug#STP

Changes from RFC v3:
* Update patch 1/3 based on the newest verson of STM patches from
Alexander Shishkin
* Addressed Steve's comments
- Reused trace_raw_output_##call() rather than defined a new
similar function.
- Moved trace_event_stm_log() into trace_event_buffer_commit()

Changes from RFC v2:
- Revised some types and variable's name according to the
code of v4.2-rc1
- Sorted this patch-set based on the v4.2-rc1
- Splited the patch 2/3 of my last patch-set to make code can
be compiled after each patch is applied in order.

Changes from RFC v1:
- Marked module init/exit functions with __init/__exit key word
according to the comments from Paul Bolle

Chunyan Zhang (2):
trace: Introduce trace log output function for STM
trace: Add an output of trace event logs to STM

Mathieu Poirier (1):
STM trace event: Adding generic buffer interface driver

drivers/hwtracing/stm/Kconfig | 11 ++++++++
drivers/hwtracing/stm/Makefile | 2 ++
drivers/hwtracing/stm/stm_trace_event.c | 46 +++++++++++++++++++++++++++++++++
kernel/trace/Makefile | 1 +
kernel/trace/trace_events.c | 2 ++
kernel/trace/trace_output.h | 7 +++++
kernel/trace/trace_output_stm.c | 22 ++++++++++++++++
7 files changed, 91 insertions(+)
create mode 100644 drivers/hwtracing/stm/stm_trace_event.c
create mode 100644 kernel/trace/trace_output_stm.c

--
1.9.1


2015-07-22 03:47:55

by Chunyan Zhang

[permalink] [raw]
Subject: [PATCH v4 1/3] STM trace event: Adding generic buffer interface driver

From: Mathieu Poirier <[email protected]>

This patch adds a driver that models itself as an stm_source and
who's sole purpose is to export an interface to the rest of the
kernel. Once the stm and stm_source have been linked via sysfs,
everything that is passed to the interface will endup in the STM
trace engine.

Signed-off-by: Mathieu Poirier <[email protected]>
Signed-off-by: Chunyan Zhang <[email protected]>
---
drivers/hwtracing/stm/Kconfig | 11 ++++++++
drivers/hwtracing/stm/Makefile | 2 ++
drivers/hwtracing/stm/stm_trace_event.c | 46 +++++++++++++++++++++++++++++++++
3 files changed, 59 insertions(+)
create mode 100644 drivers/hwtracing/stm/stm_trace_event.c

diff --git a/drivers/hwtracing/stm/Kconfig b/drivers/hwtracing/stm/Kconfig
index 583c222..ca3b9a9 100644
--- a/drivers/hwtracing/stm/Kconfig
+++ b/drivers/hwtracing/stm/Kconfig
@@ -23,3 +23,14 @@ config STM_SOURCE_CONSOLE

If you want to send kernel console messages over STM devices,
say Y.
+
+config TRACE_EVENT_STM
+ tristate "Redirect/copy the output from kernel trace event to STM engine"
+ depends on STM
+ help
+ This option can be used to redirect or copy the output from kernel trace
+ event to STM engine. Enabling this option will introduce a slight
+ timing effect.
+
+ If you want to send kernel trace event messages over STM devices,
+ say Y.
diff --git a/drivers/hwtracing/stm/Makefile b/drivers/hwtracing/stm/Makefile
index f9312c3..110a75a 100644
--- a/drivers/hwtracing/stm/Makefile
+++ b/drivers/hwtracing/stm/Makefile
@@ -7,3 +7,5 @@ obj-$(CONFIG_STM_DUMMY) += dummy_stm.o
obj-$(CONFIG_STM_SOURCE_CONSOLE) += stm_console.o

stm_console-y := console.o
+
+obj-$(CONFIG_TRACE_EVENT_STM) += stm_trace_event.o
diff --git a/drivers/hwtracing/stm/stm_trace_event.c b/drivers/hwtracing/stm/stm_trace_event.c
new file mode 100644
index 0000000..bc77dae
--- /dev/null
+++ b/drivers/hwtracing/stm/stm_trace_event.c
@@ -0,0 +1,46 @@
+/*
+ * Simple kernel driver to link kernel trace event and an STM device
+ * Copyright (c) 2015, Linaro Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/console.h>
+#include <linux/stm.h>
+
+static struct stm_source_data stm_trace_event_data = {
+ .name = "stm_trace_event",
+ .nr_chans = 1,
+};
+
+void stm_trace_event_write(const char *buf, unsigned len)
+{
+ stm_source_write(&stm_trace_event_data, 0, buf, len);
+}
+
+static int __init stm_trace_event_init(void)
+{
+ return stm_source_register_device(NULL, &stm_trace_event_data);
+}
+
+static void __exit stm_trace_event_exit(void)
+{
+ stm_source_unregister_device(&stm_trace_event_data);
+}
+
+module_init(stm_trace_event_init);
+module_exit(stm_trace_event_exit);
+
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("stm_trace_event driver");
+MODULE_AUTHOR("Mathieu Poirier <[email protected]>");
--
1.9.1

2015-07-22 03:47:58

by Chunyan Zhang

[permalink] [raw]
Subject: [PATCH v4 2/3] trace: Introduce trace log output function for STM

This patch introduced a new function to print the trace events logs
to STM buffer when the trace event happens.

Signed-off-by: Chunyan Zhang <[email protected]>
---
kernel/trace/Makefile | 1 +
kernel/trace/trace_output_stm.c | 22 ++++++++++++++++++++++
2 files changed, 23 insertions(+)
create mode 100644 kernel/trace/trace_output_stm.c

diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
index 9b1044e..ac6c195 100644
--- a/kernel/trace/Makefile
+++ b/kernel/trace/Makefile
@@ -67,4 +67,5 @@ obj-$(CONFIG_UPROBE_EVENT) += trace_uprobe.o

obj-$(CONFIG_TRACEPOINT_BENCHMARK) += trace_benchmark.o

+obj-$(CONFIG_TRACE_EVENT_STM) += trace_output_stm.o
libftrace-y := ftrace.o
diff --git a/kernel/trace/trace_output_stm.c b/kernel/trace/trace_output_stm.c
new file mode 100644
index 0000000..42d5549
--- /dev/null
+++ b/kernel/trace/trace_output_stm.c
@@ -0,0 +1,22 @@
+#include <linux/trace_events.h>
+#include "trace_output.h"
+
+void trace_event_stm_log(struct trace_event_buffer *buffer)
+{
+ /* use static because iter can be a bit big for the stack */
+ static struct trace_iterator iter;
+ struct trace_entry *entry = (struct trace_entry *)buffer->entry;
+ struct trace_event *event = NULL;
+
+ iter.ent = entry;
+
+ if (entry)
+ event = ftrace_find_event(entry->type);
+
+ if (event && event->funcs) {
+ event->funcs->trace(&iter, 0, event);
+ stm_trace_event_write(iter.seq.buffer, iter.seq.seq.len);
+ iter.seq.seq.len = 0;
+ }
+}
+EXPORT_SYMBOL_GPL(trace_event_stm_log);
--
1.9.1

2015-07-22 03:48:06

by Chunyan Zhang

[permalink] [raw]
Subject: [PATCH v4 3/3] trace: Add an output of trace event logs to STM

When the trace event happens, the traces would be committed to ring buffer.
This patch will add an output of the traces to an STM at this moment,
of course the precondition is TRACE_EVENT_STM be configured.

Signed-off-by: Chunyan Zhang <[email protected]>
---
kernel/trace/trace_events.c | 2 ++
kernel/trace/trace_output.h | 7 +++++++
2 files changed, 9 insertions(+)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 404a372..35fd171 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -249,6 +249,8 @@ void trace_event_buffer_commit(struct trace_event_buffer *fbuffer)
event_trigger_unlock_commit(fbuffer->trace_file, fbuffer->buffer,
fbuffer->event, fbuffer->entry,
fbuffer->flags, fbuffer->pc);
+
+ trace_event_stm_log(fbuffer);
}
EXPORT_SYMBOL_GPL(trace_event_buffer_commit);

diff --git a/kernel/trace/trace_output.h b/kernel/trace/trace_output.h
index 4cbfe85..28e25e9 100644
--- a/kernel/trace/trace_output.h
+++ b/kernel/trace/trace_output.h
@@ -41,5 +41,12 @@ extern struct rw_semaphore trace_event_sem;
#define SEQ_PUT_HEX_FIELD(s, x) \
trace_seq_putmem_hex(s, &(x), sizeof(x))

+#ifdef CONFIG_TRACE_EVENT_STM
+extern void stm_trace_event_write(const char *buf, unsigned len);
+extern void trace_event_stm_log(struct trace_event_buffer *buffer);
+#else
+static inline void trace_event_stm_log(struct trace_event_buffer *buffer) {}
+#endif
+
#endif

--
1.9.1

2015-08-05 12:52:52

by Chunyan Zhang

[permalink] [raw]
Subject: Re: [PATCH v4 3/3] trace: Add an output of trace event logs to STM

Hello Steve,

May I have your further comments/suggestions on this version of patchset?
I know you were just back from a vacation, and must be very busy
recently, but after you finished the most urgent matters, could you
please leave us a little bandwidth to think about how you want these
patches to be improved.

Like I said in the former emails, if you don't have enough time to do
all the modifications, I hope I can more or less help with something.
But I really need your guidance.

Thank you so much,
Chunyan

On Wed, Jul 22, 2015 at 11:46 AM, Chunyan Zhang
<[email protected]> wrote:
> When the trace event happens, the traces would be committed to ring buffer.
> This patch will add an output of the traces to an STM at this moment,
> of course the precondition is TRACE_EVENT_STM be configured.
>
> Signed-off-by: Chunyan Zhang <[email protected]>
> ---
> kernel/trace/trace_events.c | 2 ++
> kernel/trace/trace_output.h | 7 +++++++
> 2 files changed, 9 insertions(+)
>
> diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> index 404a372..35fd171 100644
> --- a/kernel/trace/trace_events.c
> +++ b/kernel/trace/trace_events.c
> @@ -249,6 +249,8 @@ void trace_event_buffer_commit(struct trace_event_buffer *fbuffer)
> event_trigger_unlock_commit(fbuffer->trace_file, fbuffer->buffer,
> fbuffer->event, fbuffer->entry,
> fbuffer->flags, fbuffer->pc);
> +
> + trace_event_stm_log(fbuffer);
> }
> EXPORT_SYMBOL_GPL(trace_event_buffer_commit);
>
> diff --git a/kernel/trace/trace_output.h b/kernel/trace/trace_output.h
> index 4cbfe85..28e25e9 100644
> --- a/kernel/trace/trace_output.h
> +++ b/kernel/trace/trace_output.h
> @@ -41,5 +41,12 @@ extern struct rw_semaphore trace_event_sem;
> #define SEQ_PUT_HEX_FIELD(s, x) \
> trace_seq_putmem_hex(s, &(x), sizeof(x))
>
> +#ifdef CONFIG_TRACE_EVENT_STM
> +extern void stm_trace_event_write(const char *buf, unsigned len);
> +extern void trace_event_stm_log(struct trace_event_buffer *buffer);
> +#else
> +static inline void trace_event_stm_log(struct trace_event_buffer *buffer) {}
> +#endif
> +
> #endif
>
> --
> 1.9.1
>

2015-08-05 13:47:40

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH v4 3/3] trace: Add an output of trace event logs to STM

On Wed, 5 Aug 2015 20:52:49 +0800
Chunyan Zhang <[email protected]> wrote:

> Hello Steve,
>
> May I have your further comments/suggestions on this version of patchset?
> I know you were just back from a vacation, and must be very busy
> recently, but after you finished the most urgent matters, could you
> please leave us a little bandwidth to think about how you want these
> patches to be improved.
>
> Like I said in the former emails, if you don't have enough time to do
> all the modifications, I hope I can more or less help with something.
> But I really need your guidance.
>

Yeah I got a bunch of -rt stuff I'm trying to get through. I'll take a
look at this after that. Note, I will be traveling again soon, and will
be at the LinuxCon/Plumbers conference in a week and a half. But this
time I'll try to do work while I'm out (it's not a family vacation as
the last one was).

-- Steve