Move TDF_DEADLKTREAT into td_pflags (and rename it accordingly) to avoid

having to acquire sched_lock when manipulating it in lockmgr(), uiomove(),
and uiomove_fromphys().

Reviewed by:	jhb
This commit is contained in:
Tim J. Robbins 2004-06-03 01:47:37 +00:00
parent d97e0534fa
commit fa2a4d0595
12 changed files with 41 additions and 88 deletions

View File

@ -71,10 +71,8 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread, KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread,
("uiomove_fromphys proc")); ("uiomove_fromphys proc"));
if (td != NULL) { if (td != NULL) {
mtx_lock_spin(&sched_lock); save = td->td_pflags & TDP_DEADLKTREAT;
save = td->td_flags & TDF_DEADLKTREAT; td->td_pflags |= TDP_DEADLKTREAT;
td->td_flags |= TDF_DEADLKTREAT;
mtx_unlock_spin(&sched_lock);
} }
while (n > 0 && uio->uio_resid) { while (n > 0 && uio->uio_resid) {
iov = uio->uio_iov; iov = uio->uio_iov;
@ -119,10 +117,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
n -= cnt; n -= cnt;
} }
out: out:
if (td != NULL && save == 0) { if (td != NULL && save == 0)
mtx_lock_spin(&sched_lock); td->td_pflags &= ~TDP_DEADLKTREAT;
td->td_flags &= ~TDF_DEADLKTREAT;
mtx_unlock_spin(&sched_lock);
}
return (error); return (error);
} }

View File

@ -71,10 +71,8 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread, KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread,
("uiomove_fromphys proc")); ("uiomove_fromphys proc"));
if (td != NULL) { if (td != NULL) {
mtx_lock_spin(&sched_lock); save = td->td_pflags & TDP_DEADLKTREAT;
save = td->td_flags & TDF_DEADLKTREAT; td->td_pflags |= TDP_DEADLKTREAT;
td->td_flags |= TDF_DEADLKTREAT;
mtx_unlock_spin(&sched_lock);
} }
while (n > 0 && uio->uio_resid) { while (n > 0 && uio->uio_resid) {
iov = uio->uio_iov; iov = uio->uio_iov;
@ -118,10 +116,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
n -= cnt; n -= cnt;
} }
out: out:
if (td != NULL && save == 0) { if (td != NULL && save == 0)
mtx_lock_spin(&sched_lock); td->td_pflags &= ~TDP_DEADLKTREAT;
td->td_flags &= ~TDF_DEADLKTREAT;
mtx_unlock_spin(&sched_lock);
}
return (error); return (error);
} }

View File

@ -75,10 +75,8 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread, KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread,
("uiomove_fromphys proc")); ("uiomove_fromphys proc"));
if (td != NULL) { if (td != NULL) {
mtx_lock_spin(&sched_lock); save = td->td_pflags & TDP_DEADLKTREAT;
save = td->td_flags & TDF_DEADLKTREAT; td->td_pflags |= TDP_DEADLKTREAT;
td->td_flags |= TDF_DEADLKTREAT;
mtx_unlock_spin(&sched_lock);
} }
while (n > 0 && uio->uio_resid) { while (n > 0 && uio->uio_resid) {
iov = uio->uio_iov; iov = uio->uio_iov;
@ -122,10 +120,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
n -= cnt; n -= cnt;
} }
out: out:
if (td != NULL && save == 0) { if (td != NULL && save == 0)
mtx_lock_spin(&sched_lock); td->td_pflags &= ~TDP_DEADLKTREAT;
td->td_flags &= ~TDF_DEADLKTREAT;
mtx_unlock_spin(&sched_lock);
}
return (error); return (error);
} }

View File

@ -71,10 +71,8 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread, KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread,
("uiomove_fromphys proc")); ("uiomove_fromphys proc"));
if (td != NULL) { if (td != NULL) {
mtx_lock_spin(&sched_lock); save = td->td_pflags & TDP_DEADLKTREAT;
save = td->td_flags & TDF_DEADLKTREAT; td->td_pflags |= TDP_DEADLKTREAT;
td->td_flags |= TDF_DEADLKTREAT;
mtx_unlock_spin(&sched_lock);
} }
while (n > 0 && uio->uio_resid) { while (n > 0 && uio->uio_resid) {
iov = uio->uio_iov; iov = uio->uio_iov;
@ -119,10 +117,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
n -= cnt; n -= cnt;
} }
out: out:
if (td != NULL && save == 0) { if (td != NULL && save == 0)
mtx_lock_spin(&sched_lock); td->td_pflags &= ~TDP_DEADLKTREAT;
td->td_flags &= ~TDF_DEADLKTREAT;
mtx_unlock_spin(&sched_lock);
}
return (error); return (error);
} }

View File

@ -71,10 +71,8 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread, KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread,
("uiomove_fromphys proc")); ("uiomove_fromphys proc"));
if (td != NULL) { if (td != NULL) {
mtx_lock_spin(&sched_lock); save = td->td_pflags & TDP_DEADLKTREAT;
save = td->td_flags & TDF_DEADLKTREAT; td->td_pflags |= TDP_DEADLKTREAT;
td->td_flags |= TDF_DEADLKTREAT;
mtx_unlock_spin(&sched_lock);
} }
while (n > 0 && uio->uio_resid) { while (n > 0 && uio->uio_resid) {
iov = uio->uio_iov; iov = uio->uio_iov;
@ -119,10 +117,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
n -= cnt; n -= cnt;
} }
out: out:
if (td != NULL && save == 0) { if (td != NULL && save == 0)
mtx_lock_spin(&sched_lock); td->td_pflags &= ~TDP_DEADLKTREAT;
td->td_flags &= ~TDF_DEADLKTREAT;
mtx_unlock_spin(&sched_lock);
}
return (error); return (error);
} }

View File

@ -251,16 +251,14 @@ debuglockmgr(lkp, flags, interlkp, td, name, file, line)
* while there is an exclusive lock holder or while an * while there is an exclusive lock holder or while an
* exclusive lock request or upgrade request is in progress. * exclusive lock request or upgrade request is in progress.
* *
* However, if TDF_DEADLKTREAT is set, we override exclusive * However, if TDP_DEADLKTREAT is set, we override exclusive
* lock requests or upgrade requests ( but not the exclusive * lock requests or upgrade requests ( but not the exclusive
* lock itself ). * lock itself ).
*/ */
if (lkp->lk_lockholder != thr) { if (lkp->lk_lockholder != thr) {
lockflags = LK_HAVE_EXCL; lockflags = LK_HAVE_EXCL;
mtx_lock_spin(&sched_lock); if (td != NULL && !(td->td_pflags & TDP_DEADLKTREAT))
if (td != NULL && !(td->td_flags & TDF_DEADLKTREAT))
lockflags |= LK_WANT_EXCL | LK_WANT_UPGRADE; lockflags |= LK_WANT_EXCL | LK_WANT_UPGRADE;
mtx_unlock_spin(&sched_lock);
error = acquire(&lkp, extflags, lockflags); error = acquire(&lkp, extflags, lockflags);
if (error) if (error)
break; break;

View File

@ -140,10 +140,8 @@ uiomove(void *cp, int n, struct uio *uio)
("uiomove proc")); ("uiomove proc"));
if (td) { if (td) {
mtx_lock_spin(&sched_lock); save = td->td_pflags & TDP_DEADLKTREAT;
save = td->td_flags & TDF_DEADLKTREAT; td->td_pflags |= TDP_DEADLKTREAT;
td->td_flags |= TDF_DEADLKTREAT;
mtx_unlock_spin(&sched_lock);
} }
while (n > 0 && uio->uio_resid) { while (n > 0 && uio->uio_resid) {
@ -187,11 +185,8 @@ uiomove(void *cp, int n, struct uio *uio)
n -= cnt; n -= cnt;
} }
out: out:
if (td && save == 0) { if (td && save == 0)
mtx_lock_spin(&sched_lock); td->td_pflags &= ~TDP_DEADLKTREAT;
td->td_flags &= ~TDF_DEADLKTREAT;
mtx_unlock_spin(&sched_lock);
}
return (error); return (error);
} }

View File

@ -71,10 +71,8 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread, KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread,
("uiomove_fromphys proc")); ("uiomove_fromphys proc"));
if (td != NULL) { if (td != NULL) {
mtx_lock_spin(&sched_lock); save = td->td_pflags & TDP_DEADLKTREAT;
save = td->td_flags & TDF_DEADLKTREAT; td->td_pflags |= TDP_DEADLKTREAT;
td->td_flags |= TDF_DEADLKTREAT;
mtx_unlock_spin(&sched_lock);
} }
while (n > 0 && uio->uio_resid) { while (n > 0 && uio->uio_resid) {
iov = uio->uio_iov; iov = uio->uio_iov;
@ -118,10 +116,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
n -= cnt; n -= cnt;
} }
out: out:
if (td != NULL && save == 0) { if (td != NULL && save == 0)
mtx_lock_spin(&sched_lock); td->td_pflags &= ~TDP_DEADLKTREAT;
td->td_flags &= ~TDF_DEADLKTREAT;
mtx_unlock_spin(&sched_lock);
}
return (error); return (error);
} }

View File

@ -71,10 +71,8 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread, KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread,
("uiomove_fromphys proc")); ("uiomove_fromphys proc"));
if (td != NULL) { if (td != NULL) {
mtx_lock_spin(&sched_lock); save = td->td_pflags & TDP_DEADLKTREAT;
save = td->td_flags & TDF_DEADLKTREAT; td->td_pflags |= TDP_DEADLKTREAT;
td->td_flags |= TDF_DEADLKTREAT;
mtx_unlock_spin(&sched_lock);
} }
while (n > 0 && uio->uio_resid) { while (n > 0 && uio->uio_resid) {
iov = uio->uio_iov; iov = uio->uio_iov;
@ -118,10 +116,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
n -= cnt; n -= cnt;
} }
out: out:
if (td != NULL && save == 0) { if (td != NULL && save == 0)
mtx_lock_spin(&sched_lock); td->td_pflags &= ~TDP_DEADLKTREAT;
td->td_flags &= ~TDF_DEADLKTREAT;
mtx_unlock_spin(&sched_lock);
}
return (error); return (error);
} }

View File

@ -77,10 +77,8 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread, KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread,
("uiomove_fromphys proc")); ("uiomove_fromphys proc"));
if (td != NULL) { if (td != NULL) {
mtx_lock_spin(&sched_lock); save = td->td_pflags & TDP_DEADLKTREAT;
save = td->td_flags & TDF_DEADLKTREAT; td->td_pflags |= TDP_DEADLKTREAT;
td->td_flags |= TDF_DEADLKTREAT;
mtx_unlock_spin(&sched_lock);
} }
while (n > 0 && uio->uio_resid) { while (n > 0 && uio->uio_resid) {
iov = uio->uio_iov; iov = uio->uio_iov;
@ -133,10 +131,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
n -= cnt; n -= cnt;
} }
out: out:
if (td != NULL && save == 0) { if (td != NULL && save == 0)
mtx_lock_spin(&sched_lock); td->td_pflags &= ~TDP_DEADLKTREAT;
td->td_flags &= ~TDF_DEADLKTREAT;
mtx_unlock_spin(&sched_lock);
}
return (error); return (error);
} }

View File

@ -355,7 +355,6 @@ struct thread {
#define TDF_NEEDSIGCHK 0x020000 /* Thread may need signal delivery. */ #define TDF_NEEDSIGCHK 0x020000 /* Thread may need signal delivery. */
#define TDF_UMTXWAKEUP 0x080000 /* Libthr thread must not sleep on a umtx. */ #define TDF_UMTXWAKEUP 0x080000 /* Libthr thread must not sleep on a umtx. */
#define TDF_THRWAKEUP 0x100000 /* Libthr thread must not suspend itself. */ #define TDF_THRWAKEUP 0x100000 /* Libthr thread must not suspend itself. */
#define TDF_DEADLKTREAT 0x800000 /* Lock aquisition - deadlock treatment. */
/* "Private" flags kept in td_pflags: */ /* "Private" flags kept in td_pflags: */
#define TDP_OLDMASK 0x0001 /* Need to restore mask after suspend. */ #define TDP_OLDMASK 0x0001 /* Need to restore mask after suspend. */
@ -364,6 +363,7 @@ struct thread {
#define TDP_UPCALLING 0x0008 /* This thread is doing an upcall. */ #define TDP_UPCALLING 0x0008 /* This thread is doing an upcall. */
#define TDP_COWINPROGRESS 0x0010 /* Snapshot copy-on-write in progress. */ #define TDP_COWINPROGRESS 0x0010 /* Snapshot copy-on-write in progress. */
#define TDP_ALTSTACK 0x0020 /* Have alternate signal stack. */ #define TDP_ALTSTACK 0x0020 /* Have alternate signal stack. */
#define TDP_DEADLKTREAT 0x0040 /* Lock aquisition - deadlock treatment. */
#define TDP_SA 0x0080 /* A scheduler activation based thread. */ #define TDP_SA 0x0080 /* A scheduler activation based thread. */
#define TDI_SUSPENDED 0x0001 /* On suspension queue. */ #define TDI_SUSPENDED 0x0001 /* On suspension queue. */

View File

@ -436,8 +436,8 @@ ffs_rawread(struct vnode *vp,
uio->uio_iovcnt == 1 && uio->uio_iovcnt == 1 &&
uio->uio_segflg == UIO_USERSPACE && uio->uio_segflg == UIO_USERSPACE &&
uio->uio_resid == uio->uio_iov->iov_len && uio->uio_resid == uio->uio_iov->iov_len &&
(((uio->uio_td != NULL) ? uio->uio_td : curthread)->td_flags & (((uio->uio_td != NULL) ? uio->uio_td : curthread)->td_pflags &
TDF_DEADLKTREAT) == 0) { TDP_DEADLKTREAT) == 0) {
int secsize; /* Media sector size */ int secsize; /* Media sector size */
off_t filebytes; /* Bytes left of file */ off_t filebytes; /* Bytes left of file */
int blockbytes; /* Bytes left of file in full blocks */ int blockbytes; /* Bytes left of file in full blocks */