-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Use placement new for ETSTimer - no heap fragmentation #6164
Conversation
…mantics unchanged.
@igrr Could you kindly review the proposed change, please? |
Why don't you use a plain |
I'm trying to stick as closely as possible to how it worked before, constructing and destructing ETSTimer objects - the pointer is used as predicate for armed/disarmed just like before. Should ETSTimer ever have a constructor/destructor, the object lifetime is unaffected - making struct ETSTimer an immediate member, that's different. |
The change looks correct, but I agree with @d-a-v that making ETSTimer struct a member of the ticker object would lead to simpler code. The pointer checks in attach/detach can then be removed. |
I agree with the idea, but I think what should be done is:
|
@devyte I have to respectfully reply that I don't care about a change for v3.0.0 but that I'm working on something for right now. That said, please consider: Please keep in mind, this PR is there to remove polling for timeouts in Scheduler. |
@doknet @hreintke @devyte @igrr @earlephilhower @anyone About this:
I must understand this PR is aimed at removing the recent recurrent scheduled function list called at every I would like to explain why I need this feature and why ticker is not sufficient. I'm currently trying to find my way to add pure ethernet drivers in this core : I have some ethernet shields to work with based on W5100 without exposed interrupt pin (even if W5100 itself has one). With that, or given the number of gpio (users may not wish to use the interrupt pin if possible), or given the fact current Ethernet library does not use it (or show me I didn't find): a function like One could argue: what's the issue with that, just put your My current issues:
I am currently seeing two solutions
I'm open to any proposal. I would like to show you what os_timer would look like, frequently called too: |
Note that this is the FreeRTOS timer. It is unrelated to the os_timer (aka ETSTimer) implemented in the non-OS SDK. (Not claiming that ETSTimer doesn't have overhead, just clearing this up to avoid confusion) |
I cannot quite follow the claims made about Ticker, and if what I understand was true, there's still no problem, as the Schedule run_scheduled_functions only runs in CONT anyway.
|
Yes you are right. You missed the part where I claim I need scheduled functions be run also at |
We're drifting off the topic of this PR. |
@d-a-v We both want your work to stay in place! What I am trying to do/prove is using Ticker to schedule timed functions instead of using the polling approach. When you say that this conflicts with execution of said scheduled functions does not happen during yield, in the case that the Ticker schedules them when their time case come, confused me - is there something about the Ticker that prevents it from executing during yield? See, if you substitute the
the test still completes successfully. Doesn't this indicate that yield() indeed lets both the Ticker execute and run_scheduled_functions() do it's job? So if this really works as it seems to me, it's a minor thing to If this makes sense, we need to figure out whether to allocate the Tickers on the heap, or in a prepared array, again using placement new(), if I can work out the reservations against that everyone seems to have. |
@devyte Naturally just my opinion, but I see absolutely nothing wrong with placement new. It expresses quite succinctly that what was going on before is still unchanged, namely, an instance of ETSTimer is constructed, and destructed later. The compiler should actually generate code that is superior to supplying an immediate ETSTimer member in the Timer class, because in common interpretation of the C++ standard, this POD class will zero-initialize during construction. A detach() - attach*() cycle may easily rely on this initialization, if os_timer_setfn() and os_timer_arm() should rely on a freshly constructed ETSTimer, that's zeroed out. |
How is ticker going to call a function in cont stack while an external library is busy waiting on network ?
output:
|
void* instead of uint32_t - fixes x86_64 server compiles.
Core "Host tests" require some fixes - use of uint32_t for pointer type was incorrect anyway. |
@igrr @devyte @d-a-v Next question: I have a choice of either adding ICACHE_RAM_ATTR to Ticker::once_ms (and assorted further members) or using the upgraded new "cont scheduler" to allow ISRs to safely schedule timed functions. The latter approach causes an additional scheduler roundtrip delay for timed functions... Which is preferable from your POV? |
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.
Much cleaner! Only minor comments now.
…operations - reduce number of code spots to one.
When using many Ticker objects, possible in a container, each allocates an ETSTimer object on the heap. On an embedded system, this is poor practice, this PR changes this, without affecting constructor/destructor effects of ETSTimer.