Changeset View
Changeset View
Standalone View
Standalone View
head/sys/kern/kern_synch.c
Show First 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | |||||
* re-locked before _sleep() returns. If priority includes the PDROP | * re-locked before _sleep() returns. If priority includes the PDROP | ||||
* flag the lock is not re-locked before returning. | * flag the lock is not re-locked before returning. | ||||
*/ | */ | ||||
int | int | ||||
_sleep(void *ident, struct lock_object *lock, int priority, | _sleep(void *ident, struct lock_object *lock, int priority, | ||||
const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags) | const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags) | ||||
{ | { | ||||
struct thread *td; | struct thread *td; | ||||
struct proc *p; | |||||
struct lock_class *class; | struct lock_class *class; | ||||
uintptr_t lock_state; | uintptr_t lock_state; | ||||
int catch, pri, rval, sleepq_flags; | int catch, pri, rval, sleepq_flags; | ||||
WITNESS_SAVE_DECL(lock_witness); | WITNESS_SAVE_DECL(lock_witness); | ||||
td = curthread; | td = curthread; | ||||
p = td->td_proc; | |||||
#ifdef KTRACE | #ifdef KTRACE | ||||
if (KTRPOINT(td, KTR_CSW)) | if (KTRPOINT(td, KTR_CSW)) | ||||
ktrcsw(1, 0, wmesg); | ktrcsw(1, 0, wmesg); | ||||
#endif | #endif | ||||
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, lock, | WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, lock, | ||||
"Sleeping on \"%s\"", wmesg); | "Sleeping on \"%s\"", wmesg); | ||||
KASSERT(sbt != 0 || mtx_owned(&Giant) || lock != NULL, | KASSERT(sbt != 0 || mtx_owned(&Giant) || lock != NULL, | ||||
("sleeping without a lock")); | ("sleeping without a lock")); | ||||
Show All 22 Lines | if ((uint8_t *)ident >= &pause_wchan[0] && | ||||
sleepq_flags = SLEEPQ_PAUSE; | sleepq_flags = SLEEPQ_PAUSE; | ||||
else | else | ||||
sleepq_flags = SLEEPQ_SLEEP; | sleepq_flags = SLEEPQ_SLEEP; | ||||
if (catch) | if (catch) | ||||
sleepq_flags |= SLEEPQ_INTERRUPTIBLE; | sleepq_flags |= SLEEPQ_INTERRUPTIBLE; | ||||
sleepq_lock(ident); | sleepq_lock(ident); | ||||
CTR5(KTR_PROC, "sleep: thread %ld (pid %ld, %s) on %s (%p)", | CTR5(KTR_PROC, "sleep: thread %ld (pid %ld, %s) on %s (%p)", | ||||
td->td_tid, p->p_pid, td->td_name, wmesg, ident); | td->td_tid, td->td_proc->p_pid, td->td_name, wmesg, ident); | ||||
if (lock == &Giant.lock_object) | if (lock == &Giant.lock_object) | ||||
mtx_assert(&Giant, MA_OWNED); | mtx_assert(&Giant, MA_OWNED); | ||||
DROP_GIANT(); | DROP_GIANT(); | ||||
if (lock != NULL && lock != &Giant.lock_object && | if (lock != NULL && lock != &Giant.lock_object && | ||||
!(class->lc_flags & LC_SLEEPABLE)) { | !(class->lc_flags & LC_SLEEPABLE)) { | ||||
WITNESS_SAVE(lock, lock_witness); | WITNESS_SAVE(lock, lock_witness); | ||||
lock_state = class->lc_unlock(lock); | lock_state = class->lc_unlock(lock); | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | #endif | ||||
return (rval); | return (rval); | ||||
} | } | ||||
int | int | ||||
msleep_spin_sbt(void *ident, struct mtx *mtx, const char *wmesg, | msleep_spin_sbt(void *ident, struct mtx *mtx, const char *wmesg, | ||||
sbintime_t sbt, sbintime_t pr, int flags) | sbintime_t sbt, sbintime_t pr, int flags) | ||||
{ | { | ||||
struct thread *td; | struct thread *td; | ||||
struct proc *p; | |||||
int rval; | int rval; | ||||
WITNESS_SAVE_DECL(mtx); | WITNESS_SAVE_DECL(mtx); | ||||
td = curthread; | td = curthread; | ||||
p = td->td_proc; | |||||
KASSERT(mtx != NULL, ("sleeping without a mutex")); | KASSERT(mtx != NULL, ("sleeping without a mutex")); | ||||
KASSERT(ident != NULL, ("msleep_spin_sbt: NULL ident")); | KASSERT(ident != NULL, ("msleep_spin_sbt: NULL ident")); | ||||
KASSERT(TD_IS_RUNNING(td), ("msleep_spin_sbt: curthread not running")); | KASSERT(TD_IS_RUNNING(td), ("msleep_spin_sbt: curthread not running")); | ||||
if (SCHEDULER_STOPPED_TD(td)) | if (SCHEDULER_STOPPED_TD(td)) | ||||
return (0); | return (0); | ||||
sleepq_lock(ident); | sleepq_lock(ident); | ||||
CTR5(KTR_PROC, "msleep_spin: thread %ld (pid %ld, %s) on %s (%p)", | CTR5(KTR_PROC, "msleep_spin: thread %ld (pid %ld, %s) on %s (%p)", | ||||
td->td_tid, p->p_pid, td->td_name, wmesg, ident); | td->td_tid, td->td_proc->p_pid, td->td_name, wmesg, ident); | ||||
DROP_GIANT(); | DROP_GIANT(); | ||||
mtx_assert(mtx, MA_OWNED | MA_NOTRECURSED); | mtx_assert(mtx, MA_OWNED | MA_NOTRECURSED); | ||||
WITNESS_SAVE(&mtx->lock_object, mtx); | WITNESS_SAVE(&mtx->lock_object, mtx); | ||||
mtx_unlock_spin(mtx); | mtx_unlock_spin(mtx); | ||||
/* | /* | ||||
* We put ourselves on the sleep queue and start our timeout. | * We put ourselves on the sleep queue and start our timeout. | ||||
▲ Show 20 Lines • Show All 315 Lines • Show Last 20 Lines |