Module Name: src Committed By: pgoyette Date: Mon Dec 26 23:12:34 UTC 2016
Modified Files: src/share/man/man4: ddb.4 options.4 src/sys/conf: files src/sys/kern: init_main.c kern_history.c vfs_bio.c src/sys/sys: buf.h kernhist.h Added Files: src/sys/sys: biohist.h Log Message: Add a BIOHIST option. As mentioned on tech-kern. To generate a diff of this commit: cvs rdiff -u -r1.161 -r1.162 src/share/man/man4/ddb.4 cvs rdiff -u -r1.457 -r1.458 src/share/man/man4/options.4 cvs rdiff -u -r1.1167 -r1.1168 src/sys/conf/files cvs rdiff -u -r1.487 -r1.488 src/sys/kern/init_main.c cvs rdiff -u -r1.6 -r1.7 src/sys/kern/kern_history.c cvs rdiff -u -r1.263 -r1.264 src/sys/kern/vfs_bio.c cvs rdiff -u -r0 -r1.1 src/sys/sys/biohist.h cvs rdiff -u -r1.125 -r1.126 src/sys/sys/buf.h cvs rdiff -u -r1.12 -r1.13 src/sys/sys/kernhist.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/share/man/man4/ddb.4 diff -u src/share/man/man4/ddb.4:1.161 src/share/man/man4/ddb.4:1.162 --- src/share/man/man4/ddb.4:1.161 Wed Apr 13 00:47:01 2016 +++ src/share/man/man4/ddb.4 Mon Dec 26 23:12:33 2016 @@ -1,4 +1,4 @@ -.\" $NetBSD: ddb.4,v 1.161 2016/04/13 00:47:01 ozaki-r Exp $ +.\" $NetBSD: ddb.4,v 1.162 2016/12/26 23:12:33 pgoyette Exp $ .\" .\" Copyright (c) 1997 - 2009 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -749,6 +749,8 @@ This command is available only if a kern or .Cd options USB_DEBUG (or related options) or +.Cd options BIOHIST +or .Cd options UVMHIST . .It Ic show vnode Ns Oo Cm /f Oc Ar address Print the vnode at Index: src/share/man/man4/options.4 diff -u src/share/man/man4/options.4:1.457 src/share/man/man4/options.4:1.458 --- src/share/man/man4/options.4:1.457 Tue Dec 13 11:00:20 2016 +++ src/share/man/man4/options.4 Mon Dec 26 23:12:33 2016 @@ -1,4 +1,4 @@ -.\" $NetBSD: options.4,v 1.457 2016/12/13 11:00:20 wiz Exp $ +.\" $NetBSD: options.4,v 1.458 2016/12/26 23:12:33 pgoyette Exp $ .\" .\" Copyright (c) 1996 .\" Perry E. Metzger. All rights reserved. @@ -711,6 +711,32 @@ The default is 100. This option depends upon the .Em UVMHIST option. +.It Cd options BIOHIST +Like +.Em KERNHIST , +it enables the BIO history logs. +These logs can be displayed by using +.Cm show kernhist +from DDB. +See the kernel source file +.Pa sys/kern/vfs_vio.c +for details. +.It Cd options BIOHIST_PRINT +Like +.Em BIOHIST , +it prints the BIO history logs on the system console as entries are added. +Note that the output is +.Em extremely +voluminous, so this option is really only useful for debugging +the very earliest parts of kernel initialization. +.It Cd options BIOHIST_SIZE +Set the size of the +.Dq biohist +kernel history. +The default is 500. +This option depends upon the +.Em BIOHIST +option. .El .Ss File Systems .Bl -ohang Index: src/sys/conf/files diff -u src/sys/conf/files:1.1167 src/sys/conf/files:1.1168 --- src/sys/conf/files:1.1167 Tue Dec 13 20:20:34 2016 +++ src/sys/conf/files Mon Dec 26 23:12:33 2016 @@ -1,4 +1,4 @@ -# $NetBSD: files,v 1.1167 2016/12/13 20:20:34 christos Exp $ +# $NetBSD: files,v 1.1168 2016/12/26 23:12:33 pgoyette Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 version 20150846 @@ -39,6 +39,7 @@ defflag opt_pipe.h PIPE_SOCKETPAIR PIPE defflag AIO defflag MQUEUE +defflag SEMAPHORE defflag BUFQ_DISKSORT defflag BUFQ_FCFS @@ -201,6 +202,13 @@ defflag opt_usb.h USB_DEBUG: KERNHIST defparam opt_usb.h USBHIST_SIZE # +# Options for BIOHIST +# +defflag opt_biohist.h BIOHIST: KERNHIST +defflag opt_biohist.h BIOHIST_PRINT: KERNHIST_PRINT +defparam opt_biohist.h BIOHIST_SIZE + +# # System monitoring framework # include "dev/sysmon/files.sysmon" @@ -1507,6 +1515,7 @@ include "miscfs/procfs/files.procfs" include "miscfs/umapfs/files.umapfs" include "nfs/files.nfs" include "ufs/files.ufs" +include "fs/nfs/files.newnfs" # # UVM (virtual memory) Index: src/sys/kern/init_main.c diff -u src/sys/kern/init_main.c:1.487 src/sys/kern/init_main.c:1.488 --- src/sys/kern/init_main.c:1.487 Wed Nov 16 12:31:33 2016 +++ src/sys/kern/init_main.c Mon Dec 26 23:12:33 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: init_main.c,v 1.487 2016/11/16 12:31:33 pgoyette Exp $ */ +/* $NetBSD: init_main.c,v 1.488 2016/12/26 23:12:33 pgoyette Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -97,7 +97,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.487 2016/11/16 12:31:33 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.488 2016/12/26 23:12:33 pgoyette Exp $"); #include "opt_ddb.h" #include "opt_inet.h" @@ -349,6 +349,7 @@ main(void) /* Initialize the buffer cache */ bufinit(); + biohist_init(); #if defined(SPLASHSCREEN) && defined(SPLASHSCREEN_IMAGE) Index: src/sys/kern/kern_history.c diff -u src/sys/kern/kern_history.c:1.6 src/sys/kern/kern_history.c:1.7 --- src/sys/kern/kern_history.c:1.6 Thu Jun 23 07:32:12 2016 +++ src/sys/kern/kern_history.c Mon Dec 26 23:12:33 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_history.c,v 1.6 2016/06/23 07:32:12 skrll Exp $ */ +/* $NetBSD: kern_history.c,v 1.7 2016/12/26 23:12:33 pgoyette Exp $ */ /* * Copyright (c) 1997 Charles D. Cranor and Washington University. @@ -33,13 +33,14 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_history.c,v 1.6 2016/06/23 07:32:12 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_history.c,v 1.7 2016/12/26 23:12:33 pgoyette Exp $"); #include "opt_ddb.h" #include "opt_kernhist.h" #include "opt_syscall_debug.h" #include "opt_usb.h" #include "opt_uvmhist.h" +#include "opt_biohist.h" #include <sys/param.h> #include <sys/systm.h> @@ -54,6 +55,10 @@ __KERNEL_RCSID(0, "$NetBSD: kern_history #include <dev/usb/usbhist.h> #endif +#ifdef BIOHIST +#include <kern/biohist.h> +#endif + #ifdef SYSCALL_DEBUG KERNHIST_DECL(scdebughist); #endif @@ -200,6 +205,11 @@ kernhist_dumpmask(u_int32_t bitmask) /* hists[i++] = &scdebughist; #endif +#ifdef BIOHIST + if ((bitmask & KERNHIST_BIOHIST) || bitmask == 0) + hists[i++] = &biohist; +#endif + hists[i] = NULL; kernhist_dump_histories(hists, printf); @@ -234,6 +244,9 @@ kernhist_print(void *addr, void (*pr)(co #ifdef SYSCALL_DEBUG hists[i++] = &scdebughist; #endif +#ifdef BIOHIST + hists[i++] = &biohist; +#endif hists[i] = NULL; kernhist_dump_histories(hists, pr); Index: src/sys/kern/vfs_bio.c diff -u src/sys/kern/vfs_bio.c:1.263 src/sys/kern/vfs_bio.c:1.264 --- src/sys/kern/vfs_bio.c:1.263 Sun Dec 18 05:43:20 2016 +++ src/sys/kern/vfs_bio.c Mon Dec 26 23:12:33 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_bio.c,v 1.263 2016/12/18 05:43:20 dholland Exp $ */ +/* $NetBSD: vfs_bio.c,v 1.264 2016/12/26 23:12:33 pgoyette Exp $ */ /*- * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -123,11 +123,12 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.263 2016/12/18 05:43:20 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.264 2016/12/26 23:12:33 pgoyette Exp $"); #ifdef _KERNEL_OPT #include "opt_bufcache.h" #include "opt_dtrace.h" +#include "opt_biohist.h" #endif #include <sys/param.h> @@ -196,6 +197,21 @@ static void brele(buf_t *); static void sysctl_kern_buf_setup(void); static void sysctl_vm_buf_setup(void); +/* Initialization for biohist */ + +#ifdef BIOHIST +#include <sys/biohist.h> +#endif /* BIOHIST */ + +KERNHIST_DEFINE(biohist); + +void +biohist_init(void) +{ + + KERNHIST_INIT(biohist, BIOHIST_SIZE); +} + /* * Definitions for the buffer hash lists. */ @@ -726,6 +742,8 @@ bread(struct vnode *vp, daddr_t blkno, i buf_t *bp; int error; + KERNHIST_FUNC(__func__); KERNHIST_CALLED(biohist); + /* Get buffer for block. */ bp = *bpp = bio_doread(vp, blkno, size, 0); if (bp == NULL) @@ -754,6 +772,8 @@ breadn(struct vnode *vp, daddr_t blkno, buf_t *bp; int error, i; + KERNHIST_FUNC(__func__); KERNHIST_CALLED(biohist); + bp = *bpp = bio_doread(vp, blkno, size, 0); if (bp == NULL) return ENOMEM; @@ -796,6 +816,9 @@ bwrite(buf_t *bp) struct vnode *vp; struct mount *mp; + KERNHIST_FUNC(__func__); KERNHIST_CALLARGS(biohist, "bp=%p", + bp, 0, 0, 0); + KASSERT(ISSET(bp->b_cflags, BC_BUSY)); KASSERT(!cv_has_waiters(&bp->b_done)); @@ -918,6 +941,9 @@ void bdwrite(buf_t *bp) { + KERNHIST_FUNC(__func__); KERNHIST_CALLARGS(biohist, "bp=%p", + bp, 0, 0, 0); + KASSERT(bp->b_vp == NULL || bp->b_vp->v_tag != VT_UFS || bp->b_vp->v_type == VBLK || ISSET(bp->b_flags, B_COWDONE)); KASSERT(ISSET(bp->b_cflags, BC_BUSY)); @@ -1497,18 +1523,28 @@ int biowait(buf_t *bp) { + KERNHIST_FUNC(__func__); + KASSERT(ISSET(bp->b_cflags, BC_BUSY)); KASSERT(bp->b_refcnt > 0); SDT_PROBE1(io, kernel, , wait__start, bp); mutex_enter(bp->b_objlock); - while (!ISSET(bp->b_oflags, BO_DONE | BO_DELWRI)) + + KERNHIST_CALLARGS(biohist, "bp=%p, oflags=0x%x", + bp, bp->b_oflags, 0, 0); + + while (!ISSET(bp->b_oflags, BO_DONE | BO_DELWRI)) { + KERNHIST_LOG(biohist, "waiting bp=%p", bp, 0, 0, 0); cv_wait(&bp->b_done, bp->b_objlock); + } mutex_exit(bp->b_objlock); SDT_PROBE1(io, kernel, , wait__done, bp); + KERNHIST_LOG(biohist, " return %d", bp->b_error, 0, 0, 0); + return bp->b_error; } @@ -1533,12 +1569,17 @@ biodone(buf_t *bp) { int s; + KERNHIST_FUNC(__func__); + KASSERT(!ISSET(bp->b_oflags, BO_DONE)); if (cpu_intr_p()) { /* From interrupt mode: defer to a soft interrupt. */ s = splvm(); TAILQ_INSERT_TAIL(&curcpu()->ci_data.cpu_biodone, bp, b_actq); + + KERNHIST_CALLARGS(biohist, "bp=%p, softint scheduled", + bp, 0, 0, 0); softint_schedule(biodone_sih); splx(s); } else { @@ -1556,6 +1597,9 @@ biodone2(buf_t *bp) SDT_PROBE1(io, kernel, ,done, bp); + KERNHIST_FUNC(__func__); + KERNHIST_CALLARGS(biohist, "bp=%p", bp, 0, 0, 0); + mutex_enter(bp->b_objlock); /* Note that the transfer is done. */ if (ISSET(bp->b_oflags, BO_DONE)) @@ -1569,6 +1613,8 @@ biodone2(buf_t *bp) vwakeup(bp); if ((callout = bp->b_iodone) != NULL) { + KERNHIST_LOG(biohist, "callout %p", callout, 0, 0, 0); + /* Note callout done, then call out. */ KASSERT(!cv_has_waiters(&bp->b_done)); KERNEL_LOCK(1, NULL); /* XXXSMP */ @@ -1578,11 +1624,13 @@ biodone2(buf_t *bp) KERNEL_UNLOCK_ONE(NULL); /* XXXSMP */ } else if (ISSET(bp->b_flags, B_ASYNC)) { /* If async, release. */ + KERNHIST_LOG(biohist, "async", 0, 0, 0, 0); KASSERT(!cv_has_waiters(&bp->b_done)); mutex_exit(bp->b_objlock); brelse(bp, 0); } else { /* Otherwise just wake up waiters in biowait(). */ + KERNHIST_LOG(biohist, "wake-up", 0, 0, 0, 0); cv_broadcast(&bp->b_done); mutex_exit(bp->b_objlock); } @@ -1595,6 +1643,8 @@ biointr(void *cookie) buf_t *bp; int s; + KERNHIST_FUNC(__func__); KERNHIST_CALLED(biohist); + ci = curcpu(); while (!TAILQ_EMPTY(&ci->ci_data.cpu_biodone)) { @@ -1605,6 +1655,7 @@ biointr(void *cookie) TAILQ_REMOVE(&ci->ci_data.cpu_biodone, bp, b_actq); splx(s); + KERNHIST_LOG(biohist, "bp=%p", bp, 0, 0, 0); biodone2(bp); } } @@ -1619,6 +1670,8 @@ buf_syncwait(void) buf_t *bp; int iter, nbusy, nbusy_prev = 0, ihash; + KERNHIST_FUNC(__func__); KERNHIST_CALLED(biohist); + for (iter = 0; iter < 20;) { mutex_enter(&bufcache_lock); nbusy = 0; Index: src/sys/sys/buf.h diff -u src/sys/sys/buf.h:1.125 src/sys/sys/buf.h:1.126 --- src/sys/sys/buf.h:1.125 Mon Jan 11 08:40:52 2016 +++ src/sys/sys/buf.h Mon Dec 26 23:12:33 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: buf.h,v 1.125 2016/01/11 08:40:52 martin Exp $ */ +/* $NetBSD: buf.h,v 1.126 2016/12/26 23:12:33 pgoyette Exp $ */ /*- * Copyright (c) 1999, 2000, 2007, 2008 The NetBSD Foundation, Inc. @@ -326,6 +326,7 @@ void buf_init(buf_t *); void buf_destroy(buf_t *); int bbusy(buf_t *, bool, int, kmutex_t *); +void biohist_init(void); __END_DECLS #endif /* _KERNEL */ Index: src/sys/sys/kernhist.h diff -u src/sys/sys/kernhist.h:1.12 src/sys/sys/kernhist.h:1.13 --- src/sys/sys/kernhist.h:1.12 Sat Apr 9 17:04:53 2016 +++ src/sys/sys/kernhist.h Mon Dec 26 23:12:33 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: kernhist.h,v 1.12 2016/04/09 17:04:53 riastradh Exp $ */ +/* $NetBSD: kernhist.h,v 1.13 2016/12/26 23:12:33 pgoyette Exp $ */ /* * Copyright (c) 1997 Charles D. Cranor and Washington University. @@ -87,6 +87,7 @@ LIST_HEAD(kern_history_head, kern_histor #define KERNHIST_UVMLOANHIST 0x00000008 /* loanhist */ #define KERNHIST_USBHIST 0x00000010 /* usbhist */ #define KERNHIST_SCDEBUGHIST 0x00000020 /* scdebughist */ +#define KERNHIST_BIOHIST 0x00000040 /* biohist */ #ifdef _KERNEL Added files: Index: src/sys/sys/biohist.h diff -u /dev/null src/sys/sys/biohist.h:1.1 --- /dev/null Mon Dec 26 23:12:34 2016 +++ src/sys/sys/biohist.h Mon Dec 26 23:12:33 2016 @@ -0,0 +1,58 @@ +/* $NetBSD: biohist.h,v 1.1 2016/12/26 23:12:33 pgoyette Exp $ */ + +/*- + * Copyright (c) 2016 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Paul Goyette + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _KERN_BIOHIST_H_ +#define _KERN_BIOHIST_H_ + +#ifdef _KERNEL_OPT +#include "opt_biohist.h" +#endif + +/* + * Make BIOHIST_PRINT force on KERNHIST_PRINT for at least BIOHIST_* usage. + */ +#if defined(BIOHIST_PRINT) && !defined(KERNHIST_PRINT) +#define KERNHIST_PRINT 1 +#endif + +#include <sys/kernhist.h> + +#ifdef BIOHIST + +#ifndef BIOHIST_SIZE +#define BIOHIST_SIZE 500 +#endif /* BIOHIST_SIZE */ + +KERNHIST_DECL(biohist); + +#endif /* BIOHIST */ + +#endif /* _KERN_BIOHIST_H_ */