Skip to contentSkip to conversation

x86:Instruments page fault trace event

PATCH New Francis Deslauriers 2 participants 7 messages Apr 8, 2013 – Apr 11, 2013 4 messages not in the archive

Subsystems (5)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/2 Add page fault trace event definitions

Add page_fault_entry and page_fault_exit event definitions. It will allow each architecture to instrument their page faults.

---
 include/trace/events/fault.h |   51 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 include/trace/events/fault.h
include/trace/events/fault.h new file +51 -0
new file mode 100644
index 0000000..522ddee
@@ -0,0 +1,51 @@
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM fault
+
+#if !defined(_TRACE_FAULT_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_FAULT_H
+
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(page_fault_entry,
+
+	TP_PROTO(struct pt_regs *regs, unsigned long address,
+					int write_access),
+
+	TP_ARGS(regs, address, write_access),
+
+	TP_STRUCT__entry(
+		__field(	unsigned long,	ip	)
+		__field(	unsigned long,	addr	)
+		__field(	uint8_t,	write	)
+	),
+
+	TP_fast_assign(
+		__entry->ip	= regs ? instruction_pointer(regs) : 0UL;
+		__entry->addr	= address;
+		__entry->write	= !!write_access;
+	),
+
+	TP_printk("ip=%lu addr=%lu write_access=%d",
+		__entry->ip, __entry->addr, __entry->write)
+);
+
+TRACE_EVENT(page_fault_exit,
+
+	TP_PROTO(int result),
+
+	TP_ARGS(result),
+
+	TP_STRUCT__entry(
+		__field(	int,	res	)
+	),
+
+	TP_fast_assign(
+		__entry->res	= result;
+	),
+
+	TP_printk("result=%d", __entry->res)
+);
+
+#endif /* _TRACE_FAULT_H */
+/* This part must be outside protection */
+#include <trace/define_trace.h>
Signature · 7 lines
1.7.10.4


_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#2 lore raw

Re: [RFC-Patch 1/2] Add page fault trace event definitions

In reply to a message not in the archive
Quoted 25 lines · * Francis Deslauriers ([email protected]) wrote:

Add page_fault_entry and page_fault_exit event definitions. It will allow each architecture to instrument their page faults.

---
 include/trace/events/fault.h |   51 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 include/trace/events/fault.h
include/trace/events/fault.h new file +9 -0
new file mode 100644
index 0000000..7256b40
@@ -0,0 +1,51 @@
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM fault
+
+#if !defined(_TRACE_FAULT_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_FAULT_H
+
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(page_fault_entry,

include/trace/events/fault.h line 19

Quoted 10 lines
include/trace/events/fault.h new file +10 -0
+
+	TP_PROTO(struct pt_regs *regs, unsigned long address,
+					int write_access),
+
+	TP_ARGS(regs, address, write_access),
+
+	TP_STRUCT__entry(
+		__field(	unsigned long,	ip	)
+		__field(	unsigned long,	addr	)
+		__field(	int,		write	)

uint8_t, write

will save some space.

include/trace/events/fault.h line 25

Quoted 6 lines
include/trace/events/fault.h new file +6 -0
+	),
+
+	TP_fast_assign(
+		__entry->ip	= regs ? instruction_pointer(regs) : 0UL;
+		__entry->addr	= address;
+		__entry->write	= write_access;

Just to be clean, if we use uint8_t:

__entry->write = !!write_access;

It will map zero/nonzero values to 0 and 1, and thus ensure it can be represented on a uint8_t.

Thanks,

Mathieu

Quoted 34 lines
include/trace/events/fault.h new file +26 -0
+	),
+
+	TP_printk("ip=%lu addr=%lu write_access=%d",
+		__entry->ip, __entry->addr, __entry->write)
+);
+
+TRACE_EVENT(page_fault_exit,
+
+	TP_PROTO(int result),
+
+	TP_ARGS(result),
+
+	TP_STRUCT__entry(
+		__field(	int,	res	)
+	),
+
+	TP_fast_assign(
+		__entry->res	= result;
+	),
+
+	TP_printk("result=%d", __entry->res)
+);
+
+#endif /* _TRACE_FAULT_H */
+/* This part must be outside protection */
+#include <trace/define_trace.h>
Signature · 7 lines
1.7.10.4


_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 21 lines · * Francis Deslauriers ([email protected]) wrote:
---
 arch/x86/mm/fault.c |    5 +++++
 1 file changed, 5 insertions(+)
arch/x86/mm/fault.c +3 -0
index 2b97525..f41a5a0 100644
@@ -20,6 +20,9 @@
 #include <asm/fixmap.h>			/* VSYSCALL_START		*/
 #include <asm/context_tracking.h>	/* exception_enter(), ...	*/
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/fault.h>		/* trace_page_fault_*(), ...	*/
+
 /*
  * Page fault error code bits:
  *

arch/x86/mm/fault.c good_area: · line 1191

Quoted 6 lines
arch/x86/mm/fault.c +2 -0
@@ -1183,7 +1186,9 @@ good_area:
 	 * make sure we exit gracefully rather than endlessly redo
 	 * the fault:
 	 */
+	trace_page_fault_entry(regs, address, write);
 	fault = handle_mm_fault(mm, vma, address, flags);
+	trace_page_fault_exit(fault);

If you look at the lttng 0.x instrumentation, I think there are other tracepoints in get user pages too ?

Thanks,

Mathieu

Quoted 11 lines
arch/x86/mm/fault.c +0 -0
 	if (unlikely(fault & (VM_FAULT_RETRY|VM_FAULT_ERROR))) {
 		if (mm_fault_error(regs, error_code, address, fault))
Signature · 7 lines
1.7.10.4


_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
#5 lore raw

PATCH 2/2 x86:Instruments page fault trace event

In reply to a message not in the archive
---
 arch/x86/mm/fault.c |    5 +++++
 1 file changed, 5 insertions(+)
arch/x86/mm/fault.c +5 -0
index 2b97525..f41a5a0 100644
@@ -20,6 +20,9 @@
 #include <asm/fixmap.h>			/* VSYSCALL_START		*/
 #include <asm/context_tracking.h>	/* exception_enter(), ...	*/
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/fault.h>		/* trace_page_fault_*(), ...	*/
+
 /*
  * Page fault error code bits:
  *
@@ -1183,7 +1186,9 @@ good_area:
 	 * make sure we exit gracefully rather than endlessly redo
 	 * the fault:
 	 */
+	trace_page_fault_entry(regs, address, write);
 	fault = handle_mm_fault(mm, vma, address, flags);
+	trace_page_fault_exit(fault);
 
 	if (unlikely(fault & (VM_FAULT_RETRY|VM_FAULT_ERROR))) {
 		if (mm_fault_error(regs, error_code, address, fault))
Signature · 7 lines
1.7.10.4


_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

PATCH 2/2 x86:Instruments page fault trace event

---
 arch/x86/mm/fault.c |    7 +++++++
 mm/memory.c         |    5 +++++
 2 files changed, 12 insertions(+)
arch/x86/mm/fault.c +7 -0
index 2b97525..6ceaaaa 100644
@@ -20,6 +20,9 @@
 #include <asm/fixmap.h>			/* VSYSCALL_START		*/
 #include <asm/context_tracking.h>	/* exception_enter(), ...	*/
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/fault.h>		/* trace_page_fault_*(), ...	*/
+
 /*
  * Page fault error code bits:
  *
@@ -754,12 +757,14 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
 
 		if (likely(show_unhandled_signals))
 			show_signal_msg(regs, error_code, address, tsk);
+		trace_page_fault_entry(regs, address, error_code & PF_WRITE);
 
 		tsk->thread.cr2		= address;
 		tsk->thread.error_code	= error_code;
 		tsk->thread.trap_nr	= X86_TRAP_PF;
 
 		force_sig_info_fault(SIGSEGV, si_code, address, tsk, 0);
+		trace_page_fault_exit(-1);
 
 		return;
 	}
@@ -1183,7 +1188,9 @@ good_area:
 	 * make sure we exit gracefully rather than endlessly redo
 	 * the fault:
 	 */
+	trace_page_fault_entry(regs, address, write);
 	fault = handle_mm_fault(mm, vma, address, flags);
+	trace_page_fault_exit(fault);
 
 	if (unlikely(fault & (VM_FAULT_RETRY|VM_FAULT_ERROR))) {
 		if (mm_fault_error(regs, error_code, address, fault))
mm/memory.c +5 -0
index 494526a..49a8119 100644
@@ -67,6 +67,8 @@
 #include <asm/tlbflush.h>
 #include <asm/pgtable.h>
 
+#include <trace/events/fault.h>
+
 #include "internal.h"
 
 #ifdef LAST_NID_NOT_IN_PAGE_FLAGS
@@ -1828,8 +1830,11 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
 				if (foll_flags & FOLL_NOWAIT)
 					fault_flags |= (FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_RETRY_NOWAIT);
 
+				trace_page_fault_entry(0, start,
+						foll_flags & FOLL_WRITE);
 				ret = handle_mm_fault(mm, vma, start,
 							fault_flags);
+				trace_page_fault_exit(ret);
 
 				if (ret & VM_FAULT_ERROR) {
 					if (ret & VM_FAULT_OOM)
Signature · 7 lines
1.7.10.4


_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw
Quoted 22 lines · * Francis Deslauriers ([email protected]) wrote:
---
 arch/x86/mm/fault.c |    7 +++++++
 mm/memory.c         |    5 +++++
 2 files changed, 12 insertions(+)
arch/x86/mm/fault.c +3 -0
index 2b97525..6ceaaaa 100644
@@ -20,6 +20,9 @@
 #include <asm/fixmap.h>			/* VSYSCALL_START		*/
 #include <asm/context_tracking.h>	/* exception_enter(), ...	*/
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/fault.h>		/* trace_page_fault_*(), ...	*/
+
 /*
  * Page fault error code bits:
  *

arch/x86/mm/fault.c __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code, · line 766

Quoted 10 lines
arch/x86/mm/fault.c +1 -0
@@ -754,12 +757,14 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
 
 		if (likely(show_unhandled_signals))
 			show_signal_msg(regs, error_code, address, tsk);
+		trace_page_fault_entry(regs, address, error_code & PF_WRITE);
 
 		tsk->thread.cr2		= address;
 		tsk->thread.error_code	= error_code;
 		tsk->thread.trap_nr	= X86_TRAP_PF;
 
 		force_sig_info_fault(SIGSEGV, si_code, address, tsk, 0);

maybe we should put a comment in the patch when sending to LKML, e.g.:

/*
* Using -1 here, since there is no VM_FAULT flag to identify
* user accesses triggering SIGSEGV.
*/

arch/x86/mm/fault.c __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code, · line 767

Quoted 1 line
arch/x86/mm/fault.c +1 -0
+		trace_page_fault_exit(-1);

And maybe interesting hints will come from LKML.

The rest looks good,

Thanks,

Mathieu

Quoted 46 lines
arch/x86/mm/fault.c +2 -0
 		return;
 	}
@@ -1183,7 +1188,9 @@ good_area:
 	 * make sure we exit gracefully rather than endlessly redo
 	 * the fault:
 	 */
+	trace_page_fault_entry(regs, address, write);
 	fault = handle_mm_fault(mm, vma, address, flags);
+	trace_page_fault_exit(fault);
 
 	if (unlikely(fault & (VM_FAULT_RETRY|VM_FAULT_ERROR))) {
 		if (mm_fault_error(regs, error_code, address, fault))
mm/memory.c +5 -0
index 494526a..49a8119 100644
@@ -67,6 +67,8 @@
 #include <asm/tlbflush.h>
 #include <asm/pgtable.h>
 
+#include <trace/events/fault.h>
+
 #include "internal.h"
 
 #ifdef LAST_NID_NOT_IN_PAGE_FLAGS
@@ -1828,8 +1830,11 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
 				if (foll_flags & FOLL_NOWAIT)
 					fault_flags |= (FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_RETRY_NOWAIT);
 
+				trace_page_fault_entry(0, start,
+						foll_flags & FOLL_WRITE);
 				ret = handle_mm_fault(mm, vma, start,
 							fault_flags);
+				trace_page_fault_exit(ret);
 
 				if (ret & VM_FAULT_ERROR) {
 					if (ret & VM_FAULT_OOM)
Signature · 7 lines
1.7.10.4


_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
reviewer Reviewed-by
#10 lore raw

Re: [RFC-Patch 1/2] Add page fault trace event definitions

In reply to a message not in the archive
Quoted 5 lines · * Francis Deslauriers ([email protected]) wrote:

Add page_fault_entry and page_fault_exit event definitions. It will allow each architecture to instrument their page faults.

Quoted 70 lines
---
 include/trace/events/fault.h |   51 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 include/trace/events/fault.h
include/trace/events/fault.h new file +51 -0
new file mode 100644
index 0000000..522ddee
@@ -0,0 +1,51 @@
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM fault
+
+#if !defined(_TRACE_FAULT_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_FAULT_H
+
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(page_fault_entry,
+
+	TP_PROTO(struct pt_regs *regs, unsigned long address,
+					int write_access),
+
+	TP_ARGS(regs, address, write_access),
+
+	TP_STRUCT__entry(
+		__field(	unsigned long,	ip	)
+		__field(	unsigned long,	addr	)
+		__field(	uint8_t,	write	)
+	),
+
+	TP_fast_assign(
+		__entry->ip	= regs ? instruction_pointer(regs) : 0UL;
+		__entry->addr	= address;
+		__entry->write	= !!write_access;
+	),
+
+	TP_printk("ip=%lu addr=%lu write_access=%d",
+		__entry->ip, __entry->addr, __entry->write)
+);
+
+TRACE_EVENT(page_fault_exit,
+
+	TP_PROTO(int result),
+
+	TP_ARGS(result),
+
+	TP_STRUCT__entry(
+		__field(	int,	res	)
+	),
+
+	TP_fast_assign(
+		__entry->res	= result;
+	),
+
+	TP_printk("result=%d", __entry->res)
+);
+
+#endif /* _TRACE_FAULT_H */
+/* This part must be outside protection */
+#include <trace/define_trace.h>
Signature · 7 lines
1.7.10.4


_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com