From nobody Fri Jan 17 12:26:53 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 4YZJrY4qQmz5kvFg; Fri, 17 Jan 2025 12:26:53 +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 4YZJrY3HHjz3TNW; Fri, 17 Jan 2025 12:26:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737116813; 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=CHJLGw/M+pMpGOmZcdBAKDud+2CX59ivhIeZon7b1Qo=; b=k5iVlmhjKQO/7t89ul8L4uUfnPlL6uUa5opIeNxbyjQ2fY90BRpF31Hylgd0gIsVZqg23Z TMQtKYw10eseeUh4xGQI+RR2G236sKRDHOTQkqzdTWTXgf9FK3fMnAyZTODimi1tOpFEjY cfFRB9ekWl03wrk5qwp7bTE47QrAlTtpU4fftQ27TBNVfDhq74HmVVBvqBhEXyajc/dmPU r20WOfSNDdGzTzCBjzPwvPUqCTVIvUct8p39SWk5VUyBbhws7KqisiErqWl85DA65DTfL0 tHKm4fyyUx1AQZe3CStxtq7lg9Sswz7AIYBHE5mtpB2acP9/lpZppf0TgdS+Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737116813; 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=CHJLGw/M+pMpGOmZcdBAKDud+2CX59ivhIeZon7b1Qo=; b=H9h9iO/dXXCYlkGBdtnc7XIdQZjvL9HeQLWIwaWx+Qasr0Nl7SHLDazn9dOHttKzVcn6zA 1Tqn4A+++/aGT5sRR33d/A3tx9qR0oDP6cH7bkxfdhqHUr5cfS2kNubhNvciUWanwnF9xw gELI6QejFBocz0WmCXMEh/Rk1GvmaRZ0NRRDS5tRlr1iHsKeWZlOwFLoGc0HBhlJhmgyGa 4lkRef9wDOr90M5zxUvAmkk5cwy8HSpuGEt+HdRxyAWEDB8ahEjFH8OQRrglBB8FXtR3ev QC1nbcatvIAblamMFYjrTj7N+q71iCG2GLMkQ6QctOvrAgK+2oFjpjImTWyleQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737116813; a=rsa-sha256; cv=none; b=Ps5FT5FXFLqLnFNWU7OF0tzJNQaNnzOWYGlk1QUs9Q3wgLprB9VcaH5OKjkhOHk27hpd63 +dhdrb8qk8QEwJcFqR2YyIvHEwj5OMwoXp7yefOwBNkjfzqoyjD9cqaZ8eH1cJO5DVHNlp 4f4SDODjOfL8fIU9ysp0UG8dp42EypiBw7pAaMbybAR/PeY8UTrZ84qUNgahDcP8Gv9u85 vNqpBY/COIND8KbuST9KAXCbZrKV6FTpKN5Ju0uPWx8VfHwZOETervgeG2IXDtMGmBagWN DEWmisKn4MJEkjP09mt4MlKHoIXd52n8fXkEaSYrqBKWjKT2JenKGbTGtgQ//g== 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 4YZJrY2dbyz2Wj; Fri, 17 Jan 2025 12:26:53 +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 50HCQrLH051590; Fri, 17 Jan 2025 12:26:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50HCQrLG051587; Fri, 17 Jan 2025 12:26:53 GMT (envelope-from git) Date: Fri, 17 Jan 2025 12:26:53 GMT Message-Id: <202501171226.50HCQrLG051587@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: 2d03e9cf8e2e - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: 2d03e9cf8e2ee39da7dc01471e09f9895ccd304e Auto-Submitted: auto-generated The branch stable/13 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=2d03e9cf8e2ee39da7dc01471e09f9895ccd304e commit 2d03e9cf8e2ee39da7dc01471e09f9895ccd304e Author: Stephen J. Kiernan AuthorDate: 2024-04-04 00:12:57 +0000 Commit: Olivier Certner CommitDate: 2025-01-17 12:24:47 +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 1b623d822cee..df5f771ac04e 100644 --- a/sys/kern/kern_osd.c +++ b/sys/kern/kern_osd.c @@ -293,25 +293,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) \