From nobody Wed May 22 19:57:50 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 4Vl2Cf6PCKz5Kc9V; Wed, 22 May 2024 19:57:50 +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 4Vl2Cf5tHVz43Hq; Wed, 22 May 2024 19:57:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716407870; 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=oP2Pg2OTP25E+I4fabKA/H44vzKLhkawGOAW7JwuMlg=; b=t94qtEgzfNTmUnWH1d7iFM+CBRNwIdQgHN9DKPBcaPyY9U2RB7OsEIpck8OCy9UyXVIaaY iWb8EwbMZpxijYGzBuDE9NiOuky2f8NMQws6H7ipMHlEcH9aagCc/JLpTpR4X/VOlnKDOi CEfn9X5wURE8Bhkc2CiVf3jBhq56n7kOiOdzsMNYIwrSMyMa8mM3CIlfAnLJpxFCXg06fW JYVt88ubMT5IZpQJGTL+Ey7bO+J7Xvo2eCi2xd1pEtv+jRhFDxfmorBdO4cHxqOpzrFh9v tCvfxluLxBejqwM2XBO8M+kRVxMzxMreHjhaV9d1hOS1cqDdZQEKrRL9XK2CdA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716407870; a=rsa-sha256; cv=none; b=SzCvA8Uv/9mda+VdlwKsdYv5Dn8cysza2+MswZgCULUzpgKYgMFp1DITZyZ8uSrTEZQdOX fWdZsovHFHsBkOFHYpmwfy1ek16A6gELWruj3qNj2Gt/864UNSKIYl1xrrZofn+46H3DMf fK0x534Dq9TtmhXi9H4UT36RFYEVbnteH+deICDjqSyQADxq5VUN8xaLXDntOzSFxhAv5o lfHcEadSsdKW3liqupnCXC+lL99u54EcBdf6ArK0pTir7N59kej1VRqvqMyyWAYTwjYgvX bbn9joqhrOQD2HeCpTeXfOSMpoHbh1wcRYzIJuqmg6lcQvqtYCg3jG1sWRHE1A== 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=1716407870; 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=oP2Pg2OTP25E+I4fabKA/H44vzKLhkawGOAW7JwuMlg=; b=md62DESoTniLy9mnlUb6BoM92qnAIpn0gSvsZdS9qeN4PVaSsk4rIprOccjQan7jlJE3r5 CRNkjKKGYtpfkAEz4p88+K8sOvEOz7nhTosZf5ZoD/5Cqz/zBsvd0z/bENOX4iWCBJaS3D g6aiUMDZrz7elU+yK704zHkIyjbBDIY+BkEgvuFfahatWEBFUKl8EFb4Yg5THF5Kx9kUI3 uI9dKgQwmZrqpaSTtCrUMG5v9C/KDh8sAIrh/XmSK97+z+6eGrBmpgE9bGyc8A4IqlYzSs EhUCYn4qaoy3vcBIJPdHjSV8Gi1a8UHPP/aLPH0n9KNUbqt3hQSYHsXZVFvYNA== 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 4Vl2Cf5MFpzJqk; Wed, 22 May 2024 19:57:50 +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 44MJvoTa063490; Wed, 22 May 2024 19:57:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44MJvo59063488; Wed, 22 May 2024 19:57:50 GMT (envelope-from git) Date: Wed, 22 May 2024 19:57:50 GMT Message-Id: <202405221957.44MJvo59063488@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Stephen J. Kiernan" Subject: git: 56b274213024 - main - 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: stevek X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 56b274213024957cea378d27393304ae5cc8ded9 Auto-Submitted: auto-generated The branch main has been updated by stevek: URL: https://cgit.FreeBSD.org/src/commit/?id=56b274213024957cea378d27393304ae5cc8ded9 commit 56b274213024957cea378d27393304ae5cc8ded9 Author: Stephen J. Kiernan AuthorDate: 2024-04-04 00:12:57 +0000 Commit: Stephen J. Kiernan CommitDate: 2024-05-22 19:55:48 +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 --- 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 38db612d34d9..dcd80a948ea7 100644 --- a/sys/kern/kern_osd.c +++ b/sys/kern/kern_osd.c @@ -278,25 +278,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) \