-
Notifications
You must be signed in to change notification settings - Fork 7.4k
llext: add dynamic heap allocation support #90763
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
base: main
Are you sure you want to change the base?
Conversation
Hello @alexivanov-google, and thank you very much for your first pull request to the Zephyr project! |
Please squash commits |
Some applications require loading extensions into the memory which does not exist during the boot time and cannot be allocated statically. Make the application responsible for LLEXT heap allocation. Do not allocate LLEXT heap statically. Signed-off-by: Alex Ivanov <alexivanov@google.com>
squashed |
|
Do I need to trigger presubmit rerun somehow? Could not find the right "button" :) |
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. I have a few minor nitpicks on the current code, and two bigger questions for you:
- can you give a brief usage example? Are there any alternatives to basically pasting the same line in the app?
- what happens if you call LLEXT APIs while the heap is not allocated? I was expecting additional checks at least in
llext_mem.c
. Is that implicit with heap APIs?
@@ -60,6 +60,14 @@ config LLEXT_BUILD_PIC | |||
most internal linking is performed by the linker at build time. Select "y" | |||
to make use of that advantage. | |||
|
|||
config LLEXT_HEAP_DYNAMIC | |||
bool "Do not allocate static LLEXT heap" | |||
default n |
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.
default n
is implicit, can be removed
Some applications require loading extensions into the memory which does not | ||
exist during the boot time and cannot be allocated statically. Make the application | ||
responsible for LLEXT heap allocation. Do not allocate LLEXT heap statically. |
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 mention how to do this as well. I suppose you need to define llext_heap
in the app?
@@ -60,6 +60,14 @@ config LLEXT_BUILD_PIC | |||
most internal linking is performed by the linker at build time. Select "y" | |||
to make use of that advantage. | |||
|
|||
config LLEXT_HEAP_DYNAMIC |
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.
Move this before LLEXT_HEAP_SIZE
. Make that entry conditional on !LLEXT_HEAP_DYNAMIC
, since specifying the size becomes useless with a dynamic heap.
Hi Luca, thanks for looking at the patch! My system does not have enough RAM to execute the code that is only needed for the boot-time hardware initialization. LLEXT to the rescue: I build the code that runs the initialization flow as an LLEXT module. During my boot time I can configure a temporary scratchpad memory bank. This is done dynamically, the scratchpad is not available during the main application body loading phase. So now, comes the problem with the heap, as I don't want to allocate the heap in the main RAM, it is only needed during the LLEXT execution phase, after which the scratchpad (and the LLEXT stack) disappears. So I am declaring the LLEXT heap in the app and initialize the heap in the scratchpad memory as follows:
Currently if the heap is not initialized by the application, the application crashes, the heap API is not checking for null pointers. If we are to check for a null pointer in the LLEXT API, I have some questions:
|
Some applications require loading extensions into the memory which does not exist during the boot time and cannot be allocated statically. Make the application responsible for LLEXT heap allocation. Do not allocate LLEXT heap statically.