From nobody Thu Jan 16 18:07:59 2025 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 4YYrSb4ZWNz5kkWw; Thu, 16 Jan 2025 18:07:59 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YYrSb3cFqz3RGM; Thu, 16 Jan 2025 18:07:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737050879; 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=UNAjDgARKpDhEiqlbfGoIaW3EplE1kOe1pYXDA1UI04=; b=dO7CMhY8YRQKlJKiN6k4teCIGMPCl530qYFuQ0WSkDK9sFR1XItDTZcscXrdwb7f1g/Nsq J52OETUdqpqcvulpUolM8u7aJkSgSQbMWweIyXxf81AHlvJZy3GgqOTMsGsQmKrAFbeQy0 4cxChmS85p7ikyPpKRyTWQ/uUKZTUI8Askd7+6VyAneaavqCQhVkGybPr5AUSk+QPKku4Q a7y2nDMfz5x0V4l87qzn6VKGOXWx4fnU+hnJzKNauAUV7YGzKUE18X+yIrUMM+fU8Ngjkk NgVp5fTYEH+JDam+kxGHFnQRdUMVn9aY82U8lMY8e1+Yce8aNV69tjtNC84aew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737050879; 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=UNAjDgARKpDhEiqlbfGoIaW3EplE1kOe1pYXDA1UI04=; b=ynb/NDhADN+Xo68KPtcC4HUy/IL/aaiWWMY4ERbzTHO5a4/i073IAxIwEOWpzObG7Wz/Sa Ie2RzAXMuv1vb1s8CC+eeLhkEG4LRY1VMR0Ihp42EEFomtai2PVKzsdUPeW9x08MFEoHru F+Wigx3ZDChydX2rQMwPDjwuYkq1NCjtQoQZi6OgrfBWidLSWMoUSW5hyl0tUswZyFbeA+ vwog51XkS/8cJS/+AdY8EGzPR/8YrG6j30gvRMcNIcoYrroMnAB2+ad2Inzn8kiRNnlmu3 LvN7qpoWXRclC/N9bShZlrdJnPKupP24wBgY3W2qYUDLSHFczux+A+xHoJHWew== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737050879; a=rsa-sha256; cv=none; b=fpDXzGX9Tnd0qOfN1kszgprP+yZxycugaJnDd8sKjX2x/64ODq/MWRMFKrcmlCHGhk3KRi Kj1ndOjz7Hf6ADi+NEfFHz7D09SgiZQQbrHgUByrYw77QxGqnytvur26vPj+ia7THvH912 RNMAiEksTLOGUKP+QrbCHUTvuh722Q9R6h9RP62PtEUqH4Ewu5ZFA/24RpGoF1SqHm+0B8 4V4quyZ7ebAKFEh07nAuIDnTmnmu0xToskA9AkWpVSoxAsvjSxX0TyR2YQorCd4uHDWbrj ALOP2pnJ1UlABT3T/zOaTEkUhCYpbtiNykF4n2lWoHh6FKBagb1Am/rIOpTTZg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4YYrSb35l9zjVn; Thu, 16 Jan 2025 18:07:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50GI7xS6091022; Thu, 16 Jan 2025 18:07:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50GI7x2n091018; Thu, 16 Jan 2025 18:07:59 GMT (envelope-from git) Date: Thu, 16 Jan 2025 18:07:59 GMT Message-Id: <202501161807.50GI7x2n091018@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: 3e496c9f10fc - stable/14 - Add function to OSD to get values without taking the 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: 3e496c9f10fc8add74722d9bd5b892a1149f31d8 Auto-Submitted: auto-generated The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=3e496c9f10fc8add74722d9bd5b892a1149f31d8 commit 3e496c9f10fc8add74722d9bd5b892a1149f31d8 Author: Stephen J. Kiernan AuthorDate: 2024-04-04 00:12:57 +0000 Commit: Olivier Certner CommitDate: 2025-01-16 18:06:52 +0000 Add function to OSD to get values without taking the lock. There are some cases of OSD use where the value is only initialized once at a point where successive access of the value can be done so safely without the need to take the lock. Reviewed by: markj Obtained from: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D44631 (cherry picked from commit 56b274213024957cea378d27393304ae5cc8ded9) --- sys/kern/kern_osd.c | 23 ++++++++++++++++------- sys/sys/osd.h | 5 +++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/sys/kern/kern_osd.c b/sys/kern/kern_osd.c index 1f93f7021201..9f5803847d24 100644 --- a/sys/kern/kern_osd.c +++ b/sys/kern/kern_osd.c @@ -279,25 +279,34 @@ osd_free_reserved(void **rsv) } void * -osd_get(u_int type, struct osd *osd, u_int slot) +osd_get_unlocked(u_int type, struct osd *osd, u_int slot) { - struct rm_priotracker tracker; void *value; - KASSERT(type >= OSD_FIRST && type <= OSD_LAST, ("Invalid type.")); - KASSERT(slot > 0, ("Invalid slot.")); - - rm_rlock(&osdm[type].osd_object_lock, &tracker); KASSERT(osdm[type].osd_destructors[slot - 1] != NULL, ("Unused slot.")); if (slot > osd->osd_nslots) { value = NULL; OSD_DEBUG("Slot doesn't exist (type=%u, slot=%u).", type, slot); } else { - value = osd->osd_slots[slot - 1]; + value = atomic_load_ptr(&osd->osd_slots[slot - 1]); OSD_DEBUG("Returning slot value (type=%u, slot=%u, value=%p).", type, slot, value); } + return (value); +} + +void * +osd_get(u_int type, struct osd *osd, u_int slot) +{ + struct rm_priotracker tracker; + void *value; + + KASSERT(type >= OSD_FIRST && type <= OSD_LAST, ("Invalid type.")); + KASSERT(slot > 0, ("Invalid slot.")); + + rm_rlock(&osdm[type].osd_object_lock, &tracker); + value = osd_get_unlocked(type, osd, slot); rm_runlock(&osdm[type].osd_object_lock, &tracker); return (value); } diff --git a/sys/sys/osd.h b/sys/sys/osd.h index 1c58c4fff8de..498cad5064f9 100644 --- a/sys/sys/osd.h +++ b/sys/sys/osd.h @@ -64,6 +64,7 @@ int osd_set_reserved(u_int type, struct osd *osd, u_int slot, void **rsv, void *value); void osd_free_reserved(void **rsv); void *osd_get(u_int type, struct osd *osd, u_int slot); +void *osd_get_unlocked(u_int type, struct osd *osd, u_int slot); void osd_del(u_int type, struct osd *osd, u_int slot); int osd_call(u_int type, u_int method, void *obj, void *data); @@ -79,6 +80,8 @@ void osd_exit(u_int type, struct osd *osd); osd_set_reserved(OSD_THREAD, &(td)->td_osd, (slot), (rsv), (value)) #define osd_thread_get(td, slot) \ osd_get(OSD_THREAD, &(td)->td_osd, (slot)) +#define osd_thread_get_unlocked(td, slot) \ + osd_get_unlocked(OSD_THREAD, &(td)->td_osd, (slot)) #define osd_thread_del(td, slot) do { \ KASSERT((td) == curthread, ("Not curthread.")); \ osd_del(OSD_THREAD, &(td)->td_osd, (slot)); \ @@ -98,6 +101,8 @@ void osd_exit(u_int type, struct osd *osd); osd_set_reserved(OSD_JAIL, &(pr)->pr_osd, (slot), (rsv), (value)) #define osd_jail_get(pr, slot) \ osd_get(OSD_JAIL, &(pr)->pr_osd, (slot)) +#define osd_jail_get_unlocked(pr, slot) \ + osd_get_unlocked(OSD_JAIL, &(pr)->pr_osd, (slot)) #define osd_jail_del(pr, slot) \ osd_del(OSD_JAIL, &(pr)->pr_osd, (slot)) #define osd_jail_call(pr, method, data) \