summaryrefslogtreecommitdiff
path: root/sys/kern/subr_disk.c
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2007-12-23 01:59:59 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2007-12-23 01:59:59 +0000
commitb138fdba471acf705e1bea127c1da17179e67dd5 (patch)
treef141eb33d15eefe36bb2684c7f216113ae1eb4a6 /sys/kern/subr_disk.c
parent8602dbb5d540b780ded7baca4f0f52226105a1b2 (diff)
protect the disk statistics with a mutex.
ok tedu@ kettenis@
Diffstat (limited to 'sys/kern/subr_disk.c')
-rw-r--r--sys/kern/subr_disk.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c
index 2bf6f11b7e0..a07904647e4 100644
--- a/sys/kern/subr_disk.c
+++ b/sys/kern/subr_disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_disk.c,v 1.67 2007/12/16 20:57:17 otto Exp $ */
+/* $OpenBSD: subr_disk.c,v 1.68 2007/12/23 01:59:58 dlg Exp $ */
/* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */
/*
@@ -712,6 +712,7 @@ int
disk_construct(struct disk *diskp, char *lockname)
{
rw_init(&diskp->dk_lock, lockname);
+ mtx_init(&diskp->dk_mtx, IPL_BIO);
diskp->dk_flags |= DKF_CONSTRUCTED;
@@ -784,9 +785,10 @@ disk_busy(struct disk *diskp)
* XXX We'd like to use something as accurate as microtime(),
* but that doesn't depend on the system TOD clock.
*/
- if (diskp->dk_busy++ == 0) {
+ mtx_enter(&diskp->dk_mtx);
+ if (diskp->dk_busy++ == 0)
microuptime(&diskp->dk_timestamp);
- }
+ mtx_leave(&diskp->dk_mtx);
}
/*
@@ -798,6 +800,8 @@ disk_unbusy(struct disk *diskp, long bcount, int read)
{
struct timeval dv_time, diff_time;
+ mtx_enter(&diskp->dk_mtx);
+
if (diskp->dk_busy-- == 0)
printf("disk_unbusy: %s: dk_busy < 0\n", diskp->dk_name);
@@ -818,6 +822,8 @@ disk_unbusy(struct disk *diskp, long bcount, int read)
} else
diskp->dk_seek++;
+ mtx_leave(&diskp->dk_mtx);
+
add_disk_randomness(bcount ^ diff_time.tv_usec);
}