Skip to contentSkip to conversation

perf tools: add 'perf irq' to measure the hardware interrupts

PATCH In review Bixuan Cui 2 participants 6 messages Jan 12, 2021 – Jan 14, 2021 perf events

lore
Share & tools
lore

Bixuan Cui

author
#0 lore raw

cover perf tools: add 'perf irq' to measure the hardware interrupts

When the hardware interrupt processing function is executed, the interrupt and preemption of current cpu are disabled. As a result, the task is suspended. The execution of the hardware processing function takes a long time (for example 5 ms), will affect the task scheduling performance.

This patches provides the 'perf irq' command to trace and calculate the time consumed of the hardware irq function.

[verse]
'perf irq' {record|timeconsume|script}

There are several variants of 'perf irq':

'perf irq record <command>' to record the irq handler events of an arbitrary workload.

'perf irq script' to see a detailed trace of the workload that
was recorded (aliased to 'perf script' for now).

'perf irq timeconsume' to calculate the time consumed by each
hardware interrupt processing function.

Example usage:
perf irq record -- sleep 1
perf irq timeconsume

By default it shows the individual irq events, including the irq name, cpu(execute the hardware interrupt processing function), time consumed, entry time and exit time for the each hardware irq:

-------------------------------------------------------------------------------------------------------------------------------------------
Irq name | CPU | Time consume us | Handler entry time | Handler exit time
-------------------------------------------------------------------------------------------------------------------------------------------

     enp2s0f2-tx-0    | [0006] |      0.000001 s |   6631263.313329 s |   6631263.313330 s

-------------------------------------------------------------------------------------------------------------------------------------------
Irq name | CPU | Time consume us | Handler entry time | Handler exit time
-------------------------------------------------------------------------------------------------------------------------------------------

     megasas          | [0013] |      0.000003 s |   6631263.209564 s |   6631263.209567 s

-------------------------------------------------------------------------------------------------------------------------------------------
Irq name | CPU | Time consume us | Handler entry time | Handler exit time
-------------------------------------------------------------------------------------------------------------------------------------------

     acpi             | [0016] |      0.000018 s |   6631263.085787 s |   6631263.085805 s

Bixuan Cui (2):
perf tools: add 'perf irq' to measure the hardware interrupts perf tools: Add documentation for 'perf irq' command

 tools/perf/Build                      |   1 +
 tools/perf/Documentation/perf-irq.txt |  58 ++++++
 tools/perf/builtin-irq.c              | 288 ++++++++++++++++++++++++++
 tools/perf/builtin.h                  |   1 +
 tools/perf/command-list.txt           |   1 +
 tools/perf/perf.c                     |   1 +
 6 files changed, 350 insertions(+)
 create mode 100644 tools/perf/Documentation/perf-irq.txt
 create mode 100644 tools/perf/builtin-irq.c
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 1/2 perf tools: add 'perf irq' to measure the hardware interrupts

Add 'perf irq' to trace/measure the hardware interrupts.

Now three functions are provided:
1. 'perf irq record <command>' to record the irq handler events.
2. 'perf irq script' to see a detailed trace of the workload that was recorded.
3. 'perf irq timeconsume' to calculate the time consumed by each hardware interrupt processing function.

---
 tools/perf/Build         |   1 +
 tools/perf/builtin-irq.c | 288 +++++++++++++++++++++++++++++++++++++++
 tools/perf/builtin.h     |   1 +
 tools/perf/perf.c        |   1 +
 4 files changed, 291 insertions(+)
 create mode 100644 tools/perf/builtin-irq.c
tools/perf/Build +1 -0
index 5f392dbb88fc..d52a1e1d6d8a 100644
@@ -24,6 +24,7 @@ perf-y += builtin-mem.o
 perf-y += builtin-data.o
 perf-y += builtin-version.o
 perf-y += builtin-c2c.o
+perf-y += builtin-irq.o
 
 perf-$(CONFIG_TRACE) += builtin-trace.o
 perf-$(CONFIG_LIBELF) += builtin-probe.o
tools/perf/builtin-irq.c new file +288 -0

288 lines not on this page · raw message

tools/perf/builtin.h +1 -0
index 14a2db622a7b..fd92dfc89370 100644
@@ -37,6 +37,7 @@ int cmd_inject(int argc, const char **argv);
 int cmd_mem(int argc, const char **argv);
 int cmd_data(int argc, const char **argv);
 int cmd_ftrace(int argc, const char **argv);
+int cmd_irq(int argc, const char **argv);
 
 int find_scripts(char **scripts_array, char **scripts_path_array, int num,
 		 int pathlen);
tools/perf/perf.c +1 -0
index 27f94b0bb874..df9cb344c2d0 100644
@@ -88,6 +88,7 @@ static struct cmd_struct commands[] = {
 	{ "mem",	cmd_mem,	0 },
 	{ "data",	cmd_data,	0 },
 	{ "ftrace",	cmd_ftrace,	0 },
+	{ "irq",	cmd_irq,	0 },
 };
 
 struct pager_config {
Signature · 1 line
2.17.1
#2 lore raw

Hi Bixuan,

Quoted 10 lines · Bixuan Cui

Add 'perf irq' to trace/measure the hardware interrupts.

Now three functions are provided:
1. 'perf irq record <command>' to record the irq handler events.
2. 'perf irq script' to see a detailed trace of the workload that was recorded.
3. 'perf irq timeconsume' to calculate the time consumed by each hardware interrupt processing function.

Thanks for the patches. There is still something that could be improved.

Quoted 8 lines
---
 tools/perf/Build         |   1 +
 tools/perf/builtin-irq.c | 288 +++++++++++++++++++++++++++++++++++++++
 tools/perf/builtin.h     |   1 +
 tools/perf/perf.c        |   1 +
 4 files changed, 291 insertions(+)
 create mode 100644 tools/perf/builtin-irq.c

<SNIP>

tools/perf/builtin-irq.c line 221

Quoted 8 lines
tools/perf/builtin-irq.c new file +8 -0
+
+static int __cmd_record(int argc, const char **argv)
+{
+	unsigned int rec_argc, i, j;
+	const char **rec_argv;
+	const char * const record_args[] = {
+		"record",
+		"-a",

I see it works also like this:

sudo perf record -p PID -c 1 -e irq:irq_handler_entry,irq:irq_handler_exit sudo perf record -R -c 1 -e irq:irq_handler_entry,irq:irq_handler_exit -- find /

This -a option jointly with -p option could be made configurable from the command line for perf irq mode.

tools/perf/builtin-irq.c line 223

Quoted 2 lines
tools/perf/builtin-irq.c new file +2 -0
+		"-R",
+		"-m", "1024",

Do you see data losses with default buffer size of 512KB when capturing trace in your specific use case?

If not then this -m could be avoided or made configurable if you still need it.

Regards,
Alexei

author
#3 lore raw
Quoted 35 lines · Alexei Budankov

Hi Bixuan,

Quoted 10 lines · Bixuan Cui

Add 'perf irq' to trace/measure the hardware interrupts.

Now three functions are provided:
1. 'perf irq record <command>' to record the irq handler events.
2. 'perf irq script' to see a detailed trace of the workload that was recorded.
3. 'perf irq timeconsume' to calculate the time consumed by each hardware interrupt processing function.

Thanks for the patches. There is still something that could be improved.

Quoted 8 lines
---
 tools/perf/Build         |   1 +
 tools/perf/builtin-irq.c | 288 +++++++++++++++++++++++++++++++++++++++
 tools/perf/builtin.h     |   1 +
 tools/perf/perf.c        |   1 +
 4 files changed, 291 insertions(+)
 create mode 100644 tools/perf/builtin-irq.c

<SNIP>

tools/perf/builtin-irq.c line 221

Quoted 8 lines
tools/perf/builtin-irq.c new file +8 -0
+
+static int __cmd_record(int argc, const char **argv)
+{
+	unsigned int rec_argc, i, j;
+	const char **rec_argv;
+	const char * const record_args[] = {
+		"record",
+		"-a",

I see it works also like this:

Quoted 5 lines

sudo perf record -p PID -c 1 -e irq:irq_handler_entry,irq:irq_handler_exit sudo perf record -R -c 1 -e irq:irq_handler_entry,irq:irq_handler_exit -- find /

This -a option jointly with -p option could be made configurable from the command line for perf irq mode.

That's true. We can add a series of commands for 'perf irq',such as record, script and report. So I kept the 'perf irq record'.

Quoted 8 lines

tools/perf/builtin-irq.c line 223

Quoted 3 lines
tools/perf/builtin-irq.c new file +2 -0
+		"-R",
+		"-m", "1024",

Do you see data losses with default buffer size of 512KB when capturing trace in your specific use case?

If not then this -m could be avoided or made configurable if you still need it.

Thank you for your advice, I will delete it.

author
#4 lore raw

PATCH 2/2 perf tools: Add documentation for 'perf irq' command

In reply to Bixuan Cui

Add documentation for 'perf irq' command.

---
 tools/perf/Documentation/perf-irq.txt | 58 +++++++++++++++++++++++++++
 tools/perf/command-list.txt           |  1 +
 2 files changed, 59 insertions(+)
 create mode 100644 tools/perf/Documentation/perf-irq.txt
tools/perf/Documentation/perf-irq.txt new file +58 -0
new file mode 100644
index 000000000000..8c0e388dad59
@@ -0,0 +1,58 @@
+perf-irq(1)
+=============
+
+NAME
+----
+perf-irq - Tool to trace/measure hardware interrupts
+
+SYNOPSIS
+--------
+[verse]
+'perf irq' {record|timeconsume|script}
+
+DESCRIPTION
+-----------
+There are several variants of 'perf irq':
+
+  'perf irq record <command>' to record the irq handler events
+  of an arbitrary workload.
+
+  'perf irq script' to see a detailed trace of the workload that
+   was recorded (aliased to 'perf script' for now).
+
+  'perf irq timeconsume' to calculate the time consumed by each
+   hardware interrupt processing function.
+
+    Example usage:
+        perf irq record -- sleep 1
+        perf irq timeconsume
+
+   By default it shows the individual irq events, including the irq name,
+   cpu(execute the hardware interrupt processing function), time consumed,
+   entry time and exit time for the each hardware irq:
+
+   -------------------------------------------------------------------------------------------------------------------------------------------
+     Irq name         |  CPU   | Time consume us | Handler entry time | Handler exit time
+   -------------------------------------------------------------------------------------------------------------------------------------------
+     enp2s0f2-tx-0    | [0006] |      0.000001 s |   6631263.313329 s |   6631263.313330 s
+
+   -------------------------------------------------------------------------------------------------------------------------------------------
+     Irq name         |  CPU   | Time consume us | Handler entry time | Handler exit time
+   -------------------------------------------------------------------------------------------------------------------------------------------
+     megasas          | [0013] |      0.000003 s |   6631263.209564 s |   6631263.209567 s
+
+   -------------------------------------------------------------------------------------------------------------------------------------------
+     Irq name         |  CPU   | Time consume us | Handler entry time | Handler exit time
+   -------------------------------------------------------------------------------------------------------------------------------------------
+     acpi             | [0016] |      0.000018 s |   6631263.085787 s |   6631263.085805 s
+
+
+OPTIONS for 'perf irq'
+----------------------------
+
+--cpus::
+	Show just entries with activities for the given CPUs.
+
+SEE ALSO
+--------
+linkperf:perf-record[1]
tools/perf/command-list.txt +1 -0
index bc6c585f74fc..c5224ea3ac71 100644
@@ -26,6 +26,7 @@ perf-report			mainporcelain common
 perf-sched			mainporcelain common
 perf-script			mainporcelain common
 perf-stat			mainporcelain common
+perf-irq			mainporcelain common
 perf-test			mainporcelain common
 perf-timechart			mainporcelain common
 perf-top			mainporcelain common
Signature · 1 line
2.17.1
#5 lore raw

Re: [PATCH 2/2] perf tools: Add documentation for 'perf irq' command

Hi,

Quoted 33 lines · Bixuan Cui

Add documentation for 'perf irq' command.

---
 tools/perf/Documentation/perf-irq.txt | 58 +++++++++++++++++++++++++++
 tools/perf/command-list.txt           |  1 +
 2 files changed, 59 insertions(+)
 create mode 100644 tools/perf/Documentation/perf-irq.txt
tools/perf/Documentation/perf-irq.txt new file +18 -0
new file mode 100644
index 000000000000..8c0e388dad59
@@ -0,0 +1,58 @@
+perf-irq(1)
+=============
+
+NAME
+----
+perf-irq - Tool to trace/measure hardware interrupts
+
+SYNOPSIS
+--------
+[verse]
+'perf irq' {record|timeconsume|script}
+
+DESCRIPTION
+-----------
+There are several variants of 'perf irq':
+
+  'perf irq record <command>' to record the irq handler events
+  of an arbitrary workload.

tools/perf/Documentation/perf-irq.txt line 28

Quoted 10 lines
tools/perf/Documentation/perf-irq.txt new file +10 -0
+
+  'perf irq script' to see a detailed trace of the workload that
+   was recorded (aliased to 'perf script' for now).
+
+  'perf irq timeconsume' to calculate the time consumed by each
+   hardware interrupt processing function.
+
+    Example usage:
+        perf irq record -- sleep 1
+        perf irq timeconsume

This timeconsume mode looks more like: perf irq report <options>

Quoted 16 lines
tools/perf/Documentation/perf-irq.txt new file +16 -0
+
+   By default it shows the individual irq events, including the irq name,
+   cpu(execute the hardware interrupt processing function), time consumed,
+   entry time and exit time for the each hardware irq:
+
+   -------------------------------------------------------------------------------------------------------------------------------------------
+     Irq name         |  CPU   | Time consume us | Handler entry time | Handler exit time
+   -------------------------------------------------------------------------------------------------------------------------------------------
+     enp2s0f2-tx-0    | [0006] |      0.000001 s |   6631263.313329 s |   6631263.313330 s
+
+   -------------------------------------------------------------------------------------------------------------------------------------------
+     Irq name         |  CPU   | Time consume us | Handler entry time | Handler exit time
+   -------------------------------------------------------------------------------------------------------------------------------------------
+     megasas          | [0013] |      0.000003 s |   6631263.209564 s |   6631263.209567 s
+
+   -------------------------------------------------------------------------------------------------------------------------------------------

tools/perf/Documentation/perf-irq.txt line 54

Quoted 10 lines
tools/perf/Documentation/perf-irq.txt new file +10 -0
+     Irq name         |  CPU   | Time consume us | Handler entry time | Handler exit time
+   -------------------------------------------------------------------------------------------------------------------------------------------
+     acpi             | [0016] |      0.000018 s |   6631263.085787 s |   6631263.085805 s
+
+
+OPTIONS for 'perf irq'
+----------------------------
+
+--cpus::
+	Show just entries with activities for the given CPUs.

I am getting this:

tools/perf/perf irq --cpus=0 record -- find /
Error: unknown option `cpus=0'

Usage: perf irq [<options>] {record|timeconsume|script}

Regards,
Alexei