Skip to content
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

[DNM][WIP][do not review yet]Service and Device initialization: automatic priorities #79340

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

tbursztyka
Copy link
Collaborator

DO NOT REVIEW YET (I just need to see first what CI will find out, my potato PC cannot run the whole test suites)

This is a fix for #76937 after discussing on the RFC #73836

I applied most comments made during these discussion.

  • Keeping current macros unchanged and able to live with the new ones
  • Adding new macros: both for device and service (not init, SYS_INIT() will be deprecated as well anyway). Taking the opportunity to reduce the number of macros. Basically merging DT/non-DT based macros, so removing manually introduced device name. This is a legacy thing that needs to disappear. Explicit device name is coming from the time DTS was not used, and during the process of switching to DTS we had to keep it. Now it's not true anymore. The new macros still can instantiate a non-DT device, but it will take the unique token as a name and that's it.
  • Declaring the explicit dependency resolution file to cmake via cmake functions and not by looking up on pre-determined places (only on the application side, I could not use such cmake function, so there it has to be a specific file, unless I misunderstood something with the build process)
  • The new service API is extremely minimal as it is meant to just replace SYS_INIT where relevant (like, say: net_init, and not all the places where SYS_INIT should not have been used). BUT: it will grow, there are plenty of rooms for improvements. We could start/stop/pause a service if needed, etc etc...

Added to this I (tried to) switch most device macro calls to new ones. Which make this PR a huge one in files touched and modified lines. There are few corner cases which prevent changes: PTP and ethernet's DSA. These needs to switch to DTS.

Last but not least: brace for impact /o\

Run after Kconfig and DTS, so it can build up on top of the edt object.
Thus filling in any gap left by Kconfig and DTS.

Signed-off-by: Tomasz Bursztyka <[email protected]>
All service or device init files added to any valid CMakeLists.txt will
now be used to generate include/zephyr/generated/zinit.h header file,
with computed priorities.

Signed-off-by: Tomasz Bursztyka <[email protected]>
It provides useful macros to manipulate generated ZINIT_ macros from
gen_init_priorities.py script.

Signed-off-by: Tomasz Bursztyka <[email protected]>
The sub-prio is entirely removed, as the new macros will bring uniquely
computed priorities.

This is seamless: none of this is of public API, so no deprecation and
macro replacement is necessary at this stage.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Now that priorities are automatically computed, and mostly coming from
DTS, it can easily go beyond 99.

Actually, this arbitrary limit of 99 in level sections has no real
meaning anymore (if it ever had any).

Signed-off-by: Tomasz Bursztyka <[email protected]>
This is an optional commit, but it makes things slightly easier to read
in zephyr.map.

Signed-off-by: Tomasz Bursztyka <[email protected]>
SERVICE_INSTANCE_INIT_ONCE is a direct replacement for SYS_INIT_NAMED,
removing the priority parameter as it is now provided by
gen_init_priorities.py script.

No alias will be created for SYS_INIT as we seek to limit the usage of
SERVICE_INSTANCE_INIT_ONCE, on the contrary to SYS_INIT which got widely
abused in the past.

Signed-off-by: Tomasz Bursztyka <[email protected]>
In order to get rid of the manually inserted initialization priority,
device object generation need new macros.

Until now, 2 set of macros have co-existed because of legacy support.
Indeed, devices used to be created fully manually before devicetree
introduction. Once devicetree appeared, DT based macros were added.
Now is the time to get rid of such difference, and have a unique macro
for creating device objects.

So instead of DEVICE_DEFINE() and DEVICE_DT_DEFINE() there will be
DEVICE_INSTANCE(). Instead of DEVICE_DT_INST_DEFINE() there will be
DEVICE_INSTANCE_FROM_DT_INST(). Instead of DEVICE_GET() and
DEVICE_DT_GET(), there will be DEVICE_INSTANCE_GET().
Same for DEVICE_INIT_DT_GET() and DEVICE_INIT_GET(), there will be
DEVICE_INIT_ENTRY_GET()

In the future step of deprecating old macros, these are then identified:
- DEVICE_DEFINE
- DEVICE_DT_DEFINE
- DEVICE_GET
- DEVICE_DT_GET
- DEVICE_INIT_DT_GET
- DEVICE_INIT_GET
- DEVICE_NAME_GET() could be replaced by DEVICE_INSTANCE_NAME())
- DEVICE_DT_NAME_GET() could be replaced by DEVICE_INSTANCE_NAME())
- DEVICE_DECLARE() could be replaced as well

And probably some more, thus reducing the amount of macros which would
help to clean-up the header and have a more concise set.

The difference is now that priority parameter is removed, as well as the
name parameter (originaly from DEVICE_DEFINE legacy macro). In this case
it is just simpler to reuse the "unique token" dev_id.

Because of the dependency being fully computed _prior_ to building
zephyr, these new macros do not support CONFIG_DEVICE_DEPS anymore. This
feature was never really used anywhere and is a legacy thing. So new
macros do not accept variable arguments.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Switching to DEVICE_INSTANCE and DEVICE_INSTANCE_FROM_DT_INST, thus
merging former DEVICE_DEFINE and DEVICE_DT_DEFINE into one, so removing
the name parameter from the earier and finally removing the prio
parameter on all.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Switching to DEVICE_INSTANCE and DEVICE_INSTANCE_FROM_DT_INST, thus
merging former DEVICE_DEFINE and DEVICE_DT_DEFINE into one, so removing
the name parameter from the earier and finally removing the prio
parameter on all.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Switching to DEVICE_INSTANCE and DEVICE_INSTANCE_FROM_DT_INST, thus
merging former DEVICE_DEFINE and DEVICE_DT_DEFINE into one, so removing
the name parameter from the earier and finally removing the prio
parameter on all.

Signed-off-by: Tomasz Bursztyka <[email protected]>
In order to get rid of the manually inserted initialization priority,
device object generation need new macros.

Again removing the prio parameter.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Switching to SENSOR_DEVICE_INSTANCE and
SENSOR_DEVICE_INSTANCE_FROM_DT_INST, thus removing the prio parameter
on all.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Again removing the prio parameter.

Managing the ident as a DT node-id or dev_id helps to reduce the number
from 12 to 7 macros.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Switching to NET_DEVICE_INSTANCE, NET_DEVICE_INSTANCE_FROM_DT_INST,
NET_DEVICE_INSTANCE_MULTI, NET_DEVICE_INSTANCE_MULT_FROM_DT_INST,
NET_DEVICE_OFFLOAD_INSTANCE and
NET_DEVICE_OFFLOAD_INSTANCE_FROM_DT_INST.

Thus removing prio and name parameters on all.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Again removing the prio and name parameters.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Switching to ETH_NET_DEVICE_INSTANCE,
ETH_NET_DEVICE_INSTANCE_FROM_DT_INST and ETH_NET_DEVICE_INSTANCE_MULTI.

Thus removing prio and name parameters on all.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Switching to NET_DEVICE_INSTANCE, NET_DEVICE_INSTANCE_FROM_DT_INST,
NET_DEVICE_INSTANCE_MULTI, NET_DEVICE_INSTANCE_MULT_FROM_DT_INST,
NET_DEVICE_OFFLOAD_INSTANCE and
NET_DEVICE_OFFLOAD_INSTANCE_FROM_DT_INST.

Thus removing prio and name parameters on all.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Again removing the prio parameter.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Switching to CAN_DEVICE_INSTANCE and CAN_DEVICE_INSTANCE_FROM_DT_INST
relevantly.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Again removing the prio parameter.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Switching to SMBUS_DEVICE_INSTANCE and
SMBUS_DEVICE_INSTANCE_FROM_DT_INST relevantly.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Lone files that define their own wrapper macro on top of formely
DEVICE_DT_DEFINE macros.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Again removing the prio parameter.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Switching to I2C_DEVICE_INSTANCE and I2C_DEVICE_INSTANCE_FROM_DT_INST
relevantly.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Again removing the prio parameter.

However, original macro does not seem to be used anywhere...

Signed-off-by: Tomasz Bursztyka <[email protected]>
Again removing the prio parameter.

And switching the unique macro call in drivers.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Switching to DEVICE_INSTANCE and DEVICE_INSTANCE_FROM_DT_INST, thus
merging former DEVICE_DEFINE and DEVICE_DT_DEFINE into one, so removing
the name parameter from the earier and finally removing the prio
parameter on all.

Signed-off-by: Tomasz Bursztyka <[email protected]>
A few test and samples require explicit dependency resolution as the
devices they introduce do not have any DTS counter-part.

Signed-off-by: Tomasz Bursztyka <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Device Management area: Device Model DNM This PR should not be merged (Do Not Merge)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant