mirror of
https://github.com/opnsense/src.git
synced 2026-06-03 13:58:30 -04: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 39e4665c9694b9f9b07d1cfa85befc288cabe906) Approved by: emaste (mentor)
This commit is contained in:
parent
f9e9c02241
commit
ce7dc52f07
1 changed files with 14 additions and 11 deletions
|
|
@ -2520,7 +2520,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;
|
||||
|
|
@ -2549,21 +2550,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