2022-06-13 10:03:22

by Yang Jihong

[permalink] [raw]
Subject: [RFC 07/13] perf kwork: Add irq report support

Implements irq kwork report function.

test case:

# perf kwork rep

Kwork Name | Cpu | Total Runtime | Frequency | Max runtime | Max runtime start | Max runtime end |
---------------------------------------------------------------------------------------------------------------------------
virtio0-requests:25 | 0000 | 429.202 ms | 7155 | 0.937 ms | 1906657.581035 s | 1906657.581973 s |
eth0:10 | 0002 | 0.136 ms | 5 | 0.045 ms | 1906656.302257 s | 1906656.302301 s |
---------------------------------------------------------------------------------------------------------------------------

#
# perf kwork rep -C 2

Kwork Name | Cpu | Total Runtime | Frequency | Max runtime | Max runtime start | Max runtime end |
---------------------------------------------------------------------------------------------------------------------------
eth0:10 | 0002 | 0.136 ms | 5 | 0.045 ms | 1906656.302257 s | 1906656.302301 s |
---------------------------------------------------------------------------------------------------------------------------

# perf kwork rep -C 1,2

Kwork Name | Cpu | Total Runtime | Frequency | Max runtime | Max runtime start | Max runtime end |
---------------------------------------------------------------------------------------------------------------------------
eth0:10 | 0002 | 0.136 ms | 5 | 0.045 ms | 1906656.302257 s | 1906656.302301 s |
---------------------------------------------------------------------------------------------------------------------------

# perf kwork rep -n eth0

Kwork Name | Cpu | Total Runtime | Frequency | Max runtime | Max runtime start | Max runtime end |
---------------------------------------------------------------------------------------------------------------------------
eth0:10 | 0002 | 0.136 ms | 5 | 0.045 ms | 1906656.302257 s | 1906656.302301 s |
---------------------------------------------------------------------------------------------------------------------------

# perf kwork rep -S

Kwork Name | Cpu | Total Runtime | Frequency | Max runtime | Max runtime start | Max runtime end |
---------------------------------------------------------------------------------------------------------------------------
virtio0-requests:25 | 0000 | 429.202 ms | 7155 | 0.937 ms | 1906657.581035 s | 1906657.581973 s |
eth0:10 | 0002 | 0.136 ms | 5 | 0.045 ms | 1906656.302257 s | 1906656.302301 s |
---------------------------------------------------------------------------------------------------------------------------
Total count : 7160
Total runtime (msec) : 429.338 (0.142% load average)
Total time span (msec) : 3013.347
---------------------------------------------------------------------------------------------------------------------------

# perf kwork rep --time 1906657,

Kwork Name | Cpu | Total Runtime | Frequency | Max runtime | Max runtime start | Max runtime end |
---------------------------------------------------------------------------------------------------------------------------
virtio0-requests:25 | 0000 | 228.631 ms | 3855 | 0.937 ms | 1906657.581035 s | 1906657.581973 s |
eth0:10 | 0002 | 0.092 ms | 4 | 0.034 ms | 1906658.614010 s | 1906658.614043 s |
---------------------------------------------------------------------------------------------------------------------------

Signed-off-by: Yang Jihong <[email protected]>
---
tools/perf/builtin-kwork.c | 62 ++++++++++++++++++++++++++++++++++++--
1 file changed, 60 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c
index ec199942150f..5741a8ac3e41 100644
--- a/tools/perf/builtin-kwork.c
+++ b/tools/perf/builtin-kwork.c
@@ -639,15 +639,73 @@ static int report_exit_event(struct perf_kwork *kwork,
return 0;
}

+static struct kwork_class kwork_irq;
+static int process_irq_handler_entry_event(struct perf_tool *tool,
+ struct evsel *evsel,
+ struct perf_sample *sample,
+ struct machine *machine)
+{
+ struct perf_kwork *kwork = container_of(tool, struct perf_kwork, tool);
+
+ if (kwork->tp_handler->entry_event)
+ return kwork->tp_handler->entry_event(kwork, &kwork_irq,
+ evsel, sample, machine);
+ return 0;
+}
+
+static int process_irq_handler_exit_event(struct perf_tool *tool,
+ struct evsel *evsel,
+ struct perf_sample *sample,
+ struct machine *machine)
+{
+ struct perf_kwork *kwork = container_of(tool, struct perf_kwork, tool);
+
+ if (kwork->tp_handler->exit_event)
+ return kwork->tp_handler->exit_event(kwork, &kwork_irq,
+ evsel, sample, machine);
+ return 0;
+}
+
const struct evsel_str_handler irq_tp_handlers[] = {
- { "irq:irq_handler_entry", NULL, },
- { "irq:irq_handler_exit", NULL, },
+ { "irq:irq_handler_entry", process_irq_handler_entry_event, },
+ { "irq:irq_handler_exit", process_irq_handler_exit_event, },
};

+static int irq_class_init(struct kwork_class *class,
+ struct perf_session *session)
+{
+ if (perf_session__set_tracepoints_handlers(session, irq_tp_handlers)) {
+ pr_debug("Failed to set irq tracepoints handlers\n");
+ return -1;
+ }
+
+ class->cluster_root = RB_ROOT_CACHED;
+ return 0;
+}
+
+static void irq_cluster_init(struct kwork_class *class,
+ struct kwork_cluster *cluster,
+ struct evsel *evsel,
+ struct perf_sample *sample)
+{
+ cluster->class = class;
+ cluster->cpu = sample->cpu;
+ cluster->id = evsel__intval(evsel, sample, "irq");
+ cluster->name = evsel__strval(evsel, sample, "name");
+}
+
+static void irq_cluster_name(struct kwork_cluster *cluster, char *buf, int len)
+{
+ snprintf(buf, len, "%s:%" PRIu64 "", cluster->name, cluster->id);
+}
+
static struct kwork_class kwork_irq = {
.name = "irq",
.nr_tracepoints = 2,
.tp_handlers = irq_tp_handlers,
+ .class_init = irq_class_init,
+ .cluster_init = irq_cluster_init,
+ .cluster_name = irq_cluster_name,
};

const struct evsel_str_handler softirq_tp_handlers[] = {
--
2.30.GIT