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
This commit is contained in:
Stephen J. Kiernan 2024-04-03 20:12:57 -04:00
parent a45a9e61b4
commit 56b2742130
2 changed files with 24 additions and 10 deletions

View File

@ -277,6 +277,24 @@ osd_free_reserved(void **rsv)
free(rsv, M_OSD);
}
void *
osd_get_unlocked(u_int type, struct osd *osd, u_int slot)
{
void *value;
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 = 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)
{
@ -287,16 +305,7 @@ osd_get(u_int type, struct osd *osd, u_int slot)
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];
OSD_DEBUG("Returning slot value (type=%u, slot=%u, value=%p).",
type, slot, value);
}
value = osd_get_unlocked(type, osd, slot);
rm_runlock(&osdm[type].osd_object_lock, &tracker);
return (value);
}

View File

@ -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) \