From nobody Thu May 09 13:30:20 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 4VZtDY2vsSz5JgnV; Thu, 09 May 2024 13:30:21 +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 4VZtDX5hl3z3yDn; Thu, 9 May 2024 13:30:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715261420; 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=LffP3NkO/L5P5Wrwq8HfyOL7Mc+vhU6N8mQkht6kgrY=; b=rx7RgyHvWmrY82Yo2G/5DFTU5rvVttkzOTmgCpibSyvaQV0bxLDBgw9zTTLcj2BTZJC11w 9f60zxORyaeHFraPEpUbRXjiovxKxIh8Mx0sEOViuYW2IalP1/D7I10WJ/SwU3eoOWXQlA AcinOawfvAgGzccDP1QSLFCbWM70+XZIUC+vuV8VXNmB48iK6lPnW+5scGzdMNKbIDnMKR JgxnXWPr8Mz7iTdhiGvAM71RPVNXUAgGrMjugSmPzv8zrvecycXo/RqgKAiCRpRKWduwwb ymWpOcFrCa0OWOvvSszZLc2DxIbtgoh+r845PQLAElqDk2HlzMQ0Vv/ru830aA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715261420; a=rsa-sha256; cv=none; b=PkVU7Y6gqqpkWFpyGWKf2WtEnkrP+ECUtJdXur7sHZ/MTcIxpChDw/549RGzeoGBcU2Hsc WQqMt9QsTcP3YGSZrOo7SCdZ1LowqB0dKfp+LbdxVUuU5Lu2Ek21ApK0UtvMQ0++gE2/I8 zalluUUny9s+DbK4xXmFxjjiUC8TDHOmZ3Glju/jYfXEbCkDQr+t86bPj+7IYot2wS84fW l4jgPNpQkrfr+NmN8l+37oZfiOahjHHvkV3EscHBCJZSIeZ7XXjIIMNEYsDQbw/WaDe/n3 fXEjJmD3I9OdRhD6nIi/sTGGoMoJz64IcFQw1YC2oB/zYm4eorkrFYJ7myYv8Q== 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=1715261420; 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=LffP3NkO/L5P5Wrwq8HfyOL7Mc+vhU6N8mQkht6kgrY=; b=TV6hU/4LBrEZgF6Hz/5H5/jxsyAzigAiwastLU7MIDdv+NJ72MvKWfOfNbHcBxJ4UWDOs/ KnvdXfDAFc65FGUjT2XzCtyx4Y2BJWfYJ0NqtuDLSbBgNOTae4j272orc3+uOQuvQc68sG BcPBJ7KgqqLgFTGsfsX7URN7i9lyfpYD0BeUmTp6sGaV3rRwCQqUDI3ZWYhECJY6IPEGvu HeFLWbtE7hUbmAb0WxTetT3XKjIiFcWicLwbb8DgAWjm4XoGznKVbW182RuV2+CbnqZ7pl EoSDcMHASKi/gMDrSUgUvFrDErKy7c57obuvrl1K7/ucAU5a4oW9zZowxJ85Iw== 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 4VZtDX5JLPz19Sr; Thu, 9 May 2024 13:30:20 +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 449DUKRC058960; Thu, 9 May 2024 13:30:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 449DUKnW058957; Thu, 9 May 2024 13:30:20 GMT (envelope-from git) Date: Thu, 9 May 2024 13:30:20 GMT Message-Id: <202405091330.449DUKnW058957@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: ba2c48a7f21e - stable/13 - 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-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/stable/13 X-Git-Reftype: branch X-Git-Commit: ba2c48a7f21e426ec84856b70db6f9b4c47f8abb Auto-Submitted: auto-generated The branch stable/13 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=ba2c48a7f21e426ec84856b70db6f9b4c47f8abb commit ba2c48a7f21e426ec84856b70db6f9b4c47f8abb Author: Olivier Certner AuthorDate: 2024-02-22 09:13:38 +0000 Commit: Olivier Certner CommitDate: 2024-05-09 13:29:25 +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) --- 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 05a47f405d30..d8587c51e6fd 100644 --- a/sys/kern/kern_umtx.c +++ b/sys/kern/kern_umtx.c @@ -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);