From nobody Tue Feb 27 09:00:18 2024 X-Original-To: dev-commits-src-all@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 4TkWfB5sRZz5Cms8; Tue, 27 Feb 2024 09:00:18 +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 4TkWfB4Rgpz4h6s; Tue, 27 Feb 2024 09:00:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1709024418; 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=dx4glNr+vGdAWasQ2hgIfBfazYTHz3uzH1fe7bamD84=; b=fOsxRIEAkpoMeKwg4nTQdT9BVRXzCLCXwmxqaeTXZvHPACZjtJDRJujFpVlX4hMifx4h9T SSWNCn7P6V/KR3WHDGmBpKTycFfubF9hAayyYP+esUkFO9aULbjzxUqpMSGGydGdk1WiOr 9JzUC0C1ybm2fnqL28R63sWduixV28GmWEOGvlwKN2XGxGTGkQh4ZX3D+TZlCAMtDnn1pW qQIB4NSEZ+VaogrvX3U1F57pMt0ZVD8Uc8NBSt29tke24VP8Ia/OPEF+1lVl0wRSTu+kaw NP+HKoU75vJUUZtIxtcJbk4Xq0rRqrdlYisCJ+qdh5iEtGZfV+epXDI7Pmj/HQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1709024418; a=rsa-sha256; cv=none; b=LraokMQVU02JqxgRGHrVexy0mIguA3WlQ97RGeLMcMfqhYNoDGZfnHI20BPlXn4KwvpcEy Fp+iE6YS1RA8LsQQmBIHfMnnZ5/UPc/QMayUAofBN68uP+6nyfJU8hhc2CTPdFhRey53Aa H31zP3UqHPVx9Y4o+rzKOmmbNXZFsga8OkHMQoQk8SBYcyIbluMXwY/iwOtkdcDKAT4c/F ArA2zaBQdhVldCVv4mJSPmtxmpyKrJb6AKH7FlJvuvpmpFIor3b73kMm1TSk+ptRuIwNh3 B5OTgKkXST2Nq4GfMQoxqeRg90bHJUOenMhpLzdHhoKE2sIBGd+oVwLfclx57w== 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=1709024418; 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=dx4glNr+vGdAWasQ2hgIfBfazYTHz3uzH1fe7bamD84=; b=X4b5Ok7B5kmBgl3YFIesThg9RUSG/Ywd0qsx4W/KDjhi8nOaCixcv1K98R6tSBucfrpUq/ H/5PgGRAIrV4PPvTLBLFF6xtGpLn8XN2heQk+ReJ0qX0egk83tjGiU+17p/rXNmxEtj1PS /jO+RNJuZ93Z5yoGoAo6Cw7Twzi/vqMfd6A258NvTWD+PWFSIqBgk1pcqgruSjEIVevzdr WgNRThDVcAHT6F/abhk6hyQ7nJNPCKaRLMeyYilLSsNAobzEMXMHHnGP0o5YAvGxzH42LX 3LXhWQOrp4yHl4IDznkyGFW/XuqMHzFP/eEYNnwRByeF1V8GMkSFFvYRQ1zPCA== 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 4TkWfB3DGSz159Q; Tue, 27 Feb 2024 09:00:18 +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 41R90IaZ004650; Tue, 27 Feb 2024 09:00:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41R90IJV004647; Tue, 27 Feb 2024 09:00:18 GMT (envelope-from git) Date: Tue, 27 Feb 2024 09:00:18 GMT Message-Id: <202402270900.41R90IJV004647@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Certner Subject: git: 39e4665c9694 - main - PP mutexes: lock: Reduce 'umtx_lock' holding before taking the user lock List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 39e4665c9694b9f9b07d1cfa85befc288cabe906 Auto-Submitted: auto-generated The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=39e4665c9694b9f9b07d1cfa85befc288cabe906 commit 39e4665c9694b9f9b07d1cfa85befc288cabe906 Author: Olivier Certner AuthorDate: 2024-02-22 09:13:38 +0000 Commit: Olivier Certner CommitDate: 2024-02-27 08:59:42 +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 --- 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);