-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
device: refactor to aggregate common dynamic state for devices #31880
Conversation
75b5f93
to
8b04c44
Compare
8b04c44
to
a8df068
Compare
Added to dev-review to introduce this to the community. |
* an 8-bit integer. If initialized is also set, a zero value | ||
* indicates initialization succeeded. | ||
*/ | ||
unsigned int init_res : 8; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the impression that initialization functions in general return a negative value in case of error, and we will end up always with 0
when it succeed or 255
on error ... That means that use one bit would give the same info, We should probably keep it signed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nevermind, you invert the signal later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks good for me
While devices have driver-specific dynamic state accessed through the data field, there is also dynamic state that is common to most if not all devices. Add a structure to hold that data. Signed-off-by: Peter Bigot <[email protected]>
Initialize all device objects in a batch before invoking any code that might try to reference data in them. This eliminates a race condition enabled by the ability to resolve a device structure at build time, and reference it from one device's initialization routine before the device itself has been initialized. While the device is pulled from the sys_init records rather than static devices, all in-tree init_entry records that are associated with devices are produced via Z_DEVICE_DEFINE(), so there should be no static devices that would be missed by instead iterating over the device records. Signed-off-by: Peter Bigot <[email protected]>
This avoids the need for distinct object that uses flash to store its initializer. Instead the state is initialized when the kernel is starting up, before anything can reference it. In future refactoring the PM state could be accessed directly without storing an extra pointer in the static device state. Signed-off-by: Peter Bigot <[email protected]>
Separate the state indicator of whether the initialization function has been invoked from the success or failure of the initialization. This allows precise confirmation that the device is ready (i.e. it has been initialized, and that initialization succeeded). Signed-off-by: Peter Bigot <[email protected]>
Move the busy status from a global atomic bit sequence to atomic flags in the device PM state. While this temporarily adds 4 bytes to each PM structure the whole device PM infrastructure will be refactored and it's likely the extra memory can be recovered. Signed-off-by: Peter Bigot <[email protected]>
a8df068
to
714114c
Compare
This PR adds a common state structure to devices, and refactors so that this holds not only the device initialization status but also all device power management state. The refactoring reduces flash usage by changing initialization to allow the kernel to initialize the state without having a per-device backing value in flash. It increases RAM but some of the increase will go away with device PM refactoring, and there's space in other memory so that new enhancements won't incur an additional cost.
Fixes #28873