From nobody Thu May 09 13:26:59 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 4VZt8h1Qz4z5Jgml; Thu, 09 May 2024 13:27:00 +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 4VZt8g5n3sz3wn2; Thu, 9 May 2024 13:26:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715261219; 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=AHSIjpdVY88MabMZmi/u4W6oC/4RPC324BxZFntEWeI=; b=v5sPJlyLGnS0e2QV9NfEto0W0rTjs3ARJ2ziqdj6/SaASPal/IGlH7VLtBhiPePhOUcLC4 7zoMutUTg5ffCIsE6/X+Np1tFtv1m1P1DHTz6trFlkoazLosY2nhYvgWm9pS6Tleh3ws2p vPPrf5TdNy2AIooTL+hELsc0g4iXe899av6PK1rB3uRMsYg0ZI1I5sjb5VsgRYxE6pEox+ ZrFGd4KBzvJ90wVax0bbb9XiGEi7GXBR16s1zY6H6QEncMTCBZeMO9ldGeaxTTmjBvzP5T jjW4bgnfU7UKsV/+xqsge69W81NW1bsjBFZxeSVMmLtODUBobDKSHiKAgKaKZw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715261219; a=rsa-sha256; cv=none; b=L6AR1H0h8CLCJHH7iinQhZn7nZRlLg1vJ37op3KrB/7QO4Fx3nzfYjgiDs9ttXEO7X/cVh vGktbVl1GTDhPYKWs/Yt1jz1LhI87JfoArYDP6CxRDefWh0FiBi7qlt7GxjpBJskwsbAnZ SBhmEfDYjekPxC3UeG85uk6Xa13n/8nuR9jLV2sz3zH/u/3lowEvL7HpB0zcb4BOLubl84 e9vH/CDCPn4BO6ljQBSZOFJfz1XhaP9x87gaudLvaod8ozWT1j2aVqSqjfX/khEcabAds8 bafC2+KmFbW9wHvhogLUuXq77Br8jUtbnWzIm1gnTN6dNmaLM2oRnZtIKYZssw== 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=1715261219; 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=AHSIjpdVY88MabMZmi/u4W6oC/4RPC324BxZFntEWeI=; b=rLXizF326ptIb2Sdw6lShmR4vnT9RbHIOotf0a8dytpnV3Ua8tksiQZUBEg5+T4tl5dhPB VV0/68Jz6t+RfhDZ6JaRjCMABvJCKUkYWq91i5YsHXTjuBHcDx7ilnmdbnWRGi/rdTSOwh noMhIIED3DjgCriq2SNR4v9sUGbGJkMXqsWAWRBEqYjnIAALXL1MZcE8flOP8aU48rq/hL CxZMkiI/v+6O/RUQaXOvFY4FY8aH0VAUCf8ZGFXCW70Z9x58ANsCfx4t+s++7JstrKWxSb OVW3ercUl6RWMQ5EeAxaKDQhyZTe1K0tsN90+2dt6kqh27H29wm+q/5+Jsro1Q== 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 4VZt8g4Slgz19Lb; Thu, 9 May 2024 13:26:59 +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 449DQxU6049673; Thu, 9 May 2024 13:26:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 449DQxdB049670; Thu, 9 May 2024 13:26:59 GMT (envelope-from git) Date: Thu, 9 May 2024 13:26:59 GMT Message-Id: <202405091326.449DQxdB049670@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: ce7dc52f07d0 - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: ce7dc52f07d05d00054d48faf00fcac4036d56df Auto-Submitted: auto-generated The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=ce7dc52f07d05d00054d48faf00fcac4036d56df commit ce7dc52f07d05d00054d48faf00fcac4036d56df Author: Olivier Certner AuthorDate: 2024-02-22 09:13:38 +0000 Commit: Olivier Certner CommitDate: 2024-05-09 13:26:21 +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 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);