-
Notifications
You must be signed in to change notification settings - Fork 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
events: Adopt osEventFlags from RTX 5 #4571
Conversation
This provides the correct binary semaphore behaviour that was expected by the equeue layer, removes concerns around semaphore overflow, and reduces the number of spurious wakeups which may save a bit of power. This also fixes some issues we were seeing around the RTX 5 changes to semaphore behaviour.
I have made some initial tests and it looks good. The event flag solution is a good one. Maybe a minor improvement could be to add a "equeue_sema_wait" after the while loop to dispatch the pending events. This would clear the event flag indicating that there is no more callbacks at this moment. When the "wait for event" code is reached further down in the function, the "equeue_sema_wait" will hang until the deadline is reached or a new event was added. If not, it is likely that the wait call will return immediately and one addition loop is performed. Of course this is not really a problem. |
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.
Event flags will be used for TCP/UDP sockets as well in mbed-os. Should we have fix defines for flags (for each module) in mbed-os common file instead of using 1?
@pan-, correct me if I'm wrong, but if an event comes in before the @tomasfrisbergublox, unfortunately an additional @deepikabhavnani, One big benefit of the osEventFlags object is that each set of flags is standalone, so we don't need to worry about flag conflicts between modules. An enum may be useful if we have more events, but since the event queue only needs a single event I think 1 is fine. |
@geky I'm not sure of the behaviour, is the flag cleared before or after the wait happens ? If it is before and the flag is set then does wait returns immediately or does it actually wait ? |
The osEventFlagsWait is similar to the osSemaphoreWait, the flags are cleared atomically if the condition is matched in osEventFlagsWait. Here's where the logic resides in RTX: If the flags are already set when osEventFlagsWait is entered, the function returns immediately: With RTX 5, boolean osEventFlags and binary semaphores should be interchangeable. |
@geky Thanks for the precision. LGTM. |
@geky shall we wait with this one for EventsFlag C++ that is already in the PR queue ? |
Nah, there's no reason for this layer to be C++. Adding another layer of indirection will just make this layer more instable. I've also been meaning to move the ticker code over to the C hal now that 64-bit tickers are in. |
For the HAL it makes sense, the API is not supposed to change and it is managed by the mbed OS team but is it the same for the RTOS ? In many aspects it is a 3rd party component; can we guarantee that RTOS APIs won't change ? |
I noticed that lot of ppl liked EventsFlag proposal, therefore I considered this as a duplicate (noting this is C++ world, not HAL) plus C++ should simplify usage of events flags, we can see how much boilerplate is needed in this patch. . By moving to C++ API, we would keep it consistent (a reason in another paragraph below).
We can't. We experienced it with the last update, it is subject to change, however with our C++, we keep backward compatibility. It is fine as it is here, I had that question just to make it more buletproof for the future and if we all are on the same page that events flag C++ is a proposal we go for. |
My above comment is just how it could be, but we dont have yet C++, this is an important fix for wifi. Thus we can always refactor this (I would create a tracking issue then to remember if we agree). Is this ready for integration? Any tests run? |
My thoughts is we should just move forward as is, the c++ api is currently in flux and might change, and @0xc0170 is right we can move forward for now independently of the c++ semaphore/event flags work. I'm not opposed to switching back to the c++ api once it's in and stable, although adopting the c++ apis doesn't help much unless we do the same accross the entire codebase: b793a3f From my point of view this can go in as is. I ran tests locally, should we kick off morph test? |
I think we're all on the same page and this pr should go in because the C++ EventFlag abstraction is not ready yet. Nonetheless the question of API stability remains what guarantees can be provided for the C and the C++ layer after the RTX update ? On the other hand, if the stability of both API is guaranteed then it should be indicated in the guidelines which API can be use: C++ or C++ and C. |
/morph test |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
retest uvisor |
This provides the correct binary semaphore behaviour that was expected by the equeue layer, removes concerns around semaphore overflow, and reduces the number of spurious wakeups which may save a bit of power.
This also fixes some issues we were seeing around the RTX 5 changes to semaphore behaviour.
related issue #4500
cc @pan-, @tomasfrisbergublox, @hesolium
Tests