-
Notifications
You must be signed in to change notification settings - Fork 13.3k
scheduled functions: calls from yield are now optional #6158
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
@d-a-v Could yield - opportunistic_yield() - be called in run_scheduled_functions() to stop the wdt from firing if there are many scheduled items? |
@dok-net done |
@d-a-v @hreintke Besides the portability (ESP32, FreeRTOS on ESP8266) question that's keeping me engaged, I would like to pose a more obvious question: what's so wrong with the SDK scheduler that we're doing this Scheduler work in the first place? From a performance point of view, iterating the list of timeouts (esp8266::polledTimeout) over and over is no advantage either, and if there is nothing in the SDK scheduler supporting timed tasks, then this can be done as a wrapper around the user code just as well. What I am saying is, is this just a work-around for some itch that gets thrown out once the Non-OS SDK becomes unavailable? But aren't we throwing performance out the window with this Schedule scheduler? If everyone/anyone starts using it, things don't look shiny, I for one have reservations about the performance for EspSoftwareSerial, once a few device drivers etc. start inserting their timed calls into the ring buffer. |
@dok-net : I think portability between ESP32, FreeRTOS ESP826 (and NONOS ESP8266 ?) is preferable. |
@dok-net if by sdk scheduler you mean the sdk tasks, then the problem is that their code executes in the SYS context, and hence the user code can't be long runnig, blocking, can't call yield or delay, etc. The Ticker for example runs cbs in that way, and so suffers from those limitations. |
I originally needed these regular scheduled functions because of ethernet. I could use a So I needed We ended up with this linked list of recurrent function mixed with non-recurrent functions which, you seem to say, brings a performance penalty. I originally was not thinking they would be that intensively used, but only for some calls sometimes (using lightweight polledtimeout lib). @dok-net and @hreintke you state there is a performance penalty because you are intensively using them. Can you be more specifc ? How many functions on each Regarding multi-thread on ESP32 or the new single core version, these beasts have at least 512KB ram while we have 50KB. They can afford a stack per task while we can't (well, esp8266-rtos-sdk can and I wonder how many tasks can be spawned without running out of memory). These recurrent scheduled functions are a useful addition (not recurrent version was already there). How could it be improved regarding the performance penalty ?
|
@devyte It's great that you mention Ticker. I was beginning to plan in this direction, like the following: determine which delayed functions will not run during the next invocation of run_scheduled_functions and set them up with the Ticker INSTEAD of in the queue. Once the Ticker finds a function "runnable", the Ticker CB would insert the function in the scheduler queue. After returning true, the scheduler would return the function object to the Ticker, and so forth. Is this possible without violating some system constraint? About my performance wishes: it would be great to have enough performance AND precision to schedule, at up to 8.6µs resolution (1/115200bps serial), the line signal changes of bit output. Or anything below that, my algorithm determines the necessary signal inversions and could fall back to change/live-lock for too high signal rates. Probably that's asking to much from coop multitasking, but I'd like to try it. |
@d-a-v @devyte @dok-net For the functions that need to run/be scheduled on regular intervals there is already the possibility to use the Ticker'
For higher precision, I think etstimer provides microscecond precision, not yet used in Ticker. |
Because the code is executed as though it were part of the loop, high timing precision between loops can't be assured. Precision depends on the application: consider wifimanager, where the execution path is completely hijacked for an extended period of time before returning. Consider File streaming, where the execution path doesn't return until the File is done. The precision in CONT depends on the frequency of loop calls and now on the frequency of calls to yield/delay. About performance, if I understand correctly, the issue is that currently we're essentially polling the entire queue to find what to run, and that is done on every loop. Because the approach is polled, there is high CPU load. I see the following possibilities, including the suggestion above:
|
@devyte I was typing the "wish" for µs between appointments - it's impossible for the obvious reasons you've restated for me. It's good that everyone is moving the direction, that on each yield or loop polling all the timeout objects, has a noticeable impact. In the case of the circular queue that I am proposing, there's even a copy involved on each round-trip! |
@hreintke This PR restores legacy behavior by default