-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
linker: Allow for 999 priority levels in init levels #86999
linker: Allow for 999 priority levels in init levels #86999
Conversation
Hello @dewitt-garmin, and thank you very much for your first pull request to the Zephyr project! |
Wow - that's a lot of priority levels. If I may ask a couple of questions
The reason I ask, is that we generally want to avoid misusing sys_init to initialize drivers. The device model should really be used instead. Personally, I have no problem extending the number of levels, but it might not be useful for the average Zephyr user. Also, there may be some implications to existing services if this lands based on assumed highest / lowest priorities. |
Hi @cfriedt, Thank you for the quick response. I agree it is a lot of potential levels, but 100 does not seem out of reach for how many modules we may need to initialize. Further we may wish to leave gaps between different modules to allow for future expansion without having to bump all of the priorities to add a new module. To answer your questions:
I hear your concerns about this being a lot of levels, but it is more just ensuring that we have enough priorities if required. Ideally we get away with 99 but don't want to have a last-minute scramble if we need more. Please let me know if you have any other questions. Side note: I did not see any test infrastructure for SYS_INIT to modify for this change and did not see anywhere that we tested that 99 was achievable. I can add it somewhere but wasn't sure the most appropriate place, but this also seemed like a fairly straightforward code and documentation change. This also begs the question on if we are allowing 999, should we go for gold and go even larger? There's really no runtime cost to supporting more, just more input sections in the linker script. Thanks, |
Thanks for the PR! Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. |
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 guess there's no particular reason to reject this, it's cleanly implemented and harmless.
But yeah: my gut says this is probably moving in the wrong direction and that we should be looking at SYS_INIT() functions as a legacy thing and aiming innovation at the device model instead, where we can do things like track dependencies instead of just throw darts into a sparse number space of priorities.
Hi @andyross , Can you help me understand how device model solves this problem? Under the hood it uses the same linker input sections, currently limited to 99 priority levels. I'm also not sure how it would be usable for software-only modules that rely on other software modules that are not represented in device tree. It would also seem to use more ROM to keep track of the dependencies whereas this may be more tedious to program but resolves to an array of function pointers by the linker script. Not saying we couldn't benefit from using the device model in more places, I just am not seeing it to be a 1-1 replacement without any tradeoffs. Perhaps I am missing something so please let me know if my understanding is incorrect. Thanks, |
@dewitt-garmin - are you runtime-loading elf modules? If so, it might be possible automatically initialize all k-objects. |
Hi @cfriedt, No, we are not runtime-loading elf modules at this time on this product. We are initializing many different mid- to high-level software modules that we use in all of our standard products, whether they run on Zephyr or not. Thanks, |
@dewitt-garmin - in that case, it would really make sense to use Additional global state would be better to set up in a similar fashion where it's set at compile time and then initialized with the C runtime. Naturally, there are other potential initialization steps that are more procedural, which would require a SYS_INIT(). This gets tricky because it requires manual separation into separate priorities but only for dependent steps. Independent steps can be initialized using a common priority. |
Hi @cfriedt, We are dealing with a lot of legacy code that runs on several different platforms, not just zephyr, so we cannot change them to work just for zephyr. I am hoping we can squash these initializations into fewer priorities long term, but we also don't want to wait until we have 98 priorities in use and then come asking for change in a rush out of desperation. So while I hope we won't need more than 100 priorities, I think it is good to have this option on the table just in case. I don't think there are really any negative impacts to having other than maybe encouraging potentially bad practices, but that would be owned by the people making an application. I say potentially bad because for zephyr code there may be better ways, but for legacy shared code, this might be the easiest path. Am I understanding correctly? Thanks, |
Ok - thanks for the details. It helps for clarification. I have no major objections but it would be good to hear from @gmarull . |
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.
No objections. I'd recommend not to build too much on top of SYS_INIT, though.
Please update zephyr_linker_section_obj_level
in cmake/modules/extensions.cmake
b76081c
to
12969bc
Compare
Hi @gmarull, Thanks for the pointer. I found a few more places to update while working on e29c9c9. I can omit that patch if everyone prefer, but it did make things easier to read in the final linker scripts and map files when working on this change. Also I tried using _CONCAT_5 in linker-defs.h to fix Thanks, |
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.
first commit contains unrelated changes mixed, please, split
Nope, just split commit |
Hi @gmarull, You mean the test change versus the linker clang format change? Sure, I can split up that commit. Thanks, |
clang-format will remove the space after the equals sign causing link issues. Disable clang-format for some linker macros since they should not be formatted as C code. Signed-off-by: Josh DeWitt <josh.dewitt@garmin.com>
Ensure the priority is surrounded by underscores for clarity. This makes sections show up as z_init_PRE_KERNEL_1_0_0_ instead of z_init_PRE_KERNEL_10_0_ Signed-off-by: Josh DeWitt <josh.dewitt@garmin.com>
Add a test to ensure that the max expected 2-digit SYS init priority works. Signed-off-by: Josh DeWitt <josh.dewitt@garmin.com>
12969bc
to
f2e0114
Compare
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.
Wow, feels excessive but I guess you have a use case for it and there's no drawbacks so I guess why not. Also thanks for taking the time to add that underscore to the object symbol file.
Compliance is finding some issues, I think it's good if you can fix those, right now since it's your first PR someone has to approve the workflow but you can also run it locally with ./scripts/ci/check_compliance.py
.
Hi @fabiobaltieri,
Did you see my reply here? I do not know how to make it pass check_compliance.py since the current code fails and there does not seem to be a way to satisfy it. Is there an inline suppression I can do similar to clang-format?
Thanks, |
Some projects may have needs for more than 99 priority levels, so add a third linker input section for each obj level. Signed-off-by: Josh DeWitt <josh.dewitt@garmin.com>
f2e0114
to
fb18b6a
Compare
Sorry missed that. If it's a false positive then just let it fail, we can ask the org admin to bypass the check and merge it. |
Hi @dewitt-garmin! To celebrate this milestone and showcase your contribution, we'd love to award you the Zephyr Technical Contributor badge. If you're interested, please claim your badge by filling out this form: Claim Your Zephyr Badge. Thank you for your valuable input, and we look forward to seeing more of your contributions in the future! 🪁 |
Unfortunately this completely broke linking for IAR. It would really help if there were some tests run with IAR. |
Looks like the wildcards are ambigous? If this is due to CMAKE_LINKER_GENERATOR or affects LD silently as well I will need to be looked into
I am not too well versed in this to propose a hotfix. Let's revert? @nashif @kartben ? |
Not much point reverting if the author (or the bulk of the community) has no access to the tooling to fix it, until that's the case I think these should be forward fixed, there were some discussions about this in #63738. |
@fabiobaltieri sure thing I appreciate that we haven't had a satisfactory solution here for the proprietary toolchains. but the fact that |
Oh ok, I missed the details about it and somehow though it was only impacting the IAR linker, yes then I think this justifies a rollback, maybe just do the last two commits, I think the first two can stay. Unless we can come up with a hotfix of course, wouldn't it be enough to disambiguate the quialifier? like adding an extra |
Some projects may have needs for more than 99 priority levels, so add a third linker input section for each obj level.