Rename the mutex thread and process states to use a more generic 'LOCK'
name instead. (e.g., SLOCK instead of SMTX, TD_ON_LOCK() instead of TD_ON_MUTEX()) Eventually a turnstile abstraction will be added that will be shared with mutexes and other types of locks. SLOCK/TDI_LOCK will be used internally by the turnstile code and will not be specific to mutexes. Making the change now ensures that turnstiles can be dropped in at a later date without affecting the ABI of userland applications.
This commit is contained in:
parent
42117b6c4d
commit
551cf4e150
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=104387
@ -138,9 +138,9 @@ db_ps(dummy1, dummy2, dummy3, dummy4)
|
||||
}
|
||||
switch (td->td_state) {
|
||||
case TDS_INHIBITED:
|
||||
if (TD_ON_MUTEX(td)) {
|
||||
db_printf("[MTX %6s %8p]",
|
||||
td->td_mtxname,
|
||||
if (TD_ON_LOCK(td)) {
|
||||
db_printf("[LOCK %6s %8p]",
|
||||
td->td_lockname,
|
||||
(void *)td->td_blocked);
|
||||
}
|
||||
if (TD_IS_SLEEPING(td)) {
|
||||
|
@ -163,7 +163,7 @@ propagate_priority(struct thread *td)
|
||||
/*
|
||||
* If we aren't blocked on a mutex, we should be.
|
||||
*/
|
||||
KASSERT(TD_ON_MUTEX(td), (
|
||||
KASSERT(TD_ON_LOCK(td), (
|
||||
"process %d(%s):%d holds %s but isn't blocked on a mutex\n",
|
||||
td->td_proc->p_pid, td->td_proc->p_comm, td->td_state,
|
||||
m->mtx_object.lo_name));
|
||||
@ -182,7 +182,7 @@ propagate_priority(struct thread *td)
|
||||
continue;
|
||||
}
|
||||
|
||||
td1 = TAILQ_PREV(td, threadqueue, td_blkq);
|
||||
td1 = TAILQ_PREV(td, threadqueue, td_lockq);
|
||||
if (td1->td_priority <= pri) {
|
||||
continue;
|
||||
}
|
||||
@ -194,15 +194,15 @@ propagate_priority(struct thread *td)
|
||||
* thread in the chain has a lower priority and that
|
||||
* td1 will thus not be NULL after the loop.
|
||||
*/
|
||||
TAILQ_REMOVE(&m->mtx_blocked, td, td_blkq);
|
||||
TAILQ_FOREACH(td1, &m->mtx_blocked, td_blkq) {
|
||||
TAILQ_REMOVE(&m->mtx_blocked, td, td_lockq);
|
||||
TAILQ_FOREACH(td1, &m->mtx_blocked, td_lockq) {
|
||||
MPASS(td1->td_proc->p_magic == P_MAGIC);
|
||||
if (td1->td_priority > pri)
|
||||
break;
|
||||
}
|
||||
|
||||
MPASS(td1 != NULL);
|
||||
TAILQ_INSERT_BEFORE(td1, td, td_blkq);
|
||||
TAILQ_INSERT_BEFORE(td1, td, td_lockq);
|
||||
CTR4(KTR_LOCK,
|
||||
"propagate_priority: p %p moved before %p on [%p] %s",
|
||||
td, td1, m, m->mtx_object.lo_name);
|
||||
@ -591,15 +591,15 @@ _mtx_lock_sleep(struct mtx *m, int opts, const char *file, int line)
|
||||
if (TAILQ_EMPTY(&m->mtx_blocked)) {
|
||||
td1 = mtx_owner(m);
|
||||
LIST_INSERT_HEAD(&td1->td_contested, m, mtx_contested);
|
||||
TAILQ_INSERT_TAIL(&m->mtx_blocked, td, td_blkq);
|
||||
TAILQ_INSERT_TAIL(&m->mtx_blocked, td, td_lockq);
|
||||
} else {
|
||||
TAILQ_FOREACH(td1, &m->mtx_blocked, td_blkq)
|
||||
TAILQ_FOREACH(td1, &m->mtx_blocked, td_lockq)
|
||||
if (td1->td_priority > td->td_priority)
|
||||
break;
|
||||
if (td1)
|
||||
TAILQ_INSERT_BEFORE(td1, td, td_blkq);
|
||||
TAILQ_INSERT_BEFORE(td1, td, td_lockq);
|
||||
else
|
||||
TAILQ_INSERT_TAIL(&m->mtx_blocked, td, td_blkq);
|
||||
TAILQ_INSERT_TAIL(&m->mtx_blocked, td, td_lockq);
|
||||
}
|
||||
#ifdef KTR
|
||||
if (!cont_logged) {
|
||||
@ -616,8 +616,8 @@ _mtx_lock_sleep(struct mtx *m, int opts, const char *file, int line)
|
||||
* Save who we're blocked on.
|
||||
*/
|
||||
td->td_blocked = m;
|
||||
td->td_mtxname = m->mtx_object.lo_name;
|
||||
TD_SET_MUTEX(td);
|
||||
td->td_lockname = m->mtx_object.lo_name;
|
||||
TD_SET_LOCK(td);
|
||||
propagate_priority(td);
|
||||
|
||||
if (LOCK_LOG_TEST(&m->mtx_object, opts))
|
||||
@ -735,7 +735,7 @@ _mtx_unlock_sleep(struct mtx *m, int opts, const char *file, int line)
|
||||
MPASS(td->td_proc->p_magic == P_MAGIC);
|
||||
MPASS(td1->td_proc->p_magic == P_MAGIC);
|
||||
|
||||
TAILQ_REMOVE(&m->mtx_blocked, td1, td_blkq);
|
||||
TAILQ_REMOVE(&m->mtx_blocked, td1, td_lockq);
|
||||
|
||||
if (TAILQ_EMPTY(&m->mtx_blocked)) {
|
||||
LIST_REMOVE(m, mtx_contested);
|
||||
@ -761,7 +761,7 @@ _mtx_unlock_sleep(struct mtx *m, int opts, const char *file, int line)
|
||||
m, td1);
|
||||
|
||||
td1->td_blocked = NULL;
|
||||
TD_CLR_MUTEX(td1);
|
||||
TD_CLR_LOCK(td1);
|
||||
if (!TD_CAN_RUN(td1)) {
|
||||
mtx_unlock_spin(&sched_lock);
|
||||
return;
|
||||
|
@ -927,10 +927,10 @@ fill_kinfo_proc(p, kp)
|
||||
strncpy(kp->ki_wmesg, td->td_wmesg,
|
||||
sizeof(kp->ki_wmesg) - 1);
|
||||
}
|
||||
if (TD_ON_MUTEX(td)) {
|
||||
kp->ki_kiflag |= KI_MTXBLOCK;
|
||||
strncpy(kp->ki_mtxname, td->td_mtxname,
|
||||
sizeof(kp->ki_mtxname) - 1);
|
||||
if (TD_ON_LOCK(td)) {
|
||||
kp->ki_kiflag |= KI_LOCKBLOCK;
|
||||
strncpy(kp->ki_lockname, td->td_lockname,
|
||||
sizeof(kp->ki_lockname) - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -943,8 +943,8 @@ fill_kinfo_proc(p, kp)
|
||||
kp->ki_stat = SSTOP;
|
||||
} else if (TD_IS_SLEEPING(td)) {
|
||||
kp->ki_stat = SSLEEP;
|
||||
} else if (TD_ON_MUTEX(td)) {
|
||||
kp->ki_stat = SMTX;
|
||||
} else if (TD_ON_LOCK(td)) {
|
||||
kp->ki_stat = SLOCK;
|
||||
} else {
|
||||
kp->ki_stat = SWAIT;
|
||||
}
|
||||
|
@ -759,7 +759,7 @@ mi_switch(void)
|
||||
KASSERT((ke->ke_state == KES_THREAD), ("mi_switch: kse state?"));
|
||||
KASSERT(!TD_ON_RUNQ(td), ("mi_switch: called by old code"));
|
||||
#ifdef INVARIANTS
|
||||
if (!TD_ON_MUTEX(td) &&
|
||||
if (!TD_ON_LOCK(td) &&
|
||||
!TD_ON_RUNQ(td) &&
|
||||
!TD_IS_RUNNING(td))
|
||||
mtx_assert(&Giant, MA_NOTOWNED);
|
||||
|
@ -163,7 +163,7 @@ propagate_priority(struct thread *td)
|
||||
/*
|
||||
* If we aren't blocked on a mutex, we should be.
|
||||
*/
|
||||
KASSERT(TD_ON_MUTEX(td), (
|
||||
KASSERT(TD_ON_LOCK(td), (
|
||||
"process %d(%s):%d holds %s but isn't blocked on a mutex\n",
|
||||
td->td_proc->p_pid, td->td_proc->p_comm, td->td_state,
|
||||
m->mtx_object.lo_name));
|
||||
@ -182,7 +182,7 @@ propagate_priority(struct thread *td)
|
||||
continue;
|
||||
}
|
||||
|
||||
td1 = TAILQ_PREV(td, threadqueue, td_blkq);
|
||||
td1 = TAILQ_PREV(td, threadqueue, td_lockq);
|
||||
if (td1->td_priority <= pri) {
|
||||
continue;
|
||||
}
|
||||
@ -194,15 +194,15 @@ propagate_priority(struct thread *td)
|
||||
* thread in the chain has a lower priority and that
|
||||
* td1 will thus not be NULL after the loop.
|
||||
*/
|
||||
TAILQ_REMOVE(&m->mtx_blocked, td, td_blkq);
|
||||
TAILQ_FOREACH(td1, &m->mtx_blocked, td_blkq) {
|
||||
TAILQ_REMOVE(&m->mtx_blocked, td, td_lockq);
|
||||
TAILQ_FOREACH(td1, &m->mtx_blocked, td_lockq) {
|
||||
MPASS(td1->td_proc->p_magic == P_MAGIC);
|
||||
if (td1->td_priority > pri)
|
||||
break;
|
||||
}
|
||||
|
||||
MPASS(td1 != NULL);
|
||||
TAILQ_INSERT_BEFORE(td1, td, td_blkq);
|
||||
TAILQ_INSERT_BEFORE(td1, td, td_lockq);
|
||||
CTR4(KTR_LOCK,
|
||||
"propagate_priority: p %p moved before %p on [%p] %s",
|
||||
td, td1, m, m->mtx_object.lo_name);
|
||||
@ -591,15 +591,15 @@ _mtx_lock_sleep(struct mtx *m, int opts, const char *file, int line)
|
||||
if (TAILQ_EMPTY(&m->mtx_blocked)) {
|
||||
td1 = mtx_owner(m);
|
||||
LIST_INSERT_HEAD(&td1->td_contested, m, mtx_contested);
|
||||
TAILQ_INSERT_TAIL(&m->mtx_blocked, td, td_blkq);
|
||||
TAILQ_INSERT_TAIL(&m->mtx_blocked, td, td_lockq);
|
||||
} else {
|
||||
TAILQ_FOREACH(td1, &m->mtx_blocked, td_blkq)
|
||||
TAILQ_FOREACH(td1, &m->mtx_blocked, td_lockq)
|
||||
if (td1->td_priority > td->td_priority)
|
||||
break;
|
||||
if (td1)
|
||||
TAILQ_INSERT_BEFORE(td1, td, td_blkq);
|
||||
TAILQ_INSERT_BEFORE(td1, td, td_lockq);
|
||||
else
|
||||
TAILQ_INSERT_TAIL(&m->mtx_blocked, td, td_blkq);
|
||||
TAILQ_INSERT_TAIL(&m->mtx_blocked, td, td_lockq);
|
||||
}
|
||||
#ifdef KTR
|
||||
if (!cont_logged) {
|
||||
@ -616,8 +616,8 @@ _mtx_lock_sleep(struct mtx *m, int opts, const char *file, int line)
|
||||
* Save who we're blocked on.
|
||||
*/
|
||||
td->td_blocked = m;
|
||||
td->td_mtxname = m->mtx_object.lo_name;
|
||||
TD_SET_MUTEX(td);
|
||||
td->td_lockname = m->mtx_object.lo_name;
|
||||
TD_SET_LOCK(td);
|
||||
propagate_priority(td);
|
||||
|
||||
if (LOCK_LOG_TEST(&m->mtx_object, opts))
|
||||
@ -735,7 +735,7 @@ _mtx_unlock_sleep(struct mtx *m, int opts, const char *file, int line)
|
||||
MPASS(td->td_proc->p_magic == P_MAGIC);
|
||||
MPASS(td1->td_proc->p_magic == P_MAGIC);
|
||||
|
||||
TAILQ_REMOVE(&m->mtx_blocked, td1, td_blkq);
|
||||
TAILQ_REMOVE(&m->mtx_blocked, td1, td_lockq);
|
||||
|
||||
if (TAILQ_EMPTY(&m->mtx_blocked)) {
|
||||
LIST_REMOVE(m, mtx_contested);
|
||||
@ -761,7 +761,7 @@ _mtx_unlock_sleep(struct mtx *m, int opts, const char *file, int line)
|
||||
m, td1);
|
||||
|
||||
td1->td_blocked = NULL;
|
||||
TD_CLR_MUTEX(td1);
|
||||
TD_CLR_LOCK(td1);
|
||||
if (!TD_CAN_RUN(td1)) {
|
||||
mtx_unlock_spin(&sched_lock);
|
||||
return;
|
||||
|
@ -2399,8 +2399,8 @@ ttyinfo(struct tty *tp)
|
||||
if (TD_ON_RUNQ(td) ||
|
||||
(TD_IS_RUNNING(td))) {
|
||||
stmp = "running";
|
||||
} else if (TD_ON_MUTEX(td)) {
|
||||
stmp = td->td_mtxname;
|
||||
} else if (TD_ON_LOCK(td)) {
|
||||
stmp = td->td_lockname;
|
||||
} else if (td->td_wmesg) {
|
||||
stmp = td->td_wmesg;
|
||||
} else {
|
||||
@ -2425,7 +2425,7 @@ ttyinfo(struct tty *tp)
|
||||
|
||||
ttyprintf(tp, " cmd: %s %d [%s%s] ", pick->p_comm,
|
||||
pick->p_pid,
|
||||
TD_ON_MUTEX(td) ? "*" : "",
|
||||
TD_ON_LOCK(td) ? "*" : "",
|
||||
stmp);
|
||||
|
||||
/* Print user time. */
|
||||
|
@ -259,7 +259,7 @@ struct thread {
|
||||
|
||||
/* The two queues below should someday be merged */
|
||||
TAILQ_ENTRY(thread) td_slpq; /* (j) Sleep queue. XXXKSE */
|
||||
TAILQ_ENTRY(thread) td_blkq; /* (j) Mutex queue. XXXKSE */
|
||||
TAILQ_ENTRY(thread) td_lockq; /* (j) Lock queue. XXXKSE */
|
||||
TAILQ_ENTRY(thread) td_runq; /* (j) Run queue(s). XXXKSE */
|
||||
|
||||
TAILQ_HEAD(, selinfo) td_selq; /* (p) List of selinfos. */
|
||||
@ -279,7 +279,7 @@ struct thread {
|
||||
short td_locks; /* (k) DEBUG: lockmgr count of locks */
|
||||
struct mtx *td_blocked; /* (j) Mutex process is blocked on. */
|
||||
struct ithd *td_ithd; /* (b) For interrupt threads only. */
|
||||
const char *td_mtxname; /* (j) Name of mutex blocked on. */
|
||||
const char *td_lockname; /* (j) Name of lock blocked on. */
|
||||
LIST_HEAD(, mtx) td_contested; /* (j) Contested locks. */
|
||||
struct lock_list_entry *td_sleeplocks; /* (k) Held sleep locks. */
|
||||
int td_intr_nesting_level; /* (k) Interrupt recursion. */
|
||||
@ -335,7 +335,7 @@ struct thread {
|
||||
#define TDI_SUSPENDED 0x01 /* On suspension queue. */
|
||||
#define TDI_SLEEPING 0x02 /* Actually asleep! (tricky). */
|
||||
#define TDI_SWAPPED 0x04 /* Stack not in mem.. bad juju if run. */
|
||||
#define TDI_MUTEX 0x08 /* Stopped on a mutex. */
|
||||
#define TDI_LOCK 0x08 /* Stopped on a lock. */
|
||||
#define TDI_IWAIT 0x10 /* Awaiting interrupt. */
|
||||
#define TDI_LOAN 0x20 /* bound thread's KSE is lent */
|
||||
|
||||
@ -343,7 +343,7 @@ struct thread {
|
||||
#define TD_ON_SLEEPQ(td) ((td)->td_wchan != NULL)
|
||||
#define TD_IS_SUSPENDED(td) ((td)->td_inhibitors & TDI_SUSPENDED)
|
||||
#define TD_IS_SWAPPED(td) ((td)->td_inhibitors & TDI_SWAPPED)
|
||||
#define TD_ON_MUTEX(td) ((td)->td_inhibitors & TDI_MUTEX)
|
||||
#define TD_ON_LOCK(td) ((td)->td_inhibitors & TDI_LOCK)
|
||||
#define TD_AWAITING_INTR(td) ((td)->td_inhibitors & TDI_IWAIT)
|
||||
#define TD_IS_RUNNING(td) ((td)->td_state == TDS_RUNNING)
|
||||
#define TD_ON_RUNQ(td) ((td)->td_state == TDS_RUNQ)
|
||||
@ -363,14 +363,14 @@ struct thread {
|
||||
|
||||
#define TD_SET_SLEEPING(td) TD_SET_INHIB((td), TDI_SLEEPING)
|
||||
#define TD_SET_SWAPPED(td) TD_SET_INHIB((td), TDI_SWAPPED)
|
||||
#define TD_SET_MUTEX(td) TD_SET_INHIB((td), TDI_MUTEX)
|
||||
#define TD_SET_LOCK(td) TD_SET_INHIB((td), TDI_LOCK)
|
||||
#define TD_SET_SUSPENDED(td) TD_SET_INHIB((td), TDI_SUSPENDED)
|
||||
#define TD_SET_IWAIT(td) TD_SET_INHIB((td), TDI_IWAIT)
|
||||
#define TD_SET_LOAN(td) TD_SET_INHIB((td), TDI_LOAN)
|
||||
|
||||
#define TD_CLR_SLEEPING(td) TD_CLR_INHIB((td), TDI_SLEEPING)
|
||||
#define TD_CLR_SWAPPED(td) TD_CLR_INHIB((td), TDI_SWAPPED)
|
||||
#define TD_CLR_MUTEX(td) TD_CLR_INHIB((td), TDI_MUTEX)
|
||||
#define TD_CLR_LOCK(td) TD_CLR_INHIB((td), TDI_LOCK)
|
||||
#define TD_CLR_SUSPENDED(td) TD_CLR_INHIB((td), TDI_SUSPENDED)
|
||||
#define TD_CLR_IWAIT(td) TD_CLR_INHIB((td), TDI_IWAIT)
|
||||
#define TD_CLR_LOAN(td) TD_CLR_INHIB((td), TDI_LOAN)
|
||||
@ -650,7 +650,7 @@ struct proc {
|
||||
#define SSTOP 4 /* Process debugging or suspension. */
|
||||
#define SZOMB 5 /* Awaiting collection by parent. */
|
||||
#define SWAIT 6 /* Waiting for interrupt. */
|
||||
#define SMTX 7 /* Blocked on a mutex. */
|
||||
#define SLOCK 7 /* Blocked on a lock. */
|
||||
|
||||
#define P_MAGIC 0xbeefface
|
||||
|
||||
|
@ -87,7 +87,7 @@
|
||||
#error "Unknown architecture"
|
||||
#endif
|
||||
#define WMESGLEN 8 /* size of returned wchan message */
|
||||
#define MTXNAMELEN 8 /* size of returned mutex name */
|
||||
#define LOCKNAMELEN 8 /* size of returned lock name */
|
||||
#define OCOMMLEN 16 /* size of returned ki_ocomm name */
|
||||
#define COMMLEN 19 /* size of returned ki_comm name */
|
||||
#define KI_NGROUPS 16 /* number of groups in ki_groups */
|
||||
@ -150,7 +150,7 @@ struct kinfo_proc {
|
||||
char ki_ocomm[OCOMMLEN+1]; /* command name */
|
||||
char ki_wmesg[WMESGLEN+1]; /* wchan message */
|
||||
char ki_login[LOGNAMELEN+1]; /* setlogin name */
|
||||
char ki_mtxname[MTXNAMELEN+1]; /* mutex name */
|
||||
char ki_lockname[LOCKNAMELEN+1]; /* lock name */
|
||||
char ki_comm[COMMLEN+1]; /* command name */
|
||||
char ki_sparestrings[85]; /* spare string space */
|
||||
struct rusage ki_rusage; /* process rusage statistics */
|
||||
@ -166,7 +166,7 @@ void fill_kinfo_proc(struct proc *, struct kinfo_proc *);
|
||||
/* ki_sessflag values */
|
||||
#define KI_CTTY 0x00000001 /* controlling tty vnode active */
|
||||
#define KI_SLEADER 0x00000002 /* session leader */
|
||||
#define KI_MTXBLOCK 0x00000004 /* proc blocked on mutex ki_mtxname */
|
||||
#define KI_LOCKBLOCK 0x00000004 /* proc blocked on lock ki_lockname */
|
||||
|
||||
/*
|
||||
* Per process structure containing data that isn't needed in core
|
||||
|
@ -118,7 +118,7 @@ vmtotal(SYSCTL_HANDLER_ARGS)
|
||||
/* Need new statistics XXX */
|
||||
switch (td->td_state) {
|
||||
case TDS_INHIBITED:
|
||||
if (TD_ON_MUTEX(td) ||
|
||||
if (TD_ON_LOCK(td) ||
|
||||
(td->td_inhibitors ==
|
||||
TDI_SWAPPED)) {
|
||||
totalp->t_sw++;
|
||||
|
Loading…
Reference in New Issue
Block a user