-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add supervisor.set_next_code_file() #3454
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
Conversation
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!!! This approach looks really good overall. I have a question about reload_on_success but it should be easy to sort out.
If this is used in an OTA case maybe we want something like "errors_ok=False" where a failure in the next code reverts what is run back to code.py. When on USB, I think an error would be ok.
Wild idea, what if you use the same approach to save the traceback string and provide it to the code.py? That way an OTA could capture the error.
Thanks for the comments! Together with the implementation experience, they enable me to identify more higher-level requirements and I decided to go back to #1084 to discuss that, or should we continue everything here?
Sounds good, but maybe that would best be tackled in a separate PR? I’m not sure offhand how easy that is to obtain – is it still stored anywhere after |
Yup, agreed a separate PR is best. I don't know how to get it either. |
1b3b5f9
to
c97078d
Compare
This force push
By the way, are the artifacts from the automated build available anywhere? The logs say |
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 looks good to me. It's a bit complex but it's an advanced API and I'm not actually sure what we'll want. I'm fine if you want to undraft it and then we can merge.
That’s good to hear, my thinking was to reduce the complexity a bit and only keep what we need before merging. I’m not sure yet what that is either, but we’re not done yet figuring it out. It partially depends on how the “retain previous traceback“ feature comes along (expect a PR on that later, maybe tonight) and on resolving divergent opinions. (By the way, I found the artifacts – top right of the build output. A text search would have found it… Will probably rebase so we get the latest state built too.) |
Rebased to fix trivial merge conflict and get a new build. No content changes (so don’t bother re-reviewing). More changes forthcoming, but they’re not ready yet. |
Hi @cwalther Thanks for the new functionality. I tested "set_next_code_file()" this afternoon and it is just what I needed. Do you have a time line on when you intend to merge the functionality into the main branch? Thanks for your time! Cheers, Lee |
I have an implementation on a more robust base than this prototype almost done. I hope to have pull requests ready for review this week. A few more days to weeks of review and discussion will then probably be required before the final merge. Thanks for testing! Would you mind telling which of the optional keyword arguments to |
Hi @cwalther, I have a pretty simple use case, my supervisor calls are as follows: For me, I prefer the VM not running my menu system (code.py) when the secondary script raises an unhandled exception. I am developing a factory test fixture, so leaving error information on the screen is preferential. That said, for commercial products it may be preferential to reload the original code.py script if the secondary script crashes. One nice to have would be to run scripts from an SD card. I am guessing this would require running a configuration script to mount the SD card prior to running the secondary script. This is just a nice to have, but something to think about. Thanks for the work you are doing on this! Cheers, Lee |
b1996c2
to
9bd1ad6
Compare
This is now implemented on top of the movable allocation system. Functionality should be unchanged from the previous revisions. Only the last commit is relevant, the rest are from #3695. |
Will fix the mimxrt10xx and xtensa failures soon, I missed something there. That it would overflow the flash on some of the smaller boards I kinda feared. Pruning back the optional arguments will reduce the size a little, but probably not enough for all of them. Open for discussion on what to do about that. |
I wonder if it will fit better now, with the complex arithmetic removed. |
Working on it. I plan to make it optional anyway, and then we’ll see on how many boards it can be enabled. |
As a sign of life, here is the previous state rebased on current main. I have not checked yet whether the way I merged it with the sleep changes makes sense. Haven’t mustered the motivation to learn how sleep works yet, it looks complicated. I also haven’t made any of the other promised/planned changes yet. |
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 for pushing your latest code! Sorry it overlapped with the deep sleep changes. I think we'll want to treat deep sleep like a successful run.
Thanks for taking up work on this! I’m embarrassed about dropping the ball. I’m busy right now but I’ll try to at least take a look at your changes. |
I've brought this up to date with the Main branch and removed the use of
Currently, true deep sleep will just "not work" with the next_file system and will always default to startup behavior (ie return to the menu) which we should make a note of in the docs if we push the sleep solution to a later PR. I think the best solution for deep sleep is probably to add a new API to the Sleep Memory system that keeps track of how much sleep RAM is in use by the user, and adds system reservations to the end of the block, reducing the available "size" at runtime. If it conflicts with user-reserved memory, or if the user tries to encroach on system memory, it'll throw a runtime error. |
No problem! We know folks don't always have time to contribute. We're happy to pick it up. You got it very far!
No, I don't think so. It's an advanced API so it can have all of the options.
I think it's ok to have as an option. It's meant for advanced use and presumably the user intends to hide errors.
After today's meeting we decided to set aside part of sleep memory to store the next filename. It'll be part of a fixed area so that the user accessible portion of sleep memory is consistent. |
My 2 cents, without having examined the code yet:
I did originally intend to pare down the options, but if you are OK with keeping them, that’s fine with me too. I think we were approaching a consensus around #1084 (comment).
As far as I’m concerned, dealing with deep sleep is outside of the scope of this proposal. I’m fine with having it “not work” (work the same way as a hard power-off). I agree it should be mentioned in the function docs though, where currently only “powering off or resetting” is mentioned. But if you can make it work, all the better. Finally: “All checks have passed” – does that mean it now also fits on the small SAMD21s and doesn’t need to be made optional? Nice! |
We've discussed adding all of the deep sleep integration settings in a new PR, so if this is passing CI and other people can confirm that it works for their purposes under test, it should be good to go, right? |
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.
Works for me! Thanks for picking this up @hierophect!
I have tested the new version and it appears to work fine in my game console menu use case. 👍 Some code review notes: Your
I’m not totally sure about the interaction with deep sleep since I still haven’t put in the effort to understand how that works in detail, but it seems to me like in the event of entering a fake deep sleep (not a real deep sleep because then the settings are lost anyway), the |
This was intentional, I didn't want the code to restart without any text indicator that it did so.
I will double check this, not sure if I understand you totally.
Currently the system masks out deep sleep exceptions and will never skip when they are present. The interaction issue is that true deep sleep, across all ports, acts more like a power reset than a soft-reboot - it clears all ram and register contents except for those in the vendor's sleep management peripheral. To store any information across deep sleep at all requires use of special ram banks that we refer to as "sleep memory", which are handled differently based on the port since they all have different hardware implementations. Without a special API integration using this sleep memory, a chip waking from deep sleep has no way of knowing what the next file allocation was, and will return to the main menu as if it was waking from a reset. This is not intuitive behavior for a sub-program: users will expect that their software examples would work the same whether they are main/sub program, but in the deep sleep case they would act very differently. It's a bad "philosophical" problem, which is why I'm putting in the extra effort to make sure deep sleep programs can wake up to the same file they slept in. |
Specifically, if
That much is fine. That is the Or perhaps it’s a separate category from “success”, “error”, and “reload” altogether? There probably doesn’t need to be an additional argument |
@cwalther if you are entering a deep sleep exception for true deep sleep, the code stickiness situation is irrelevant - all of that information will be lost when the RAM shuts down. The program will never reach a decision point where it would use it. This is slightly different for a fake deep sleep, but we try to make fake sleep as similar to true deep sleep as possible, so the stickyness should not be retained in that case either. |
Think of deep sleep as basically being an exception that causes the entire chip to lose power for a set duration of time, and start up essentially from scratch, with some very limited data that we can fetch out of a special section of memory. |
It appears we are talking past each other. 🙂 Sorry, I should have been clearer which of my suggestions apply to the current situation where storage in sleep memory for persistence across deep sleep is not implemented yet, and which to the future situation where it is.
I agree with that goal. But I claim it is not what your code does. In order to stop speculating, I just tried it on a Feather S2: code.py: import time
import alarm
import supervisor
print('waking in code.py')
supervisor.set_next_code_file('other.py', sticky_on_success=False, sticky_on_error=True)
alarm.exit_and_deep_sleep_until_alarms(alarm.time.TimeAlarm(monotonic_time=time.monotonic() + 5)) other.py: import time
import alarm
print('waking in other.py')
alarm.exit_and_deep_sleep_until_alarms(alarm.time.TimeAlarm(monotonic_time=time.monotonic() + 5)) Actual result:
i.e. Expected result in the current situation (no sleep memory):
i.e. Expected result in the future situation with sleep memory:
i.e. |
This is a prototype implementation of #1084. Feature set and implementation details to be discussed.