-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
llext: convert "modules" tests to sample #74060
llext: convert "modules" tests to sample #74060
Conversation
8e277c4
to
b0a6452
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.
Thank you for doing this, and yes this makes great sense to not repeat the same work over and over for showing how the tristate Kconfig works.
@lyakh should run this with qemu_xtensa at the very least and approve before merging, marking DNM (with my +1 here) until @lyakh does just that. Feel free to remove DNM once reviewed and approved by @lyakh.
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.
this is awesome stuff - thanks! Some minor nits/typos in case this goes through another round of updates.
their symbols can be accessed and functions called. | ||
|
||
Specifically, this shows how to call a simple "hello world" function, | ||
implemented in ``src/hello_world_ext.c``. This is achieved in two different ways, |
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.
nit (i.e. not worth updating unless there's another round of reviews needed): maybe make this a :zephyr_file:
like you're doing for others
:relevant-api: llext | ||
|
||
Call a function in a loadable extension module, | ||
either built in or loaded at runtime. |
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.
either built in or loaded at runtime. | |
either built-in or loaded at runtime. |
samples/subsys/llext/modules/Kconfig
Outdated
default m | ||
help | ||
This enables calling the hello_world function, implemented in | ||
hello_world_ext.c, either as an llext module or as a built in part of |
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.
hello_world_ext.c, either as an llext module or as a built in part of | |
hello_world_ext.c, either as an llext module or as a built-in part of |
tests: | ||
sample.llext.modules_enabled: | ||
extra_configs: | ||
- CONFIG_MODULES=y |
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.
just to make sure this is correct - it's also set in prj.conf and left unchanged below in the monolithic case - is that correct?
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.
Thanks, you are right, it's an useless line. The point is to have MODULES
always enabled during this test so I will remove this.
extra_configs: | ||
- CONFIG_MODULES=y | ||
- CONFIG_LLEXT_STORAGE_WRITABLE=y | ||
- CONFIG_LLEXT_TYPE_ELF_RELOCATABLE=y |
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.
as an example, I looked for another CONFIG_LLEXT_STORAGE_WRITABLE=y && CONFIG_LLEXT_TYPE_ELF_RELOCATABLE=y
test here since you're saying, that you're removing copies, and I haven't found such a test, am I missing something?
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, you're right - that was a proper mistake. 🙂
I will make sure to check all removed paths and convert them to non-MODULES in case they were not duplicates.
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.
Looks nice! A few points that I think need to be addressed/checked:
- simulation | ||
- arch | ||
platform_exclude: | ||
- qemu_cortex_a9 # MMU |
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.
Cortex-A9 platform exclusion seems gone in sample.yaml
.
Is this on purpose?
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.
Yes, that exclusion was there before the runtime filter was added, so that platform should be caught by the above filter anyway. I will double-check this before submitting v2 though.
filter: not CONFIG_MPU and not CONFIG_MMU and not CONFIG_SOC_SERIES_S32ZE | ||
platform_exclude: | ||
- apollo4p_evb | ||
- apollo4p_blue_kxr_evb |
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.
Please add a comment referring to issues 72775 / 73443 for apollo platforms, to make the reason why they are excluded obvious (as done for the numaker right below).
{ | ||
printk("Hello, world!\n"); | ||
} | ||
LL_EXTENSION_SYMBOL(hello_world); |
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.
If CONFIG_LLEXT_HELLO_WORLD=y
, this file will be built as part of the Zephyr application. However, there is nothing special in the LL_EXTENSION_SYMBOL
macro that makes it not emit the export table entry.
Is there no risk to blow up CI with orphan section linker warnings due to something being emitted to the .exported_sym
section which, AFAICT, is not handled in Zephyr linker script?
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.
Interesting... it did not in my tests, but I can't be sure it won't everywhere. I will fix this as we did for the EXPORT_SYMBOL
macro: make it a NOP if LLEXT is not enabled, and disable LLEXT for the =y case.
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'm not sure this would work in this case though; AFAICT, CONFIG_LLEXT is always y
for this sample. Maybe switching according to the tristate's value would work though (but I don't know what CONFIG_LLEXT_HELLO_WORLD=m
yields once converted to C macro...)
CONFIG_LOG=y | ||
CONFIG_LOG_MODE_IMMEDIATE=y | ||
|
||
CONFIG_MODULES=y |
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.
Nit, and definitely out of this PR's scope: I find this Kconfig option's name quite confusing at first glance.
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.
Indeed it is. We can't change it unless we modify kconfiglib
internals, though, since that is the name that triggers the whole "tristate" stuff in Kconfig. 🙁
LOG_MODULE_REGISTER(app); | ||
|
||
#include <zephyr/llext/llext.h> | ||
#include <zephyr/llext/buf_loader.h> |
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.
These includes seem unneeded.
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.
Thanks everyone for your comments, will try to address all of them 🙂
CONFIG_LOG=y | ||
CONFIG_LOG_MODE_IMMEDIATE=y | ||
|
||
CONFIG_MODULES=y |
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.
Indeed it is. We can't change it unless we modify kconfiglib
internals, though, since that is the name that triggers the whole "tristate" stuff in Kconfig. 🙁
tests: | ||
sample.llext.modules_enabled: | ||
extra_configs: | ||
- CONFIG_MODULES=y |
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.
Thanks, you are right, it's an useless line. The point is to have MODULES
always enabled during this test so I will remove this.
{ | ||
printk("Hello, world!\n"); | ||
} | ||
LL_EXTENSION_SYMBOL(hello_world); |
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.
Interesting... it did not in my tests, but I can't be sure it won't everywhere. I will fix this as we did for the EXPORT_SYMBOL
macro: make it a NOP if LLEXT is not enabled, and disable LLEXT for the =y case.
- simulation | ||
- arch | ||
platform_exclude: | ||
- qemu_cortex_a9 # MMU |
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.
Yes, that exclusion was there before the runtime filter was added, so that platform should be caught by the above filter anyway. I will double-check this before submitting v2 though.
extra_configs: | ||
- CONFIG_MODULES=y | ||
- CONFIG_LLEXT_STORAGE_WRITABLE=y | ||
- CONFIG_LLEXT_TYPE_ELF_RELOCATABLE=y |
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, you're right - that was a proper mistake. 🙂
I will make sure to check all removed paths and convert them to non-MODULES in case they were not duplicates.
b0a6452
to
c4d58b2
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.
LGTM.
:zephyr-app: samples/subsys/llext/modules | ||
:board: qemu_xtensa | ||
:goals: build run | ||
:gen-args: -DCONFIG_LLEXT_HELLO_WORLD=y |
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.
Shouldn't this be -T sample.llext.modules_disabled
instead?
:zephyr-app: samples/subsys/llext/modules | ||
:board: qemu_xtensa | ||
:goals: build run | ||
:gen-args: -DCONFIG_LLEXT_HELLO_WORLD=m |
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.
Shouldn't this be -T sample.llext.modules_enabled
instead?
c4d58b2
to
4c850da
Compare
4c850da
to
594d8aa
Compare
The LL_EXTENSION_SYMBOL macro is used to export a symbol to the base image. When CONFIG_LLEXT is not defined, or the file is being compiled outside of an llext, the macro is not useful and would leave orphan sections in the final image instead. This patch adds the LL_EXTENSION_BUILD definition to the llext build process, and uses it to stub out the symbol-defining macro when not building an llext. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
This adds a new sample to demonstrate the use of tristate symbols in Kconfig to build a function as an llext module or as a built-in part of Zephyr. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
These tests are simple copies of the existing tests with the addition of the CONFIG_MODULES=y option. This different Kconfig setting has no practical effect on the code, and the tests are therefore redundant. Remove them to halve the number of tests. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
594d8aa
to
9eb02d1
Compare
Thanks @mathieuchopstm for making me think a bit more about what we are trying to explain here. v2:
Note [1]: the first commit adds an Ready for review/test as soon as CI turns this way... 🙂 |
@mathieuchopstm did you accept the invite? should have a green checkbox |
Pretty sure I did, I'm confused as well 🤔 EDIT: and as a matter of fact, in my GitHub security log, I do have entries for |
The current llext test suite contains a number of tests that are called
modules_enabled
and were originally added in #67105 as a way to showcase the Kconfigtristate
element type; those have since been expanded to 8 tests covering all current llext option combinations.This abundance of tests, however, is not useful: since the different Kconfig options have no practical effect on the llext code, all those tests perform exactly like the non-modules-enabled configuration and just double the testing effort and number of configurations in
testcase.yaml
.This PR replaces those redundant tests with a sample that shows how to actually create a "module" in the Linux kernel sense - a piece of code that can be either linked in or loaded at runtime.