Date: Sat, 19 Jan 2002 08:01:25 -0800 From: Alfred Perlstein <bright@mu.org> To: smp@freebsd.org Cc: dillon@freebsd.org Subject: help with mutex_pool please? Message-ID: <20020119080125.X13686@elvis.mu.org>
index | next in thread | raw e-mail
I was going to convert some subsystems to use mutex pools...
However if I apply this delta, a couple of seconds after boot I get
a lockup, sometimes the panic message is printed "sleeping with
mutex held"
Any clues?
Index: kern/kern_descrip.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_descrip.c,v
retrieving revision 1.118
diff -u -r1.118 kern_descrip.c
--- kern/kern_descrip.c 15 Jan 2002 00:58:40 -0000 1.118
+++ kern/kern_descrip.c 19 Jan 2002 05:55:09 -0000
@@ -1037,7 +1037,7 @@
FREE(fp, M_FILE);
return (error);
}
- mtx_init(&fp->f_mtx, "file structure", MTX_DEF);
+ fp->f_mtxp = mtx_pool_alloc();
fp->f_gcflag = 0;
fp->f_count = 1;
fp->f_cred = crhold(p->p_ucred);
@@ -1075,7 +1075,6 @@
nfiles--;
sx_xunlock(&filelist_lock);
crfree(fp->f_cred);
- mtx_destroy(&fp->f_mtx);
FREE(fp, M_FILE);
}
Index: kern/kern_resource.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_resource.c,v
retrieving revision 1.94
diff -u -r1.94 kern_resource.c
--- kern/kern_resource.c 4 Nov 2001 18:28:45 -0000 1.94
+++ kern/kern_resource.c 19 Jan 2002 05:55:09 -0000
@@ -859,7 +859,7 @@
free(uip, M_UIDINFO);
uip = old_uip;
} else {
- mtx_init(&uip->ui_mtx, "uidinfo struct", MTX_DEF);
+ uip->ui_mtxp = mtx_pool_alloc();
uip->ui_uid = uid;
LIST_INSERT_HEAD(UIHASH(uid), uip, ui_hash);
}
@@ -877,9 +877,9 @@
struct uidinfo *uip;
{
- mtx_lock(&uip->ui_mtx);
+ UIDINFO_LOCK(uip);
uip->ui_ref++;
- mtx_unlock(&uip->ui_mtx);
+ UIDINFO_UNLOCK(uip);
}
/*-
@@ -903,18 +903,18 @@
{
/* Prepare for optimal case. */
- mtx_lock(&uip->ui_mtx);
+ UIDINFO_LOCK(uip);
if (--uip->ui_ref != 0) {
- mtx_unlock(&uip->ui_mtx);
+ UIDINFO_UNLOCK(uip);
return;
}
/* Prepare for suboptimal case. */
uip->ui_ref++;
- mtx_unlock(&uip->ui_mtx);
+ UIDINFO_UNLOCK(uip);
mtx_lock(&uihashtbl_mtx);
- mtx_lock(&uip->ui_mtx);
+ UIDINFO_LOCK(uip);
/*
* We must subtract one from the count again because we backed out
@@ -932,13 +932,12 @@
if (uip->ui_proccnt != 0)
printf("freeing uidinfo: uid = %d, proccnt = %ld\n",
uip->ui_uid, uip->ui_proccnt);
- mtx_destroy(&uip->ui_mtx);
FREE(uip, M_UIDINFO);
return;
}
mtx_unlock(&uihashtbl_mtx);
- mtx_unlock(&uip->ui_mtx);
+ UIDINFO_UNLOCK(uip);
}
/*
@@ -952,16 +951,16 @@
int max;
{
- mtx_lock(&uip->ui_mtx);
+ UIDINFO_LOCK(uip);
/* don't allow them to exceed max, but allow subtraction */
if (diff > 0 && uip->ui_proccnt + diff > max && max != 0) {
- mtx_unlock(&uip->ui_mtx);
+ UIDINFO_UNLOCK(uip);
return (0);
}
uip->ui_proccnt += diff;
if (uip->ui_proccnt < 0)
printf("negative proccnt for uid = %d\n", uip->ui_uid);
- mtx_unlock(&uip->ui_mtx);
+ UIDINFO_UNLOCK(uip);
return (1);
}
@@ -979,12 +978,12 @@
int s;
s = splnet();
- mtx_lock(&uip->ui_mtx);
+ UIDINFO_LOCK(uip);
new = uip->ui_sbsize + to - *hiwat;
/* don't allow them to exceed max, but allow subtraction */
if (to > *hiwat && new > max) {
splx(s);
- mtx_unlock(&uip->ui_mtx);
+ UIDINFO_UNLOCK(uip);
return (0);
}
uip->ui_sbsize = new;
@@ -992,6 +991,6 @@
if (uip->ui_sbsize < 0)
printf("negative sbsize for uid = %d\n", uip->ui_uid);
splx(s);
- mtx_unlock(&uip->ui_mtx);
+ UIDINFO_UNLOCK(uip);
return (1);
}
Index: sys/file.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/file.h,v
retrieving revision 1.38
diff -u -r1.38 file.h
--- sys/file.h 14 Jan 2002 09:02:33 -0000 1.38
+++ sys/file.h 19 Jan 2002 00:57:03 -0000
@@ -105,7 +105,7 @@
off_t f_offset;
caddr_t f_data; /* vnode or socket */
u_int f_flag; /* see fcntl.h */
- struct mtx f_mtx; /* mutex to protect data */
+ struct mtx *f_mtxp; /* mutex to protect data */
};
#ifdef MALLOC_DECLARE
@@ -128,10 +128,10 @@
int fdrop_locked __P((struct file *fp, struct thread *td));
/* Lock a file. */
-#define FILE_LOCK(f) mtx_lock(&(f)->f_mtx)
-#define FILE_UNLOCK(f) mtx_unlock(&(f)->f_mtx)
-#define FILE_LOCKED(f) mtx_owned(&(f)->f_mtx)
-#define FILE_LOCK_ASSERT(f, type) mtx_assert(&(f)->f_mtx, (type))
+#define FILE_LOCK(f) mtx_lock((f)->f_mtxp)
+#define FILE_UNLOCK(f) mtx_unlock((f)->f_mtxp)
+#define FILE_LOCKED(f) mtx_owned((f)->f_mtxp)
+#define FILE_LOCK_ASSERT(f, type) mtx_assert((f)->f_mtxp, (type))
int fgetvp __P((struct thread *td, int fd, struct vnode **vpp));
int fgetvp_read __P((struct thread *td, int fd, struct vnode **vpp));
Index: sys/resourcevar.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/resourcevar.h,v
retrieving revision 1.24
diff -u -r1.24 resourcevar.h
--- sys/resourcevar.h 12 Sep 2001 08:38:05 -0000 1.24
+++ sys/resourcevar.h 18 Jan 2002 23:41:51 -0000
@@ -96,8 +96,11 @@
long ui_proccnt; /* number of processes */
uid_t ui_uid; /* uid */
u_short ui_ref; /* reference count */
- struct mtx ui_mtx; /* protect all counts/limits */
+ struct mtx *ui_mtxp; /* protect all counts/limits */
};
+
+#define UIDINFO_LOCK(ui) mtx_lock((ui)->ui_mtxp);
+#define UIDINFO_UNLOCK(ui) mtx_unlock((ui)->ui_mtxp);
struct thread;
struct kse;
--
-Alfred Perlstein [alfred@freebsd.org]
'Instead of asking why a piece of software is using "1970s technology,"
start asking why software is ignoring 30 years of accumulated wisdom.'
Tax deductable donations for FreeBSD: http://www.freebsdfoundation.org/
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-smp" in the body of the message
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020119080125.X13686>
