perf: measure page fault duration in perf trace
Subsystems (3)
cover perf: measure page fault duration in perf trace
Hi,
Here are 2 small patches which try to fulfill a point in the perf todo list:
* Forward port the page fault tracepoints and use it in 'trace'.
http://git.kernel.org/?p=linux/kernel/git/acme/linux.git;a=commitdiff;h=d53b11976093b6d8afeb8181db53aaffc754920d;hp=32ba4abf60ae1b710d22a75725491815de649bc5
There are some questionable points:
* With luck I think I found the patch related with the todo item (the link in the todo wiki page is broken); I hope I am not wrong...
* In the patch mentioned above, I found only changes related with tracepoints creations and calls; the tracepoints were declared generic (in include/trace/events/kmem.h) but were only called in x86 (arch/x86/mm/fault.c); as in x86, the tracepoint "mm_pagefault_start" looks fairly like "page_fault_user" and "page_fault_kernel", I decided to only create one x86-specific
tracepoint: "page_fault_exit"; maybe, you would prefer declaring generic tracepoints;
* No option has been added for activating page-fault duration
calculation: if the needed tracepoints are available, durations will be printed; maybe, that was not what you were looking for.
The patches were generated against tip/perf/core.
Alexis.
Alexis Berlemont (2):
perf, x86-mm: Add exit-fault tracing
perf: add page fault duration measures in perf trace
arch/x86/include/asm/trace/exceptions.h | 21 +++ arch/x86/mm/fault.c | 1 + tools/perf/builtin-trace.c | 225 ++++++++++++++++++++++++++++---- 3 files changed, 221 insertions(+), 26 deletions(-)
Signature · 1 line
2.10.1
PATCH 1/2 perf, x86-mm: Add exit-fault tracing
--- arch/x86/include/asm/trace/exceptions.h | 21 +++++++++++++++++++++ arch/x86/mm/fault.c | 1 + 2 files changed, 22 insertions(+)
arch/x86/include/asm/trace/exceptions.h +21 -0
@@ -43,6 +43,27 @@ DEFINE_EVENT_FN(x86_exceptions, name, \DEFINE_PAGE_FAULT_EVENT (page_fault_user);DEFINE_PAGE_FAULT_EVENT (page_fault_kernel); +TRACE_EVENT_FN (page_fault_exit, + + TP_PROTO(unsigned long address), + +TP_ARGS (address), + +TP_STRUCT__entry ( + __field(unsigned long, address) + ), + +TP_fast_assign ( + __entry->address = address; + ), + +TP_printk ("address=%lx" , __entry->address), + + trace_irq_vector_regfunc, + + trace_irq_vector_unregfunc +); +#undef TRACE_INCLUDE_PATH#define TRACE_INCLUDE_PATH .#define TRACE_INCLUDE_FILE exceptions
arch/x86/mm/fault.c +1 -0
@@ -1488,6 +1488,7 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code) prev_state =exception_enter ();trace_page_fault_entries (address, regs, error_code);__do_page_fault (regs, error_code, address); +trace_page_fault_exit (address);exception_exit (prev_state); }NOKPROBE_SYMBOL (trace_do_page_fault);
Signature · 1 line
2.10.1
Peter Zijlstra
maintainerRe: [PATCH 1/2] perf, x86-mm: Add exit-fault tracing
On Wed, Oct 26, 2016 at 01:51:59AM +0200, Alexis Berlemont wrote:
-ENOCHANGELOG
arch/x86/mm/fault.c trace_do_page_fault(struct pt_regs *regs, unsigned long error_code) · line 1491
Quoted 12 lines
Signed-off-by Alexis Berlemont <[email protected]>---
arch/x86/mm/fault.c +1
-0@@ -1488,6 +1488,7 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code) prev_state =exception_enter ();trace_page_fault_entries (address, regs, error_code);__do_page_fault (regs, error_code, address); +trace_page_fault_exit (address);
Aside from my general hatred of tracepoint, it bugs me that its not symmetric like the irq vector ones. But I'll leave that to x86 people.
Quoted 6 lines
arch/x86/mm/fault.c +0
-0exception_exit (prev_state); }NOKPROBE_SYMBOL (trace_do_page_fault);Signature · 1 line
2.10.1
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 1/2] perf, x86-mm: Add exit-fault tracing
Em Wed, Oct 26, 2016 at 10:51:16AM +0200, Peter Zijlstra escreveu:
Quoted 3 lines · Alexis Berlemont
-ENOCHANGELOG
Yeah, please add one explaining why we want this, how we can use it, for example, in 'perf trace', to measure how long each page fault took, examples of it in use, etc.
Quoted 15 lines
arch/x86/mm/fault.c trace_do_page_fault(struct pt_regs *regs, unsigned long error_code) · line 1491
Quoted 12 lines
Signed-off-by Alexis Berlemont <[email protected]>---
arch/x86/mm/fault.c +1
-0@@ -1488,6 +1488,7 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code) prev_state =exception_enter ();trace_page_fault_entries (address, regs, error_code);__do_page_fault (regs, error_code, address); +trace_page_fault_exit (address);Aside from my general hatred of tracepoint, it bugs me that its not symmetric like the irq vector ones. But I'll leave that to x86 people.
What is the simmetry problem, you think we should have:
exceptions:page_fault_kernel_exit
exceptions:page_fault_user_exit
To be counterparts of:
[root@jouet ~]# perf list exceptions:*
List of pre-defined events (to be used in -e):
exceptions:page_fault_kernel [Tracepoint event]
exceptions:page_fault_user [Tracepoint event]
[root@jouet ~]#
?
For perf usage yeah, the good thing would be to have just exceptions:page_fault_entry and exceptions:page_fault_exit, and then use perf_event_attr fields to filter what kind was desired, with a header.misc stating where it took place, just like with other events, but by now we have two for entry, so two for exit?
- Arnaldo
Quoted 6 lines
Quoted 6 lines
arch/x86/mm/fault.c +0
-0exception_exit (prev_state); }NOKPROBE_SYMBOL (trace_do_page_fault);Signature · 1 line
2.10.1
Peter Zijlstra
maintainerRe: [PATCH 1/2] perf, x86-mm: Add exit-fault tracing
Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 9 lines
arch/x86/mm/fault.c trace_do_page_fault(struct pt_regs *regs, unsigned long error_code) · line 1491
Quoted 6 lines
+++
b/arch/x86/mm/fault.carch/x86/mm/fault.c +1
-0@@ -1488,6 +1488,7 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code) prev_state =exception_enter ();trace_page_fault_entries (address, regs, error_code);__do_page_fault (regs, error_code, address); +trace_page_fault_exit (address);Aside from my general hatred of tracepoint, it bugs me that its not symmetric like the irq vector ones. But I'll leave that to x86 people.
What is the simmetry problem, you think we should have:
Look at arch/x86/include/asm/trace/irq_vectors.h and
$ git grep "trace.*_VECTOR"
The entry and exit tracepoints are fully symmetric and generate from a single macro.
PATCH v2 1/1 perf, x86-mm: declare page-faults tracepoints like irq-vectors ones
So, would you be OK with the following patch ?
There is a symmetry just like irq_vectors tracepoints:
# perf list | grep -E "exception|irq_vectors" exceptions:page_fault_kernel_entry [Tracepoint event] exceptions:page_fault_kernel_exit [Tracepoint event] exceptions:page_fault_user_entry [Tracepoint event] exceptions:page_fault_user_exit [Tracepoint event] irq_vectors:call_function_entry [Tracepoint event] irq_vectors:call_function_exit [Tracepoint event] ...
Maybe 2 tracepoints (instead of 4) should have been enough; however, there were already 1 tracepoint per mode before.
Alexis.
Alexis Berlemont (1):
perf, x86-mm: declare page-faults tracepoints like irq-vectors ones
arch/x86/include/asm/trace/exceptions.h | 17 ++++++++++++++++- arch/x86/mm/fault.c | 17 ++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-)
Signature · 1 line
2.10.1
PATCH v2 1/1 perf, x86-mm: declare page-faults tracepoints like irq-vectors ones
The tracepoints "exceptions:page_fault_(user|kernel)" were renamed "exceptions:page_fault_(user|kernel)_entry". Two more tracepoints were
added: "exceptions:page_fault_(user|kernel)_exit". These events are called right before and after __do_page_fault().
--- arch/x86/include/asm/trace/exceptions.h | 17 ++++++++++++++++- arch/x86/mm/fault.c | 17 ++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-)
arch/x86/include/asm/trace/exceptions.h +16 -1
@@ -33,14 +33,29 @@ DECLARE_EVENT_CLASS(x86_exceptions, __entry->error_code) );#define DEFINE_PAGE_FAULT_EVENT (name) \ -DEFINE_EVENT_FN(x86_exceptions, name, \ +DEFINE_EVENT_FN(x86_exceptions, name##_entry, \ + TP_PROTO(unsigned long address, struct pt_regs *regs, \ + unsigned long error_code), \ + TP_ARGS(address, regs, error_code), \ + trace_irq_vector_regfunc, \ + trace_irq_vector_unregfunc); \ +DEFINE_EVENT_FN(x86_exceptions, name##_exit, \ TP_PROTO(unsigned long address, struct pt_regs *regs, \ unsigned long error_code), \ TP_ARGS(address, regs, error_code), \ trace_irq_vector_regfunc, \ trace_irq_vector_unregfunc); +/* +* page_fault_user - called when entering/exiting a page fault in +* user-space +*/ DEFINE_PAGE_FAULT_EVENT (page_fault_user); + +/* +* page_fault_kernel - called when entering/exiting a page fault in +* kernel-space +*/ DEFINE_PAGE_FAULT_EVENT (page_fault_kernel);#undef TRACE_INCLUDE_PATH
arch/x86/mm/fault.c +14 -3
@@ -1465,12 +1465,22 @@ NOKPROBE_SYMBOL(do_page_fault);#ifdef CONFIG_TRACING static nokprobe_inline voidtrace_page_fault_entries (unsigned long address,struct pt_regs *regs, -unsigned long error_code) +unsigned long error_code) {if (user_mode (regs)) -trace_page_fault_user (address, regs, error_code); +trace_page_fault_user_entry (address, regs, error_code);else -trace_page_fault_kernel (address, regs, error_code); +trace_page_fault_kernel_entry (address, regs, error_code); +} + +static nokprobe_inline void +trace_page_fault_exits (unsigned long address,struct pt_regs *regs, +unsigned long error_code) +{ +if (user_mode (regs)) +trace_page_fault_user_exit (address, regs, error_code); +else +trace_page_fault_kernel_exit (address, regs, error_code); } dotraplinkage void notrace
@@ -1488,6 +1498,7 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code) prev_state =exception_enter ();trace_page_fault_entries (address, regs, error_code);__do_page_fault (regs, error_code, address); +trace_page_fault_exits (address, regs, error_code);exception_exit (prev_state); }NOKPROBE_SYMBOL (trace_do_page_fault);
Signature · 1 line
2.10.1
v3 cover perf: measure page fault duration in perf trace
In reply to Peter ZijlstraHi,
Here is another attempt to make the perf-trace subcommand print the page fault durations.
This solution is based on static tracepoints and it was necessary to add 2 more tracepoints. I understood that adding tracepoints is a questionable solution; I can try something else if someone has another idea.
Alexis.
Alexis Berlemont (2):
perf, x86-mm: declare page-faults tracepoints like irq-vectors ones
perf: add page fault duration measures in perf trace
arch/x86/include/asm/trace/exceptions.h | 17 ++- arch/x86/mm/fault.c | 17 ++- tools/perf/Documentation/perf-trace.txt | 4 +- tools/perf/builtin-trace.c | 231 ++++++++++++++++++++++++++++---- 4 files changed, 238 insertions(+), 31 deletions(-)
Signature · 1 line
2.10.2
PATCH v3 1/2 perf, x86-mm: declare page-faults tracepoints like irq-vectors ones
The tracepoints "exceptions:page_fault_(user|kernel)" were renamed "exceptions:page_fault_(user|kernel)_entry". Two more tracepoints were
added: "exceptions:page_fault_(user|kernel)_exit". These events are called right before and after __do_page_fault().
--- arch/x86/include/asm/trace/exceptions.h | 17 ++++++++++++++++- arch/x86/mm/fault.c | 17 ++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-)
arch/x86/include/asm/trace/exceptions.h +16 -1
@@ -33,14 +33,29 @@ DECLARE_EVENT_CLASS(x86_exceptions, __entry->error_code) );#define DEFINE_PAGE_FAULT_EVENT (name) \ -DEFINE_EVENT_FN(x86_exceptions, name, \ +DEFINE_EVENT_FN(x86_exceptions, name##_entry, \ + TP_PROTO(unsigned long address, struct pt_regs *regs, \ + unsigned long error_code), \ + TP_ARGS(address, regs, error_code), \ + trace_irq_vector_regfunc, \ + trace_irq_vector_unregfunc); \ +DEFINE_EVENT_FN(x86_exceptions, name##_exit, \ TP_PROTO(unsigned long address, struct pt_regs *regs, \ unsigned long error_code), \ TP_ARGS(address, regs, error_code), \ trace_irq_vector_regfunc, \ trace_irq_vector_unregfunc); +/* +* page_fault_user - called when entering/exiting a page fault in +* user-space +*/ DEFINE_PAGE_FAULT_EVENT (page_fault_user); + +/* +* page_fault_kernel - called when entering/exiting a page fault in +* kernel-space +*/ DEFINE_PAGE_FAULT_EVENT (page_fault_kernel);#undef TRACE_INCLUDE_PATH
arch/x86/mm/fault.c +14 -3
@@ -1465,12 +1465,22 @@ NOKPROBE_SYMBOL(do_page_fault);#ifdef CONFIG_TRACING static nokprobe_inline voidtrace_page_fault_entries (unsigned long address,struct pt_regs *regs, -unsigned long error_code) +unsigned long error_code) {if (user_mode (regs)) -trace_page_fault_user (address, regs, error_code); +trace_page_fault_user_entry (address, regs, error_code);else -trace_page_fault_kernel (address, regs, error_code); +trace_page_fault_kernel_entry (address, regs, error_code); +} + +static nokprobe_inline void +trace_page_fault_exits (unsigned long address,struct pt_regs *regs, +unsigned long error_code) +{ +if (user_mode (regs)) +trace_page_fault_user_exit (address, regs, error_code); +else +trace_page_fault_kernel_exit (address, regs, error_code); } dotraplinkage void notrace
@@ -1488,6 +1498,7 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code) prev_state =exception_enter ();trace_page_fault_entries (address, regs, error_code);__do_page_fault (regs, error_code, address); +trace_page_fault_exits (address, regs, error_code);exception_exit (prev_state); }NOKPROBE_SYMBOL (trace_do_page_fault);
Signature · 1 line
2.10.2
PATCH v3 2/2 perf: add page fault duration measures in perf trace
In reply to Alexis BerlemontThanks to the tracepoints exceptions:page_fault_kernel_exit and exceptions:page_fault_user_exit, the subcommand perf-trace can now print the duration of page-fault exception handling just like it is done for syscalls.
Here is the result; the page fault durations are indicated in parenthesis (like syscalls):
Here is an example; the durations are indicated in parenthesis just like with syscalls:
0.053 ( 0.053 ms): ls/152 minfault [__clear_user+0x25] => 0x694e7e (?k) 0.114 ( 0.027 ms): ls/152 minfault [__clear_user+0x25] => 0x7fb912eaafc0 (?k) 0.201 ( 0.030 ms): ls/152 minfault [_start+0x0] => /lib/ld-2.23.so@0xc70 (x.)
...
--- tools/perf/Documentation/perf-trace.txt | 4 +- tools/perf/builtin-trace.c | 231 ++++++++++++++++++++++++++++---- 2 files changed, 208 insertions(+), 27 deletions(-)
tools/perf/Documentation/perf-trace.txt +3 -1
@@ -117,7 +117,9 @@ the thread executes on the designated CPUs. Default is to monitor all CPUs. -F=[all|min|maj]:: --pf=[all|min|maj]:: Trace pagefaults. Optionally, you can specify whether you want minor, - major or all pagefaults. Default value is maj. + major or all pagefaults. Default value is maj. Durations of + page-fault handling will be printed if possible (need for some + architecture-dependent tracepoints). --syscalls:: Trace system calls. This options is enabled by default.
tools/perf/builtin-trace.c +205 -26
308 lines not on this page · raw message
Signature · 1 line
2.10.2
Quoted 10 lines · Alexis Berlemont
Hi,
Here is another attempt to make the perf-trace subcommand print the page fault durations.
This solution is based on static tracepoints and it was necessary to add 2 more tracepoints. I understood that adding tracepoints is a questionable solution; I can try something else if someone has another idea.
Could you indicate me a way to improve these patches so as to move forward ?
Regards,
Alexis.
Quoted 15 lines
Alexis.
Alexis Berlemont (2):
perf, x86-mm: declare page-faults tracepoints like irq-vectors ones
perf: add page fault duration measures in perf tracearch/x86/include/asm/trace/exceptions.h | 17 ++- arch/x86/mm/fault.c | 17 ++- tools/perf/Documentation/perf-trace.txt | 4 +- tools/perf/builtin-trace.c | 231 ++++++++++++++++++++++++++++---- 4 files changed, 238 insertions(+), 31 deletions(-)Signature · 1 line
2.10.2
Arnaldo Carvalho de Melo
maintainerEm Tue, Dec 06, 2016 at 12:40:06AM +0100, Alexis Berlemont escreveu:
Quoted 6 lines
Quoted 5 lines · Alexis Berlemont
Hi,
Here is another attempt to make the perf-trace subcommand print the page fault durations.
Quoted 8 lines
Quoted 5 lines
This solution is based on static tracepoints and it was necessary to add 2 more tracepoints. I understood that adding tracepoints is a questionable solution; I can try something else if someone has another idea.
Could you indicate me a way to improve these patches so as to move forward ?
I have to test this, and review PeterZ latest comment about it, to see if all is well with him by now, Peter?
- Arnaldo
Quoted 19 lines
Regards,
Alexis.
Quoted 15 lines
Alexis.
Alexis Berlemont (2):
perf, x86-mm: declare page-faults tracepoints like irq-vectors ones
perf: add page fault duration measures in perf tracearch/x86/include/asm/trace/exceptions.h | 17 ++- arch/x86/mm/fault.c | 17 ++- tools/perf/Documentation/perf-trace.txt | 4 +- tools/perf/builtin-trace.c | 231 ++++++++++++++++++++++++++++---- 4 files changed, 238 insertions(+), 31 deletions(-)Signature · 1 line
2.10.2
Peter Zijlstra
maintainerRe: [PATCH 1/2] perf, x86-mm: Add exit-fault tracing
In reply to Arnaldo Carvalho de MeloQuoted 8 lines · Arnaldo Carvalho de Melo
Em Wed, Oct 26, 2016 at 10:51:16AM +0200, Peter Zijlstra escreveu:
Quoted 3 lines · Alexis Berlemont
-ENOCHANGELOGYeah, please add one explaining why we want this, how we can use it, for example, in 'perf trace', to measure how long each page fault took, examples of it in use, etc.
Note that 'to measure page-fault duration' is not a reason, its a what. This needs a proper reason.
PATCH 2/2 perf: add page fault duration measures in perf trace
In reply to Alexis Berlemont--- tools/perf/Documentation/perf-trace.txt | 4 +- tools/perf/builtin-trace.c | 225 ++++++++++++++++++++++++++++---- 2 files changed, 202 insertions(+), 27 deletions(-)
tools/perf/Documentation/perf-trace.txt +3 -1
@@ -117,7 +117,9 @@ the thread executes on the designated CPUs. Default is to monitor all CPUs. -F=[all|min|maj]:: --pf=[all|min|maj]:: Trace pagefaults. Optionally, you can specify whether you want minor, - major or all pagefaults. Default value is maj. + major or all pagefaults. Default value is maj. Durations of + page-fault handling will be printed if possible (need for some + architecture-dependent tracepoints). --syscalls:: Trace system calls. This options is enabled by default.
tools/perf/builtin-trace.c +199 -26
302 lines not on this page · raw message
Signature · 1 line
2.10.1
Peter Zijlstra
maintainerQuoted 4 lines · Alexis Berlemont
Hi,
Here are 2 small patches which try to fulfill a point in the perf todo list:
There's a todo list?
Quoted 2 lines
* Forward port the page fault tracepoints and use it in 'trace'.
http://git.kernel.org/?p=linux/kernel/git/acme/linux.git;a=commitdiff;h=d53b11976093b6d8afeb8181db53aaffc754920d;hp=32ba4abf60ae1b710d22a75725491815de649bc5
dead link
Arnaldo Carvalho de Melo
maintainerEm Wed, Oct 26, 2016 at 10:46:18AM +0200, Peter Zijlstra escreveu:
Quoted 7 lines · Alexis Berlemont
Quoted 4 lines
Hi,
Here are 2 small patches which try to fulfill a point in the perf todo list:
There's a todo list?
https://perf.wiki.kernel.org/index.php/Todo
Quoted 4 lines
Quoted 2 lines
* Forward port the page fault tracepoints and use it in 'trace'.
http://git.kernel.org/?p=linux/kernel/git/acme/linux.git;a=commitdiff;h=d53b11976093b6d8afeb8181db53aaffc754920d;hp=32ba4abf60ae1b710d22a75725491815de649bc5dead link
I guess this is the one:
author Frederic Weisbecker <[email protected]> 2010-11-12 04:35:06 (GMT)
committer Ingo Molnar <[email protected]> 2011-05-07 16:10:43 (GMT)
commit eea86c6e06c241667c96c8e87e43c0870e1d6285 (patch)
tree b00ce7ef9a6219f4df6b0e1ffe453d2d5baf3593
parent 57d524154ffe99d27fb55e0e30ddbad9f4c35806 (diff)
perf, mm: Add fault tracing
Part of that are two modified patches from Jiri Olsa who added the fault tracepoints. I had to split them in two tracepoints so that we get the faults
handling duration.
Originally-from: Frederic Weisbecker <[email protected]>
--------------------
After that entry was added to the todo we got --pf, but no duration:
[root@jouet ~]# perf trace --pf maj --no-syscalls
0.000 ( 0.000 ms): perf/20412 majfault [__memcmp_sse4_1+0xbc6] => 0x7f1e0010c000 (?.)
1.156 ( 0.000 ms): perf/20412 majfault [__memcmp_sse4_1+0xbc6] => /usr/bin/mv@0x0 (d.)
56.907 ( 0.000 ms): perf/20412 majfault [__memcpy_avx_unaligned+0x1e7] => /usr/bin/mv@0x207a0 (d.)
57.683 ( 0.000 ms): perf/20412 majfault [__memcmp_sse4_1+0xbc6] => /usr/lib/debug/usr/bin/mv.debug@0x0 (d.)
60.916 ( 0.000 ms): perf/20412 majfault [__memcpy_avx_unaligned+0x2b6] => /usr/lib/debug/usr/bin/mv.debug@0x6ace0 (d.)
18446744073708.766 ( 0.000 ms): systemd-journa/578 majfault [0x14972] => 0x7f25bdd9ebd0 (?.)
70.193 ( 0.000 ms): perf/20412 majfault [__memcmp_sse4_1+0xbc6] => /usr/lib/debug/usr/lib/systemd/systemd-journald.debug@0x0 (d.)
71.176 ( 0.000 ms): perf/20412 majfault [__memcpy_avx_unaligned+0x2b6] => /usr/lib/debug/usr/lib/systemd/systemd-journald.debug@0x1221e0 (d.)^C[root@jouet ~]# trace -h --pf
Usage: perf trace [<options>] [<command>]
or: perf trace [<options>] -- <command> [<options>]
or: perf trace record [<options>] [<command>]
or: perf trace record [<options>] -- <command> [<options>]
-F, --pf <all|maj|min>
Trace pagefaults
[root@jouet ~]#