mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-02 22:54:52 +00:00
PP mutexes: lock: Reduce 'umtx_lock' holding before taking the user lock
There is no need to have it for the priority check (that the thread
doesn't have a higher priority than the mutex's ceiling), and there's
also no need to take it if the thread doesn't have privileges to set its
priority to the mutex's ceiling.
While here, turn 'su' into a 'bool' and compute the internal priority
corresponding to the mutex's ceiling once and for all, putting it in new
'new_pri'.
Reviewed by: kib
Approved by: emaste (mentor)
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D44045
(cherry picked from commit 39e4665c96
)
Approved by: emaste (mentor)
This commit is contained in:
parent
f5a145cb0a
commit
ba2c48a7f2
|
@ -2521,7 +2521,8 @@ do_lock_pp(struct thread *td, struct umutex *m, uint32_t flags,
|
|||
struct umtx_pi *pi;
|
||||
uint32_t ceiling;
|
||||
uint32_t owner, id;
|
||||
int error, pri, old_inherited_pri, su, rv;
|
||||
int error, pri, old_inherited_pri, new_pri, rv;
|
||||
bool su;
|
||||
|
||||
id = td->td_tid;
|
||||
uq = td->td_umtxq;
|
||||
|
@ -2550,21 +2551,23 @@ do_lock_pp(struct thread *td, struct umutex *m, uint32_t flags,
|
|||
error = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
new_pri = PRI_MIN_REALTIME + ceiling;
|
||||
|
||||
mtx_lock(&umtx_lock);
|
||||
if (td->td_base_user_pri < PRI_MIN_REALTIME + ceiling) {
|
||||
mtx_unlock(&umtx_lock);
|
||||
if (td->td_base_user_pri < new_pri) {
|
||||
error = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
if (su && PRI_MIN_REALTIME + ceiling < uq->uq_inherited_pri) {
|
||||
uq->uq_inherited_pri = PRI_MIN_REALTIME + ceiling;
|
||||
thread_lock(td);
|
||||
if (uq->uq_inherited_pri < UPRI(td))
|
||||
sched_lend_user_prio(td, uq->uq_inherited_pri);
|
||||
thread_unlock(td);
|
||||
if (su) {
|
||||
mtx_lock(&umtx_lock);
|
||||
if (new_pri < uq->uq_inherited_pri) {
|
||||
uq->uq_inherited_pri = new_pri;
|
||||
thread_lock(td);
|
||||
if (new_pri < UPRI(td))
|
||||
sched_lend_user_prio(td, new_pri);
|
||||
thread_unlock(td);
|
||||
}
|
||||
mtx_unlock(&umtx_lock);
|
||||
}
|
||||
mtx_unlock(&umtx_lock);
|
||||
|
||||
rv = casueword32(&m->m_owner, UMUTEX_CONTESTED, &owner,
|
||||
id | UMUTEX_CONTESTED);
|
||||
|
|
Loading…
Reference in a new issue