2022-05-09 09:44:28

by Junwen Wu

[permalink] [raw]
Subject: [PATCH v1] softirq: Add tracepoint for tasklet_entry/exit

Usually softirq handler is pre-defined,only tasklet can be register by
driver.We expand tracepoint for tasklet_entry/exit to trace
tasklet handler.

Signed-off-by: Junwen Wu <[email protected]>
---
include/trace/events/irq.h | 32 ++++++++++++++++++++++++++++++++
kernel/softirq.c | 4 ++++
2 files changed, 36 insertions(+)

diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
index eeceafaaea4c..d3e922dcd475 100644
--- a/include/trace/events/irq.h
+++ b/include/trace/events/irq.h
@@ -160,6 +160,38 @@ DEFINE_EVENT(softirq, softirq_raise,
TP_ARGS(vec_nr)
);

+TRACE_EVENT(tasklet_entry,
+
+ TP_PROTO(void *func),
+
+ TP_ARGS(func),
+
+ TP_STRUCT__entry(
+ __field( void *, func )
+ ),
+
+ TP_fast_assign(
+ __entry->func = func;
+ ),
+
+ TP_printk("function=%ps", __entry->func)
+);
+TRACE_EVENT(tasklet_exit,
+
+ TP_PROTO(void *func),
+
+ TP_ARGS(func),
+
+ TP_STRUCT__entry(
+ __field( void *, func )
+ ),
+
+ TP_fast_assign(
+ __entry->func = func;
+ ),
+
+ TP_printk("function=%ps", __entry->func)
+);
#endif /* _TRACE_IRQ_H */

/* This part must be outside protection */
diff --git a/kernel/softirq.c b/kernel/softirq.c
index 41f470929e99..b3bce2b3b655 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -780,10 +780,14 @@ static void tasklet_action_common(struct softirq_action *a,
if (tasklet_trylock(t)) {
if (!atomic_read(&t->count)) {
if (tasklet_clear_sched(t)) {
+ trace_tasklet_entry(t->use_callback ? (void *)t->callback
+ : (void *)t->func);
if (t->use_callback)
t->callback(t);
else
t->func(t->data);
+ trace_tasklet_exit(t->use_callback ? (void *)t->callback
+ : (void *)t->func);
}
tasklet_unlock(t);
continue;
--
2.25.1



2022-05-25 03:35:38

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH v1] softirq: Add tracepoint for tasklet_entry/exit

On Sun, 8 May 2022 16:06:24 +0000
Junwen Wu <[email protected]> wrote:

> --- a/include/trace/events/irq.h
> +++ b/include/trace/events/irq.h
> @@ -160,6 +160,38 @@ DEFINE_EVENT(softirq, softirq_raise,
> TP_ARGS(vec_nr)
> );
>
> +TRACE_EVENT(tasklet_entry,
> +
> + TP_PROTO(void *func),
> +
> + TP_ARGS(func),
> +
> + TP_STRUCT__entry(
> + __field( void *, func )
> + ),
> +
> + TP_fast_assign(
> + __entry->func = func;
> + ),
> +
> + TP_printk("function=%ps", __entry->func)
> +);
> +TRACE_EVENT(tasklet_exit,
> +
> + TP_PROTO(void *func),
> +
> + TP_ARGS(func),
> +
> + TP_STRUCT__entry(
> + __field( void *, func )
> + ),
> +
> + TP_fast_assign(
> + __entry->func = func;
> + ),
> +
> + TP_printk("function=%ps", __entry->func)

This needs an acked-by from Thomas, but regardless, the above two trace
events are identical. You need to have a DECLARE_EVENT_CLASS() followed by
two DEFINE_EVENT()s, otherwise you are wasting memory.

-- Steve


> +);
> #endif /* _TRACE_IRQ_H */
>
> /* This part must be outside protection */
> diff --git a/kernel/softirq.c b/kernel/softirq.c
> index 41f470929e99..b3bce2b3b655 100644
> --- a/kernel/softirq.c
> +++ b/kernel/softirq.c
> @@ -780,10 +780,14 @@ static void tasklet_action_common(struct softirq_action *a,
> if (tasklet_trylock(t)) {
> if (!atomic_read(&t->count)) {
> if (tasklet_clear_sched(t)) {
> + trace_tasklet_entry(t->use_callback ? (void *)t->callback
> + : (void *)t->func);
> if (t->use_callback)
> t->callback(t);
> else
> t->func(t->data);
> + trace_tasklet_exit(t->use_callback ? (void *)t->callback
> + : (void *)t->func);
> }
> tasklet_unlock(t);
> continue;


2022-05-28 18:14:46

by Junwen Wu

[permalink] [raw]
Subject: Re: [PATCH v1] softirq: Add tracepoint for tasklet_entry/exit

From: Steven Rostedt <[email protected]>

>> +
>> + TP_printk("function=%ps", __entry->func)

>This needs an acked-by from Thomas, but regardless, the above two trace
>events are identical. You need to have a DECLARE_EVENT_CLASS() followed by
>two DEFINE_EVENT()s, otherwise you are wasting memory.

I have use DECLARE_EVENT_CLASS() define use tracepoint,Steve.
Thomas, can you give me acked-by,here is patch v2.


From 68d2298372018ec90c8587d5421a0e1a3c9f879f Mon Sep 17 00:00:00 2001
From: Junwen Wu <[email protected]>
Date: Sun, 8 May 2022 15:29:56 +0000
Subject: [PATCH v2] softirq: Add tracepoint for tasklet_entry/exit

Usually softirq handler is pre-defined,only tasklet can be register by
driver.We expand tracepoint for tasklet_entry/exit to trace
tasklet handler.

Signed-off-by: Junwen Wu <[email protected]>
---
include/trace/events/irq.h | 41 ++++++++++++++++++++++++++++++++++++++
kernel/softirq.c | 4 ++++
2 files changed, 45 insertions(+)

diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
index eeceafaaea4c..62b7e53121da 100644
--- a/include/trace/events/irq.h
+++ b/include/trace/events/irq.h
@@ -160,6 +160,47 @@ DEFINE_EVENT(softirq, softirq_raise,
TP_ARGS(vec_nr)
);

+DECLARE_EVENT_CLASS(tasklet,
+
+ TP_PROTO(void *func),
+
+ TP_ARGS(func),
+
+ TP_STRUCT__entry(
+ __field( void*, func )
+ ),
+
+ TP_fast_assign(
+ __entry->func = func;
+ ),
+
+ TP_printk("function=%ps", __entry->func)
+);
+
+/**
+ * tasklet_entry - called immediately when a tasklet exec
+ * @func: the callback function when a tasklet exec
+ *
+ * When used in combination with the tasklet_entry tracepoint
+ * we can determine the callback function when a tasklet exec.
+ */
+DEFINE_EVENT(tasklet, tasklet_entry,
+
+ TP_PROTO(void *func),
+
+ TP_ARGS(func)
+);
+
+/**
+ * tasklet_exit - called immediately after the tasklet handler returns
+ * @func: the callback function when a tasklet exec
+ */
+DEFINE_EVENT(tasklet, tasklet_exit,
+
+ TP_PROTO(void *func),
+
+ TP_ARGS(func)
+);
#endif /* _TRACE_IRQ_H */

/* This part must be outside protection */
diff --git a/kernel/softirq.c b/kernel/softirq.c
index 41f470929e99..79b3814ad166 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -780,10 +780,14 @@ static void tasklet_action_common(struct softirq_action *a,
if (tasklet_trylock(t)) {
if (!atomic_read(&t->count)) {
if (tasklet_clear_sched(t)) {
+ trace_tasklet_entry(t->use_callback ? (void *)t->callback
+ : (void *)t->func);
if (t->use_callback)
t->callback(t);
else
t->func(t->data);
+ trace_tasklet_exit(t->use_callback ? (void *)t->callback
+ : (void *)t->func);
}
tasklet_unlock(t);
continue;
--
2.25.1


2022-05-28 19:38:15

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH v1] softirq: Add tracepoint for tasklet_entry/exit

On Sat, 28 May 2022 13:54:11 +0000
Junwen Wu <[email protected]> wrote:

> >From 68d2298372018ec90c8587d5421a0e1a3c9f879f Mon Sep 17 00:00:00 2001
> From: Junwen Wu <[email protected]>
> Date: Sun, 8 May 2022 15:29:56 +0000
> Subject: [PATCH v2] softirq: Add tracepoint for tasklet_entry/exit

You should always send a v2 as a separate email starting a new thread.

>
> Usually softirq handler is pre-defined,only tasklet can be register by
> driver.We expand tracepoint for tasklet_entry/exit to trace
> tasklet handler.
>
> Signed-off-by: Junwen Wu <[email protected]>
> ---

And reference v1 here, by something like:

Changes since v1: https://lore.kernel.org/all/[email protected]/

- Used DECLARE_EVENT_CLASS (Steven Rostedt)


> include/trace/events/irq.h | 41 ++++++++++++++++++++++++++++++++++++++
> kernel/softirq.c | 4 ++++
> 2 files changed, 45 insertions(+)


-- Steve