Skip to contentSkip to conversation

tasklet: Introduce tasklet tracepoints

PATCH In review Muchun Song 3 participants 5 messages Sep 5, 2020 – Sep 25, 2020 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tasklet: Introduce tasklet tracepoints

Introduce tracepoints for tasklets just like softirq does. In this case, we can calculate tasklet latency and know what tasklet run.

---
 include/trace/events/irq.h | 44 ++++++++++++++++++++++++++++++++++++++
 kernel/softirq.c           |  2 ++
 2 files changed, 46 insertions(+)
include/trace/events/irq.h +44 -0
index eeceafaaea4c..69a16f3a21c2 100644
@@ -160,6 +160,50 @@ DEFINE_EVENT(softirq, softirq_raise,
 	TP_ARGS(vec_nr)
 );
 
+DECLARE_EVENT_CLASS(tasklet,
+
+	TP_PROTO(struct tasklet_struct *t),
+
+	TP_ARGS(t),
+
+	TP_STRUCT__entry(
+		__field(	void *,	callback	)
+	),
+
+	TP_fast_assign(
+		__entry->callback = t->callback;
+	),
+
+	TP_printk("callback=%ps", __entry->callback)
+);
+
+/**
+ * tasklet_entry - called immediately before the tasklet handler
+ * @t: pointer to struct tasklet_struct
+ *
+ * When used in combination with the tasklet_exit tracepoint
+ * we can determine the tasklet handler routine.
+ */
+DEFINE_EVENT(tasklet, tasklet_entry,
+
+	TP_PROTO(struct tasklet_struct *t),
+
+	TP_ARGS(t)
+);
+
+/**
+ * tasklet_exit - called immediately after the tasklet handler returns
+ * @t: pointer to struct tasklet_struct
+ *
+ * When used in combination with the tasklet_entry tracepoint
+ * we can determine the tasklet handler routine.
+ */
+DEFINE_EVENT(tasklet, tasklet_exit,
+
+	TP_PROTO(struct tasklet_struct *t),
+
+	TP_ARGS(t)
+);
 #endif /*  _TRACE_IRQ_H */
 
 /* This part must be outside protection */
kernel/softirq.c +2 -0
index bf88d7f62433..0f9f5b2cc3d3 100644
@@ -553,10 +553,12 @@ static void tasklet_action_common(struct softirq_action *a,
 				if (!test_and_clear_bit(TASKLET_STATE_SCHED,
 							&t->state))
 					BUG();
+				trace_tasklet_entry(t);
 				if (t->use_callback)
 					t->callback(t);
 				else
 					t->func(t->data);
+				trace_tasklet_exit(t);
 				tasklet_unlock(t);
 				continue;
 			}
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 19 lines · On Sat, 5 Sep 2020 14:04:12 +0800 Muchun Song <[email protected]> wrote:

Introduce tracepoints for tasklets just like softirq does. In this case, we can calculate tasklet latency and know what tasklet run.

---
 include/trace/events/irq.h | 44 ++++++++++++++++++++++++++++++++++++++
 kernel/softirq.c           |  2 ++
 2 files changed, 46 insertions(+)
include/trace/events/irq.h +2 -0
index eeceafaaea4c..69a16f3a21c2 100644
@@ -160,6 +160,50 @@ DEFINE_EVENT(softirq, softirq_raise,
 	TP_ARGS(vec_nr)
 );
 
+DECLARE_EVENT_CLASS(tasklet,
+

include/trace/events/irq.h DEFINE_EVENT(softirq, softirq_raise, · line 174

Quoted 10 lines
include/trace/events/irq.h +10 -0
+	TP_PROTO(struct tasklet_struct *t),
+
+	TP_ARGS(t),
+
+	TP_STRUCT__entry(
+		__field(	void *,	callback	)
+	),
+
+	TP_fast_assign(
+		__entry->callback = t->callback;

I think you need to replicate the logic in the code:

		if (t->use_callback)
			__entry->callback = t->callback;
		else
			__entry->callback = t->func;

-- Steve

Quoted 52 lines
include/trace/events/irq.h +32 -0
+	),
+
+	TP_printk("callback=%ps", __entry->callback)
+);
+
+/**
+ * tasklet_entry - called immediately before the tasklet handler
+ * @t: pointer to struct tasklet_struct
+ *
+ * When used in combination with the tasklet_exit tracepoint
+ * we can determine the tasklet handler routine.
+ */
+DEFINE_EVENT(tasklet, tasklet_entry,
+
+	TP_PROTO(struct tasklet_struct *t),
+
+	TP_ARGS(t)
+);
+
+/**
+ * tasklet_exit - called immediately after the tasklet handler returns
+ * @t: pointer to struct tasklet_struct
+ *
+ * When used in combination with the tasklet_entry tracepoint
+ * we can determine the tasklet handler routine.
+ */
+DEFINE_EVENT(tasklet, tasklet_exit,
+
+	TP_PROTO(struct tasklet_struct *t),
+
+	TP_ARGS(t)
+);
 #endif /*  _TRACE_IRQ_H */
 
 /* This part must be outside protection */
kernel/softirq.c +2 -0
index bf88d7f62433..0f9f5b2cc3d3 100644
@@ -553,10 +553,12 @@ static void tasklet_action_common(struct softirq_action *a,
 				if (!test_and_clear_bit(TASKLET_STATE_SCHED,
 							&t->state))
 					BUG();
+				trace_tasklet_entry(t);
 				if (t->use_callback)
 					t->callback(t);
 				else
 					t->func(t->data);
+				trace_tasklet_exit(t);
 				tasklet_unlock(t);
 				continue;
 			}
#2 lore raw
Quoted 36 lines · Steven Rostedt
Quoted 19 lines · On Sat, 5 Sep 2020 14:04:12 +0800 Muchun Song <[email protected]> wrote:

Introduce tracepoints for tasklets just like softirq does. In this case, we can calculate tasklet latency and know what tasklet run.

---
 include/trace/events/irq.h | 44 ++++++++++++++++++++++++++++++++++++++
 kernel/softirq.c           |  2 ++
 2 files changed, 46 insertions(+)
include/trace/events/irq.h +2 -0
index eeceafaaea4c..69a16f3a21c2 100644
@@ -160,6 +160,50 @@ DEFINE_EVENT(softirq, softirq_raise,
      TP_ARGS(vec_nr)
 );
 
+DECLARE_EVENT_CLASS(tasklet,
+

include/trace/events/irq.h DEFINE_EVENT(softirq, softirq_raise, · line 174

Quoted 10 lines
include/trace/events/irq.h +10 -0
+     TP_PROTO(struct tasklet_struct *t),
+
+     TP_ARGS(t),
+
+     TP_STRUCT__entry(
+             __field(        void *, callback        )
+     ),
+
+     TP_fast_assign(
+             __entry->callback = t->callback;

I think you need to replicate the logic in the code:

Quoted 4 lines
                if (t->use_callback)
                        __entry->callback = t->callback;
                else
                        __entry->callback = t->func;

The callback and func is union and callback will replace func someday in the feature. So I think that here we use t->callback is enough. Right? Thanks.

Quoted 56 lines

-- Steve

Quoted 52 lines
include/trace/events/irq.h +32 -0
+     ),
+
+     TP_printk("callback=%ps", __entry->callback)
+);
+
+/**
+ * tasklet_entry - called immediately before the tasklet handler
+ * @t: pointer to struct tasklet_struct
+ *
+ * When used in combination with the tasklet_exit tracepoint
+ * we can determine the tasklet handler routine.
+ */
+DEFINE_EVENT(tasklet, tasklet_entry,
+
+     TP_PROTO(struct tasklet_struct *t),
+
+     TP_ARGS(t)
+);
+
+/**
+ * tasklet_exit - called immediately after the tasklet handler returns
+ * @t: pointer to struct tasklet_struct
+ *
+ * When used in combination with the tasklet_entry tracepoint
+ * we can determine the tasklet handler routine.
+ */
+DEFINE_EVENT(tasklet, tasklet_exit,
+
+     TP_PROTO(struct tasklet_struct *t),
+
+     TP_ARGS(t)
+);
 #endif /*  _TRACE_IRQ_H */
 
 /* This part must be outside protection */
kernel/softirq.c +2 -0
index bf88d7f62433..0f9f5b2cc3d3 100644
@@ -553,10 +553,12 @@ static void tasklet_action_common(struct softirq_action *a,
                              if (!test_and_clear_bit(TASKLET_STATE_SCHED,
                                                      &t->state))
                                      BUG();
+                             trace_tasklet_entry(t);
                              if (t->use_callback)
                                      t->callback(t);
                              else
                                      t->func(t->data);
+                             trace_tasklet_exit(t);
                              tasklet_unlock(t);
                              continue;
                      }
Signature · 2 lines
Yours,
Muchun
#3 lore raw
In reply to Muchun Song
Quoted 1 line · Muchun Song

Introduce tracepoints for tasklets just like softirq does.

What does softirq?

Quoted 2 lines

In this case, we can calculate tasklet latency and know what tasklet run.

I rather see people working on removal of tasklets.

Thanks,

tglx

#4 lore raw
Quoted 6 lines · Thomas Gleixner
Quoted 1 line · Muchun Song

Introduce tracepoints for tasklets just like softirq does.

What does softirq?

I mean that the softirq has tracepoints and the tasklet may also be needed.

Quoted 5 lines
Quoted 3 lines

In this case, we can calculate tasklet latency and know what tasklet run.

I rather see people working on removal of tasklets.

I do not know about this, why do we remove the tasklet?

Quoted 4 lines

Thanks,

tglx

Thanks.

Signature · 2 lines
Yours,
Muchun