pm: optimize resources #39397
I think get rid of the pm struct with the when
This is not a
Since an API change has not been discarded yet (usage of PM_DISABLE), I think it's worth considering all options to try avoiding yet another change in the future. In some other proposals, like pinctrl, optimizing memory usage has been a critical factor on the API design. If savings are considerable, increased complexity could be justified up to a certain point. I think Zephyr should be consistent on this aspect. I'm currently reviewing the runtime API to see if it can be simplified somehow, so this option may become less relevant. Let's see.
@yperess I have updated the PR with a simpler approach: a reference to the state is passed to the device definition macros (I think @carlescufi mentioned this option), making the change less impactful (NULL can continue to be used). I'll continue exploring the bind option and see if I can come up with something, or just feel free to work on it/contact me.
This change takes the following approach: 1. Create a new `struct device_subsystem_hooks` which will be extended anytime that a new subsystem requires direct access from a device. This will add `sizeof(void*)` to the device struct (less than adding `struct pm_device` per instance. Then an additional pointer per enabled subsystem that hooks to the device struct. 2. The subsystem is responsible for creating the device-to-pm pointer by adding a `const struct device*` to the `struct pm_device` (again a cost of 1 pointer per enabled PM device). The subsystem then registers a `SYS_INIT` which will iterate through the PM structs and set the pointers from the device back to the PM struct. This commit demonstrates a tradeoff. There's a slight increased cost in memory over PR zephyrproject-rtos#39397 in favor of an extensible API that allows device declaration to be separate from subsystems. Signed-off-by: Yuval Peress <email@example.com>
Define the device using DEVICE_DEFINE macro, so that a single option can be used regardless of PM being enabled or not. Signed-off-by: Gerard Marull-Paretas <firstname.lastname@example.org>
The macro already mentions in the docstrings that PM is not supported: "Invokes DEVICE_DEFINE() with no power management support". This patch removed the PM entry from the macro and ajusts its uses. Signed-off-by: Gerard Marull-Paretas <email@example.com>
It is well known that PM subsystem has never been optimized in terms of resource usage. The situation is particularly bad in case the PM runtime API is enabled. What this patch does is to move the responsability of PM resource definition to the device like this: - Device is responsible to define PM resources, using a new set of macros: PM_DEVICE_*DEFINE(). - DEVICE_*DEFINE macro accepts a reference to the device PM state, which can be obtained using PM_DEVICE_*REF() set of macros. This allows device to initialize the dev->pm reference. This method decouples a bit more PM from devices since devices just keep a reference to the device PM state. It also means that future PM changes will have less chances to impact all devices, but only devices that support PM. Signed-off-by: Gerard Marull-Paretas <firstname.lastname@example.org>
Increase main stack size (in 128 bytes) to make these tests run successfully on qemu_x86 platform. Signed-off-by: Gerard Marull-Paretas <email@example.com>