Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Jun 2012 21:12:16 +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-9@freebsd.org
Subject:   svn commit: r237663 - in stable/9: sys/kern sys/sys sys/vm usr.bin/kdump usr.bin/ktrace
Message-ID:  <201206272112.q5RLCGPK032949@svn.freebsd.org>

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

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/9/sys/kern/kern_ktrace.c
  stable/9/sys/sys/ktrace.h
  stable/9/sys/vm/vm_fault.c
  stable/9/usr.bin/kdump/kdump.1
  stable/9/usr.bin/kdump/kdump.c
  stable/9/usr.bin/kdump/kdump_subr.h
  stable/9/usr.bin/kdump/mksubr
  stable/9/usr.bin/ktrace/ktrace.1
  stable/9/usr.bin/ktrace/ktrace.h
  stable/9/usr.bin/ktrace/subr.c
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/amd64/include/xen/   (props changed)
  stable/9/sys/boot/   (props changed)
  stable/9/sys/boot/i386/efi/   (props changed)
  stable/9/sys/boot/ia64/efi/   (props changed)
  stable/9/sys/boot/ia64/ski/   (props changed)
  stable/9/sys/boot/powerpc/boot1.chrp/   (props changed)
  stable/9/sys/boot/powerpc/ofw/   (props changed)
  stable/9/sys/cddl/contrib/opensolaris/   (props changed)
  stable/9/sys/conf/   (props changed)
  stable/9/sys/contrib/dev/acpica/   (props changed)
  stable/9/sys/contrib/octeon-sdk/   (props changed)
  stable/9/sys/contrib/pf/   (props changed)
  stable/9/sys/contrib/x86emu/   (props changed)
  stable/9/sys/dev/   (props changed)
  stable/9/sys/dev/e1000/   (props changed)
  stable/9/sys/dev/isp/   (props changed)
  stable/9/sys/dev/ixgbe/   (props changed)
  stable/9/sys/fs/   (props changed)
  stable/9/sys/fs/ntfs/   (props changed)
  stable/9/sys/modules/   (props changed)
  stable/9/usr.bin/kdump/   (props changed)
  stable/9/usr.bin/ktrace/   (props changed)

Modified: stable/9/sys/kern/kern_ktrace.c
==============================================================================
--- stable/9/sys/kern/kern_ktrace.c	Wed Jun 27 21:05:21 2012	(r237662)
+++ stable/9/sys/kern/kern_ktrace.c	Wed Jun 27 21:12:15 2012	(r237663)
@@ -100,6 +100,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;
 };
@@ -117,6 +119,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;
@@ -768,6 +772,42 @@ ktrstruct(name, 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/9/sys/sys/ktrace.h
==============================================================================
--- stable/9/sys/sys/ktrace.h	Wed Jun 27 21:05:21 2012	(r237662)
+++ stable/9/sys/sys/ktrace.h	Wed Jun 27 21:12:15 2012	(r237663)
@@ -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/9/sys/vm/vm_fault.c
==============================================================================
--- stable/9/sys/vm/vm_fault.c	Wed Jun 27 21:05:21 2012	(r237662)
+++ stable/9/sys/vm/vm_fault.c	Wed Jun 27 21:12:15 2012	(r237663)
@@ -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>
@@ -212,10 +216,23 @@ int
 vm_fault(vm_map_t map, vm_offset_t vaddr, vm_prot_t fault_type,
     int fault_flags)
 {
+	struct thread *td;
+	int result;
 
-	if ((curthread->td_pflags & TDP_NOFAULTING) != 0)
+	td = curthread;
+	if ((td->td_pflags & TDP_NOFAULTING) != 0)
 		return (KERN_PROTECTION_FAILURE);
-	return (vm_fault_hold(map, vaddr, fault_type, fault_flags, NULL));
+#ifdef KTRACE
+	if (map != kernel_map && KTRPOINT(td, KTR_FAULT))
+		ktrfault(vaddr, fault_type);
+#endif
+	result = vm_fault_hold(map, trunc_page(vaddr), fault_type, fault_flags,
+	    NULL);
+#ifdef KTRACE
+	if (map != kernel_map && KTRPOINT(td, KTR_FAULTEND))
+		ktrfaultend(result);
+#endif
+	return (result);
 }
 
 int

Modified: stable/9/usr.bin/kdump/kdump.1
==============================================================================
--- stable/9/usr.bin/kdump/kdump.1	Wed Jun 27 21:05:21 2012	(r237662)
+++ stable/9/usr.bin/kdump/kdump.1	Wed Jun 27 21:12:15 2012	(r237663)
@@ -28,7 +28,7 @@
 .\"	@(#)kdump.1	8.1 (Berkeley) 6/6/93
 .\" $FreeBSD$
 .\"
-.Dd February 23, 2008
+.Dd April 5, 2012
 .Dt KDUMP 1
 .Os
 .Sh NAME
@@ -171,6 +171,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/9/usr.bin/kdump/kdump.c
==============================================================================
--- stable/9/usr.bin/kdump/kdump.c	Wed Jun 27 21:05:21 2012	(r237662)
+++ stable/9/usr.bin/kdump/kdump.c	Wed Jun 27 21:12:15 2012	(r237663)
@@ -99,6 +99,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);
@@ -302,6 +304,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;
@@ -441,6 +449,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;
@@ -1512,6 +1526,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/9/usr.bin/kdump/kdump_subr.h
==============================================================================
--- stable/9/usr.bin/kdump/kdump_subr.h	Wed Jun 27 21:05:21 2012	(r237662)
+++ stable/9/usr.bin/kdump/kdump_subr.h	Wed Jun 27 21:12:15 2012	(r237663)
@@ -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/9/usr.bin/kdump/mksubr
==============================================================================
--- stable/9/usr.bin/kdump/mksubr	Wed Jun 27 21:05:21 2012	(r237662)
+++ stable/9/usr.bin/kdump/mksubr	Wed Jun 27 21:12:15 2012	(r237663)
@@ -185,6 +185,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"
 
@@ -329,6 +331,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_COPY, or);
+}
 _EOF_
 
 auto_or_type "modename" "S_[A-Z]+[[:space:]]+[0-6]{7}" "sys/stat.h"
@@ -370,6 +392,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/9/usr.bin/ktrace/ktrace.1
==============================================================================
--- stable/9/usr.bin/ktrace/ktrace.1	Wed Jun 27 21:05:21 2012	(r237662)
+++ stable/9/usr.bin/ktrace/ktrace.1	Wed Jun 27 21:12:15 2012	(r237663)
@@ -28,7 +28,7 @@
 .\"	@(#)ktrace.1	8.1 (Berkeley) 6/6/93
 .\" $FreeBSD$
 .\"
-.Dd February 23, 2008
+.Dd May 31, 2012
 .Dt KTRACE 1
 .Os
 .Sh NAME
@@ -108,6 +108,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/9/usr.bin/ktrace/ktrace.h
==============================================================================
--- stable/9/usr.bin/ktrace/ktrace.h	Wed Jun 27 21:05:21 2012	(r237662)
+++ stable/9/usr.bin/ktrace/ktrace.h	Wed Jun 27 21:12:15 2012	(r237663)
@@ -36,7 +36,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/9/usr.bin/ktrace/subr.c
==============================================================================
--- stable/9/usr.bin/ktrace/subr.c	Wed Jun 27 21:05:21 2012	(r237662)
+++ stable/9/usr.bin/ktrace/subr.c	Wed Jun 27 21:12:15 2012	(r237663)
@@ -61,6 +61,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?201206272112.q5RLCGPK032949>