-
Notifications
You must be signed in to change notification settings - Fork 8.1k
boards: native_sim: add reboot for native sim #87987
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
boards: native_sim: add reboot for native sim #87987
Conversation
c2e3845 to
e4f4a85
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.
Thanks @koalatux
The reason why it does not build with the POSIX_API and why it won't work in some other cases, is because some of calls you intend to do to the Linux host are getting linked into the embedded code.
You need to split the reboot file in 2 files.
One of them, containing the code that interacts with the host side, which needs to be compiled in the native_simulator runner context.
The other, which provides sys_arch_reboot() and calls into a function provided from the first one, which is compiled with the embedded side of things.
Similarly as how we do with the native_sim drivers which interact with the host:
https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/entropy/CMakeLists.txt#L22-L27
see this branch: https://github.com/aescolar/zephyr/tree/native-sim-reboot
native_sim only works on Linux, so no issue there :)
A new file descriptor will be opened for the new pty. So that would be expected. But if one uses |
|
@aescolar thanks a lot for your explanations, your branch looks quite good to me. Just one question, is it guaranteed that Also I found there is a more efficient |
It should only be called from the first native simulator thread (which takes care of running the HW models/HW scheduling)
Better no. Lot's of users out there run on old kernels, and the performance benefit is really irrelevant in this case. By the way, if I do diff --git a/samples/hello_world/src/main.c b/samples/hello_world/src/main.c
index c550ab461cb..2a4f295186e 100644
--- a/samples/hello_world/src/main.c
+++ b/samples/hello_world/src/main.c
@@ -5,10 +5,13 @@
*/
#include <stdio.h>
+#include <zephyr/kernel.h>
+#include <zephyr/sys/reboot.h>
int main(void)
{
printf("Hello World! %s\n", CONFIG_BOARD_TARGET);
-
+ k_sleep(K_SECONDS(1));
+ sys_reboot(0);
return 0;
}And run it as |
I get from time to time |
e4f4a85 to
3934c70
Compare
|
@aescolar I pushed the changes including the ones from your branch. Do you want me to add a |
same here (ubuntu 24.04, kernel 6.8.0-57, glibc 2.39-0ubuntu8.4) |
Up to you |
boards/native/native_sim/Kconfig
Outdated
| config NATIVE_SIM_REBOOT | ||
| bool "Reboot native sim" | ||
| depends on REBOOT | ||
| default 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.
| default y | |
| default n |
This does not work with valgrind, and I guess with some other tools.
And I'd expect that a few developers only trigger reboots in error conditions (so they will prefer native_sim to error out), so I'm inclined to leave the default as 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.
I changed it. I did not have this use case in mind, I'm using native_sim to test behaviour where the real hardware also does a reboot.
Debian 12 (bookworm), kernel 6.12.12+bpo-amd64, glibc 2.36-9+deb12u10 |
I also assume |
d0772e8 to
30b1c85
Compare
Yes, unless somebody calls that API from somewhere else. But it should not really matter how many times it is called as it only sets that flag to true. |
The crash seems to only happen if the reboot is done really early at startup. Adding a bit more delay like the following is enough for the crash not to happen (it is now running since hours on my machine): |
|
The CI failure is due to #88159 |
still crashed after 205m23.264s and 2931398 reboots 😞 |
Add a reboot implementation for the native_sim target which restarts the current executable keeping the command line arguments after closing all open file descriptors. Signed-off-by: Adrian Friedli <adrian.friedli@husqvarnagroup.com> Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no> Co-authored-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
30b1c85 to
f209fc6
Compare
|
@koalatux why was it that this code was closing all open file descriptors? |
The reason for closing all open file descriptors is, that they are not leaked into the restarted process. |
Add a reboot implementation for the native sim which restarts the current executable keeping the command line arguments after closing all open file descriptors.
Test it for example with:
west build -p -b native_sim samples/subsys/shell/shell_module -t run -DCONFIG_REBOOT=y -DCONFIG_POSIX_API=nand then enter in the zephyr shellkernel reboot.Note: The pseudotty disconnects while the application restarts.
I could not get it working with CONFIG_POSIX_API enabled.
Probably only works on Linux because it relies on the proc filesystem.