From owner-svn-src-all@FreeBSD.ORG Wed Jun 27 21:13:01 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 194C5106564A; Wed, 27 Jun 2012 21:13:01 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 014B78FC0C; Wed, 27 Jun 2012 21:13:01 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q5RLD0di033037; Wed, 27 Jun 2012 21:13:00 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q5RLD0fO033026; Wed, 27 Jun 2012 21:13:00 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <201206272113.q5RLD0fO033026@svn.freebsd.org> From: John Baldwin Date: Wed, 27 Jun 2012 21:13:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r237664 - in stable/8: sys/kern sys/sys sys/vm usr.bin/kdump usr.bin/ktrace X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Jun 2012 21:13:01 -0000 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< __FBSDID("$FreeBSD$"); +#include "opt_ktrace.h" #include "opt_vm.h" #include @@ -86,6 +87,9 @@ __FBSDID("$FreeBSD$"); #include #include #include +#ifdef KTRACE +#include +#endif #include #include @@ -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 #include #include +#include +#include #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;