Page MenuHomeFreeBSD

device: add generic named per-device property
ClosedPublic

Authored by kib on Sep 8 2024, 5:52 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Oct 20, 4:17 AM
Unknown Object (File)
Thu, Oct 17, 6:19 PM
Unknown Object (File)
Oct 3 2024, 12:18 AM
Unknown Object (File)
Sep 30 2024, 1:38 PM
Unknown Object (File)
Sep 23 2024, 1:34 AM
Unknown Object (File)
Sep 22 2024, 8:44 PM
Unknown Object (File)
Sep 19 2024, 2:32 AM
Unknown Object (File)
Sep 18 2024, 3:58 PM
Subscribers

Details

Summary
The KPI allows to store arbitrary data within struct device, retrieve it
back by name, and update the value.  The data is automatically destroyed
on the device deletion.  Also, the user can request to clear the named
property from all devices.

My need for this interface is due to IOMMU needing to save some
indicator on device, which must survive the re-creation of the domain
context.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kib requested review of this revision.Sep 8 2024, 5:52 AM

'man osd' won't help?

osd was my initial thought when I realized that I need this. But looking closely at interface, and realizing that I need to modify osd.h just to add my new osd type made me much less enthusiastic.

Also, osd would need too much rituals to be used: slots are identified by ints, while I can name them directly by iommu devunit name, etc, the overhead of osd is by order higher both in locking and in memory use. My code also has a way to conveniently destroy properties on either device or consumer destruction.

Ping?

I have at least one more use for this: I plan to use the props to report iommu unit serving specific device.

This seems reasonable to my eye.
I'd feel better if there were a man page for it, though.

This revision is now accepted and ready to land.Sun, Oct 13, 10:05 PM
In D46605#1073513, @imp wrote:

This seems reasonable to my eye.
I'd feel better if there were a man page for it, though.

I will write the man page after the KPI sit some time in main, to catch any general public' suggestions.

In D46605#1073525, @kib wrote:
In D46605#1073513, @imp wrote:

This seems reasonable to my eye.
I'd feel better if there were a man page for it, though.

I will write the man page after the KPI sit some time in main, to catch any general public' suggestions.

works for me. Thanks!

I will write the man page after the KPI sit some time in main

Most of the interface is obvious (to me), but some interesting points:

  • for device_set_prop, If a property with the same name already exists, it is overwritten with the new value. EEXIST is returned in this case.
  • the memory pointed to by name passed to device_set_prop must remain static for the lifetime of the property

I will write the man page after the KPI sit some time in main

Most of the interface is obvious (to me), but some interesting points:

  • for device_set_prop, If a property with the same name already exists, it is overwritten with the new value. EEXIST is returned in this case.

This is intended, of course.

  • the memory pointed to by name passed to device_set_prop must remain static for the lifetime of the property

This is also intended. It is in-line with the destructor -based KPI for properties, since I want the owner to 1. be able to flush all owned properties (e.g. on owner detach) 2. to be able to handle device detach. From this PoV, typical consumer would provide the same string pointer to all prop_set() call.

I will note these cases in the hypothetical man page, thanks.

This revision was automatically updated to reflect the committed changes.