From nobody Tue May 14 13:39:25 2024 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VdyBk2RkHz5K7Dm; Tue, 14 May 2024 13:39:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VdyBk0LdCz4Pm7; Tue, 14 May 2024 13:39:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715693966; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cjJZWiiH6ONfubtGZHHFmICOTWKGrGgtZt4inC/sScs=; b=tKKxCyzPCVzMkYEJWy0FiAVRJV3AZS6hcaF3BxaAQWQDmQk/Tn5mz9eAbQPaPtDPuuWg3U hKjqPT0cCxCBUhXzwfoLofwUEYWb7/lzI/Yd7tpAyXalJ0dbGrVwNGpMUhqQnekaZ70/3W kk4b2lyxhOOgKjnV9revkKo/5oEAKqUBAZtLSqPY2qR+BHI5+LcVOStEMccW45ZzHe+4ct GGaP4t4bpY35hboVb8mkx3y3VNTUcZyw23bN0CUBYTs4Wjayte8Xx+sL8MBZlRaQQUPNF0 QtbK6n13ouA0nh0tTcpHYn823BSgO3fR2qws0Qr5qMDDF8Wfy+kwY7VsOZiWyw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715693966; a=rsa-sha256; cv=none; b=wLEfMjFHTGjFDbMc7qCq05enBiBEptYZfyvRcdlDlSU06WoEErZdfXZHUBW2oVEDCLOwPa nedFyrK/SvgQ9WBbfYAdK1eKrAOxOSAzgUuX99lmuqhXSiMoIc3wgMz9GXh0pW3XzwGmJn y8xyMEWRSUiivH3cfn73RNq/YnIFEBsMPj11zQfKVvJyYiPS/rmRgpVXbezKtFC2WBv7ih bDHXNHoKE4RfRO2uTDJ4JZfT1SRVibWcXyJDJKI1ozDyE9wRKIuXd4m2gh4HmLpWIGjJpM QF+sdyF04n763IYgXvfcosfQm840QXFgt4qZP9suFvII78fzFkSjzVYyIrA9wQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715693966; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cjJZWiiH6ONfubtGZHHFmICOTWKGrGgtZt4inC/sScs=; b=sBmQ07hjSalrf+AVZQE/ILSfz5PL0yl332H3LsyV14NX3OU7NmasUiMNjgmhGso+Hujn6B qozWn/kIQ2nOOc6A1jKtIVoDqD0TDGJkeLKt6cqRpgJEREyGofebpypxoLTgebVYT/XXgr P9DhE2LfbR6JnMBc4n34V7nU4Ja9X2P672hPKYlvdhlRk9UZ/BzOtdtpNBOlscgjsFeUKS 3S/vIVJ0q2uP4jZ6wCDQ+5DEARyYt1R2aajeuBojgPlbEYhUrYejTLcYrye+FZWzNHyEl7 Ll0Y87/bk5mzYKND2pE47j/tKonRq7Amn50j6opk9eJde2vF+KXnOYzpFdM3jA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VdyBj6kRlzZ6g; Tue, 14 May 2024 13:39:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44EDdPNb080509; Tue, 14 May 2024 13:39:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44EDdPH6080506; Tue, 14 May 2024 13:39:25 GMT (envelope-from git) Date: Tue, 14 May 2024 13:39:25 GMT Message-Id: <202405141339.44EDdPH6080506@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: 9dad96bc6344 - releng/14.1 - PP mutexes: lock: Reduce 'umtx_lock' holding before taking the user lock List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/releng/14.1 X-Git-Reftype: branch X-Git-Commit: 9dad96bc634429711f3a1f74a8f988d963e99d96 Auto-Submitted: auto-generated The branch releng/14.1 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=9dad96bc634429711f3a1f74a8f988d963e99d96 commit 9dad96bc634429711f3a1f74a8f988d963e99d96 Author: Olivier Certner AuthorDate: 2024-02-22 09:13:38 +0000 Commit: Olivier Certner CommitDate: 2024-05-14 13:37:35 +0000 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) (cherry picked from commit ce7dc52f07d05d00054d48faf00fcac4036d56df) Approved by: emaste (mentor) Approved by: re (cperciva) --- sys/kern/kern_umtx.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c index 5abc1e71d763..092fcade9d19 100644 --- a/sys/kern/kern_umtx.c +++ b/sys/kern/kern_umtx.c @@ -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);