diff mbox series

[v6,09/14] mm/damon: Add a tracepoint for result writing

Message ID 20200224123047.32506-10-sjpark@amazon.com (mailing list archive)
State New, archived
Headers show
Series Introduce Data Access MONitor (DAMON) | expand

Commit Message

SeongJae Park Feb. 24, 2020, 12:30 p.m. UTC
From: SeongJae Park <sjpark@amazon.de>

This commit adds a tracepoint for DAMON's result buffer writing.  It is
called for each writing of the DAMON results and print the result data.
Therefore, it would be used to easily integrated with other tracepoint
supporting tracers such as perf.

Signed-off-by: SeongJae Park <sjpark@amazon.de>
---
 include/trace/events/damon.h | 32 ++++++++++++++++++++++++++++++++
 mm/damon.c                   |  4 ++++
 2 files changed, 36 insertions(+)
 create mode 100644 include/trace/events/damon.h

Comments

Jonathan Cameron March 10, 2020, 9:03 a.m. UTC | #1
On Mon, 24 Feb 2020 13:30:42 +0100
SeongJae Park <sjpark@amazon.com> wrote:

> From: SeongJae Park <sjpark@amazon.de>
> 
> This commit adds a tracepoint for DAMON's result buffer writing.  It is
> called for each writing of the DAMON results and print the result data.
> Therefore, it would be used to easily integrated with other tracepoint
> supporting tracers such as perf.
> 
> Signed-off-by: SeongJae Park <sjpark@amazon.de>

I'm curious, why at the flush of rbuf rather than using a more structured trace
point for each of the writes into rbuf?

Seems it would make more sense to have a tracepoint for each record write out.
Probably at the level of each task, though might be more elegant to do it at the
level of each region within a task and duplicate the header stuff.

> ---
>  include/trace/events/damon.h | 32 ++++++++++++++++++++++++++++++++
>  mm/damon.c                   |  4 ++++
>  2 files changed, 36 insertions(+)
>  create mode 100644 include/trace/events/damon.h
> 
> diff --git a/include/trace/events/damon.h b/include/trace/events/damon.h
> new file mode 100644
> index 000000000000..fb33993620ce
> --- /dev/null
> +++ b/include/trace/events/damon.h
> @@ -0,0 +1,32 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#undef TRACE_SYSTEM
> +#define TRACE_SYSTEM damon
> +
> +#if !defined(_TRACE_DAMON_H) || defined(TRACE_HEADER_MULTI_READ)
> +#define _TRACE_DAMON_H
> +
> +#include <linux/types.h>
> +#include <linux/tracepoint.h>
> +
> +TRACE_EVENT(damon_write_rbuf,
> +
> +	TP_PROTO(void *buf, const ssize_t sz),
> +
> +	TP_ARGS(buf, sz),
> +
> +	TP_STRUCT__entry(
> +		__dynamic_array(char, buf, sz)
> +	),
> +
> +	TP_fast_assign(
> +		memcpy(__get_dynamic_array(buf), buf, sz);
> +	),
> +
> +	TP_printk("dat=%s", __print_hex(__get_dynamic_array(buf),
> +			__get_dynamic_array_len(buf)))
> +);
> +
> +#endif /* _TRACE_DAMON_H */
> +
> +/* This part must be outside protection */
> +#include <trace/define_trace.h>
> diff --git a/mm/damon.c b/mm/damon.c
> index facb1d7f121b..8faf3879f99e 100644
> --- a/mm/damon.c
> +++ b/mm/damon.c
> @@ -9,6 +9,8 @@
>  
>  #define pr_fmt(fmt) "damon: " fmt
>  
> +#define CREATE_TRACE_POINTS
> +
>  #include <linux/damon.h>
>  #include <linux/debugfs.h>
>  #include <linux/delay.h>
> @@ -20,6 +22,7 @@
>  #include <linux/sched/mm.h>
>  #include <linux/sched/task.h>
>  #include <linux/slab.h>
> +#include <trace/events/damon.h>
>  
>  #define damon_get_task_struct(t) \
>  	(get_pid_task(find_vpid(t->pid), PIDTYPE_PID))
> @@ -553,6 +556,7 @@ static void damon_flush_rbuffer(struct damon_ctx *ctx)
>   */
>  static void damon_write_rbuf(struct damon_ctx *ctx, void *data, ssize_t size)
>  {
> +	trace_damon_write_rbuf(data, size);
>  	if (!ctx->rbuf_len || !ctx->rbuf)
>  		return;
>  	if (ctx->rbuf_offset + size > ctx->rbuf_len)
diff mbox series

Patch

diff --git a/include/trace/events/damon.h b/include/trace/events/damon.h
new file mode 100644
index 000000000000..fb33993620ce
--- /dev/null
+++ b/include/trace/events/damon.h
@@ -0,0 +1,32 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM damon
+
+#if !defined(_TRACE_DAMON_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_DAMON_H
+
+#include <linux/types.h>
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(damon_write_rbuf,
+
+	TP_PROTO(void *buf, const ssize_t sz),
+
+	TP_ARGS(buf, sz),
+
+	TP_STRUCT__entry(
+		__dynamic_array(char, buf, sz)
+	),
+
+	TP_fast_assign(
+		memcpy(__get_dynamic_array(buf), buf, sz);
+	),
+
+	TP_printk("dat=%s", __print_hex(__get_dynamic_array(buf),
+			__get_dynamic_array_len(buf)))
+);
+
+#endif /* _TRACE_DAMON_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
diff --git a/mm/damon.c b/mm/damon.c
index facb1d7f121b..8faf3879f99e 100644
--- a/mm/damon.c
+++ b/mm/damon.c
@@ -9,6 +9,8 @@ 
 
 #define pr_fmt(fmt) "damon: " fmt
 
+#define CREATE_TRACE_POINTS
+
 #include <linux/damon.h>
 #include <linux/debugfs.h>
 #include <linux/delay.h>
@@ -20,6 +22,7 @@ 
 #include <linux/sched/mm.h>
 #include <linux/sched/task.h>
 #include <linux/slab.h>
+#include <trace/events/damon.h>
 
 #define damon_get_task_struct(t) \
 	(get_pid_task(find_vpid(t->pid), PIDTYPE_PID))
@@ -553,6 +556,7 @@  static void damon_flush_rbuffer(struct damon_ctx *ctx)
  */
 static void damon_write_rbuf(struct damon_ctx *ctx, void *data, ssize_t size)
 {
+	trace_damon_write_rbuf(data, size);
 	if (!ctx->rbuf_len || !ctx->rbuf)
 		return;
 	if (ctx->rbuf_offset + size > ctx->rbuf_len)