Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Jun 2012 21:13:00 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r237664 - in stable/8: sys/kern sys/sys sys/vm usr.bin/kdump usr.bin/ktrace
Message-ID:  <201206272113.q5RLD0fO033026@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Wed Jun 27 21:13:00 2012
New Revision: 237664
URL: http://svn.freebsd.org/changeset/base/237664

Log:
  MFC 233925,236357:
  Add new ktrace records for the start and end of VM faults.  This gives
  a pair of records similar to syscall entry and return that a user can
  use to determine how long page faults take.  The new ktrace records are
  enabled via the 'p' trace type, but are not enabled in the default set of
  trace points.

Modified:
  stable/8/sys/kern/kern_ktrace.c
  stable/8/sys/sys/ktrace.h
  stable/8/sys/vm/vm_fault.c
  stable/8/usr.bin/kdump/kdump.1
  stable/8/usr.bin/kdump/kdump.c
  stable/8/usr.bin/kdump/kdump_subr.h
  stable/8/usr.bin/kdump/mksubr
  stable/8/usr.bin/ktrace/ktrace.1
  stable/8/usr.bin/ktrace/ktrace.h
  stable/8/usr.bin/ktrace/subr.c
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/boot/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)
  stable/8/sys/dev/e1000/   (props changed)
  stable/8/usr.bin/kdump/   (props changed)
  stable/8/usr.bin/ktrace/   (props changed)

Modified: stable/8/sys/kern/kern_ktrace.c
==============================================================================
--- stable/8/sys/kern/kern_ktrace.c	Wed Jun 27 21:12:15 2012	(r237663)
+++ stable/8/sys/kern/kern_ktrace.c	Wed Jun 27 21:13:00 2012	(r237664)
@@ -98,6 +98,8 @@ struct ktr_request {
 		struct	ktr_genio ktr_genio;
 		struct	ktr_psig ktr_psig;
 		struct	ktr_csw ktr_csw;
+		struct	ktr_fault ktr_fault;
+		struct	ktr_faultend ktr_faultend;
 	} ktr_data;
 	STAILQ_ENTRY(ktr_request) ktr_list;
 };
@@ -115,6 +117,8 @@ static int data_lengths[] = {
 	0,					/* KTR_SYSCTL */
 	sizeof(struct ktr_proc_ctor),		/* KTR_PROCCTOR */
 	0,					/* KTR_PROCDTOR */
+	sizeof(struct ktr_fault),		/* KTR_FAULT */
+	sizeof(struct ktr_faultend),		/* KTR_FAULTEND */
 };
 
 static STAILQ_HEAD(, ktr_request) ktr_free;
@@ -767,6 +771,42 @@ ktrstruct(name, namelen, data, datalen)
 	req->ktr_header.ktr_len = buflen;
 	ktr_submitrequest(curthread, req);
 }
+
+void
+ktrfault(vaddr, type)
+	vm_offset_t vaddr;
+	int type;
+{
+	struct thread *td = curthread;
+	struct ktr_request *req;
+	struct ktr_fault *kf;
+
+	req = ktr_getrequest(KTR_FAULT);
+	if (req == NULL)
+		return;
+	kf = &req->ktr_data.ktr_fault;
+	kf->vaddr = vaddr;
+	kf->type = type;
+	ktr_enqueuerequest(td, req);
+	ktrace_exit(td);
+}
+
+void
+ktrfaultend(result)
+	int result;
+{
+	struct thread *td = curthread;
+	struct ktr_request *req;
+	struct ktr_faultend *kf;
+
+	req = ktr_getrequest(KTR_FAULTEND);
+	if (req == NULL)
+		return;
+	kf = &req->ktr_data.ktr_faultend;
+	kf->result = result;
+	ktr_enqueuerequest(td, req);
+	ktrace_exit(td);
+}
 #endif /* KTRACE */
 
 /* Interface and common routines */

Modified: stable/8/sys/sys/ktrace.h
==============================================================================
--- stable/8/sys/sys/ktrace.h	Wed Jun 27 21:12:15 2012	(r237663)
+++ stable/8/sys/sys/ktrace.h	Wed Jun 27 21:13:00 2012	(r237664)
@@ -178,6 +178,23 @@ struct ktr_proc_ctor {
 #define KTR_PROCDTOR	11
 
 /*
+ * KTR_FAULT - page fault record
+ */
+#define KTR_FAULT	13
+struct ktr_fault {
+	vm_offset_t vaddr;
+	int type;
+};
+
+/*
+ * KTR_FAULTEND - end of page fault record
+ */
+#define KTR_FAULTEND	14
+struct ktr_faultend {
+	int result;
+};
+
+/*
  * KTR_DROP - If this bit is set in ktr_type, then at least one event
  * between the previous record and this record was dropped.
  */
@@ -198,6 +215,8 @@ struct ktr_proc_ctor {
 #define KTRFAC_SYSCTL	(1<<KTR_SYSCTL)
 #define KTRFAC_PROCCTOR	(1<<KTR_PROCCTOR)
 #define KTRFAC_PROCDTOR	(1<<KTR_PROCDTOR)
+#define KTRFAC_FAULT	(1<<KTR_FAULT)
+#define KTRFAC_FAULTEND	(1<<KTR_FAULTEND)
 
 /*
  * trace flags (also in p_traceflags)
@@ -210,6 +229,8 @@ struct ktr_proc_ctor {
 void	ktrnamei(char *);
 void	ktrcsw(int, int);
 void	ktrpsig(int, sig_t, sigset_t *, int);
+void	ktrfault(vm_offset_t, int);
+void	ktrfaultend(int);
 void	ktrgenio(int, enum uio_rw, struct uio *, int);
 void	ktrsyscall(int, int narg, register_t args[]);
 void	ktrsysctl(int *name, u_int namelen);

Modified: stable/8/sys/vm/vm_fault.c
==============================================================================
--- stable/8/sys/vm/vm_fault.c	Wed Jun 27 21:12:15 2012	(r237663)
+++ stable/8/sys/vm/vm_fault.c	Wed Jun 27 21:13:00 2012	(r237664)
@@ -74,6 +74,7 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include "opt_ktrace.h"
 #include "opt_vm.h"
 
 #include <sys/param.h>
@@ -86,6 +87,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/sysctl.h>
 #include <sys/vmmeter.h>
 #include <sys/vnode.h>
+#ifdef KTRACE
+#include <sys/ktrace.h>
+#endif
 
 #include <vm/vm.h>
 #include <vm/vm_param.h>
@@ -114,6 +118,9 @@ static int prefault_pageorder[] = {
 
 static int vm_fault_additional_pages(vm_page_t, int, int, vm_page_t *, int *);
 static void vm_fault_prefault(pmap_t, vm_offset_t, vm_map_entry_t);
+#ifdef KTRACE
+static int vm_fault_traced(vm_map_t, vm_offset_t, vm_prot_t, int);
+#endif
 
 #define VM_FAULT_READ_AHEAD 8
 #define VM_FAULT_READ_BEHIND 7
@@ -209,6 +216,24 @@ unlock_and_deallocate(struct faultstate 
 int
 vm_fault(vm_map_t map, vm_offset_t vaddr, vm_prot_t fault_type,
 	 int fault_flags)
+#ifdef KTRACE
+{
+	struct thread *td;
+	int result;
+
+	td = curthread;
+	if (map != kernel_map && KTRPOINT(td, KTR_FAULT))
+		ktrfault(vaddr, fault_type);
+	result = vm_fault_traced(map, vaddr, fault_type, fault_flags);
+	if (map != kernel_map && KTRPOINT(td, KTR_FAULTEND))
+		ktrfaultend(result);
+	return (result);
+}
+
+int
+vm_fault_traced(vm_map_t map, vm_offset_t vaddr, vm_prot_t fault_type,
+    int fault_flags)
+#endif
 {
 	vm_prot_t prot;
 	int is_first_object_locked, result;

Modified: stable/8/usr.bin/kdump/kdump.1
==============================================================================
--- stable/8/usr.bin/kdump/kdump.1	Wed Jun 27 21:12:15 2012	(r237663)
+++ stable/8/usr.bin/kdump/kdump.1	Wed Jun 27 21:13:00 2012	(r237664)
@@ -32,7 +32,7 @@
 .\"	@(#)kdump.1	8.1 (Berkeley) 6/6/93
 .\" $FreeBSD$
 .\"
-.Dd February 23, 2008
+.Dd April 5, 2012
 .Dt KDUMP 1
 .Os
 .Sh NAME
@@ -175,6 +175,8 @@ The possible operations are:
 .It Li USER Ta data from user process Ta the data
 .It Li STRU Ta various syscalls Ta structure
 .It Li SCTL Ta Xr sysctl 3 requests Ta MIB name
+.It Li PFLT Ta enter page fault Ta fault address and type
+.It Li PRET Ta return from page fault Ta fault result
 .El
 .Sh SEE ALSO
 .Xr ktrace 1

Modified: stable/8/usr.bin/kdump/kdump.c
==============================================================================
--- stable/8/usr.bin/kdump/kdump.c	Wed Jun 27 21:12:15 2012	(r237663)
+++ stable/8/usr.bin/kdump/kdump.c	Wed Jun 27 21:13:00 2012	(r237664)
@@ -103,6 +103,8 @@ void ktruser(int, unsigned char *);
 void ktrsockaddr(struct sockaddr *);
 void ktrstat(struct stat *);
 void ktrstruct(char *, size_t);
+void ktrfault(struct ktr_fault *);
+void ktrfaultend(struct ktr_faultend *);
 void usage(void);
 void sockfamilyname(int);
 const char *ioctlname(u_long);
@@ -306,6 +308,12 @@ main(int argc, char *argv[])
 		case KTR_STRUCT:
 			ktrstruct(m, ktrlen);
 			break;
+		case KTR_FAULT:
+			ktrfault((struct ktr_fault *)m);
+			break;
+		case KTR_FAULTEND:
+			ktrfaultend((struct ktr_faultend *)m);
+			break;
 		default:
 			printf("\n");
 			break;
@@ -445,6 +453,12 @@ dumpheader(struct ktr_header *kth)
 		/* FALLTHROUGH */
 	case KTR_PROCDTOR:
 		return;
+	case KTR_FAULT:
+		type = "PFLT";
+		break;
+	case KTR_FAULTEND:
+		type = "PRET";
+		break;
 	default:
 		(void)sprintf(unknown, "UNKNOWN(%d)", kth->ktr_type);
 		type = unknown;
@@ -1513,6 +1527,23 @@ invalid:
 	printf("invalid record\n");
 }
 
+void
+ktrfault(struct ktr_fault *ktr)
+{
+
+	printf("0x%jx ", ktr->vaddr);
+	vmprotname(ktr->type);
+	printf("\n");
+}
+
+void
+ktrfaultend(struct ktr_faultend *ktr)
+{
+
+	vmresultname(ktr->result);
+	printf("\n");
+}
+
 #if defined(__amd64__) || defined(__i386__)
 void
 linux_ktrsyscall(struct ktr_syscall *ktr)

Modified: stable/8/usr.bin/kdump/kdump_subr.h
==============================================================================
--- stable/8/usr.bin/kdump/kdump_subr.h	Wed Jun 27 21:12:15 2012	(r237663)
+++ stable/8/usr.bin/kdump/kdump_subr.h	Wed Jun 27 21:13:00 2012	(r237664)
@@ -46,3 +46,5 @@ void lio_listioname (int);
 void minheritname (int);
 void quotactlname (int);
 void ptraceopname (int);
+void vmprotname (int);
+void vmresultname (int);

Modified: stable/8/usr.bin/kdump/mksubr
==============================================================================
--- stable/8/usr.bin/kdump/mksubr	Wed Jun 27 21:12:15 2012	(r237663)
+++ stable/8/usr.bin/kdump/mksubr	Wed Jun 27 21:13:00 2012	(r237664)
@@ -183,6 +183,8 @@ cat <<_EOF_
 #include <sys/shm.h>
 #include <nfsserver/nfs.h>
 #include <ufs/ufs/quota.h>
+#include <vm/vm.h>
+#include <vm/vm_param.h>
 
 #include "kdump_subr.h"
 
@@ -327,6 +329,26 @@ sockoptlevelname (int level, int decimal
 	}
 }
 
+/*
+ * MANUAL
+ *
+ * Used for page fault type.  Cannot use auto_or_type since the macro
+ * values contain a cast.  Also, VM_PROT_NONE has to be handled specially.
+ */
+void
+vmprotname (int type)
+{
+	int	or = 0;
+
+	if (type == VM_PROT_NONE) {
+		(void)printf("VM_PROT_NONE");
+		return;
+	}
+	if_print_or(type, VM_PROT_READ, or);
+	if_print_or(type, VM_PROT_WRITE, or);
+	if_print_or(type, VM_PROT_EXECUTE, or);
+	if_print_or(type, VM_PROT_OVERRIDE_WRITE, or);
+}
 _EOF_
 
 auto_or_type "modename" "S_[A-Z]+[[:space:]]+[0-6]{7}" "sys/stat.h"
@@ -368,6 +390,7 @@ auto_if_type "sockipprotoname" "IPPROTO_
 auto_switch_type "sockoptname" "SO_[A-Z]+[[:space:]]+0x[0-9]+" "sys/socket.h"
 auto_switch_type "socktypename" "SOCK_[A-Z]+[[:space:]]+[1-9]+[0-9]*" "sys/socket.h"
 auto_switch_type "ptraceopname" "PT_[[:alnum:]_]+[[:space:]]+[0-9]+" "sys/ptrace.h"
+auto_switch_type "vmresultname" "KERN_[A-Z]+[[:space:]]+[0-9]+" "vm/vm_param.h"
 
 cat <<_EOF_
 /*

Modified: stable/8/usr.bin/ktrace/ktrace.1
==============================================================================
--- stable/8/usr.bin/ktrace/ktrace.1	Wed Jun 27 21:12:15 2012	(r237663)
+++ stable/8/usr.bin/ktrace/ktrace.1	Wed Jun 27 21:13:00 2012	(r237664)
@@ -32,7 +32,7 @@
 .\"	@(#)ktrace.1	8.1 (Berkeley) 6/6/93
 .\" $FreeBSD$
 .\"
-.Dd February 23, 2008
+.Dd May 31, 2012
 .Dt KTRACE 1
 .Os
 .Sh NAME
@@ -112,6 +112,8 @@ The following table equates the letters 
 .Bl -tag -width flag -compact
 .It Cm c
 trace system calls
+.It Cm f
+trace page faults
 .It Cm i
 trace
 .Tn I/O

Modified: stable/8/usr.bin/ktrace/ktrace.h
==============================================================================
--- stable/8/usr.bin/ktrace/ktrace.h	Wed Jun 27 21:12:15 2012	(r237663)
+++ stable/8/usr.bin/ktrace/ktrace.h	Wed Jun 27 21:13:00 2012	(r237664)
@@ -40,7 +40,8 @@
 
 #define PROC_ABI_POINTS (KTRFAC_PROCCTOR | KTRFAC_PROCDTOR)
 
-#define ALL_POINTS (DEF_POINTS | KTRFAC_CSW | PROC_ABI_POINTS)
+#define ALL_POINTS (DEF_POINTS | KTRFAC_CSW | PROC_ABI_POINTS | \
+		    KTRFAC_FAULT | KTRFAC_FAULTEND)
 
 #define DEF_TRACEFILE	"ktrace.out"
 

Modified: stable/8/usr.bin/ktrace/subr.c
==============================================================================
--- stable/8/usr.bin/ktrace/subr.c	Wed Jun 27 21:12:15 2012	(r237663)
+++ stable/8/usr.bin/ktrace/subr.c	Wed Jun 27 21:13:00 2012	(r237664)
@@ -65,6 +65,9 @@ getpoints(char *s)
 		case 'c':
 			facs |= KTRFAC_SYSCALL | KTRFAC_SYSRET;
 			break;
+		case 'f':
+			facs |= KTRFAC_FAULT | KTRFAC_FAULTEND;
+			break;
 		case 'n':
 			facs |= KTRFAC_NAMEI;
 			break;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201206272113.q5RLD0fO033026>