-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
fix(freertos): Made select function non-blocking on Linux target (IDFGH-13569) #14457
Conversation
👋 Hello snake-4, we appreciate your contribution to this project! 📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more. 🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project. Click to see more instructions ...
Review and merge process you can expect ...
|
12b141f
to
1cc8e5c
Compare
1cc8e5c
to
9845b06
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.
Hi @snake-4, this looks like a great improvement!
The only question I have here is how did you determine the number of 10 ticks for waiting? Is there a reasoning why it's exactly 10 or could it be something else, too?
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.
LGTM.
There's no specific reason why it's 10 but it has to be at least 1 tick to let the FreeRTOS scheduler know that lower priority tasks may run. Although, at 1 tick delay, it would take up 50% of the simulator's CPU time (not the actual host CPU time). A delay of 10 ticks seemed like a good trade-off, considering the select timeout resolution is affected by it as well. I'll refer to threads that are not scheduled by the FreeRTOS scheduler as raw threads and FreeRTOS tasks as just tasks below. The reason why polling is used is because while it is possible to signal raw threads from tasks (using pthread), other way around is not possible as a FreeRTOS semaphore would have to be used. The simulator does not expect the FreeRTOS APIs to be called from raw threads and doing so will cause issues as mentioned here. A method for achieving what I've said above could be done by modifying the FreeRTOS scheduler's internal state to immediately schedule the task waiting on IO upon completion, but this approach would require modifying the simulator's source code. |
As per my original post, all blocking host system calls (except select) will be considered as "work" by the FreeRTOS scheduler. This includes |
The select function wrapper was rewritten to be non-blocking on Linux systems, as it was stealing all the CPU time from lower priority tasks when called from a higher priority task. This is because the FreeRTOS scheduler does not know that the task thread is sleeping during the system call. This issue manifests all "slow" system calls on the Linux target, but handling the case of select fixes the problems for most ESP-IDF components. The FreeRTOS POSIX port documentation lists this as a known issue, so user code is responsible handling this case if other system calls are used, even if unknowingly. This closes GH issue espressif#14395 "select() blocks the FreeRTOS scheduler on Linux target"
9845b06
to
8a39db3
Compare
Thanks for explaining 👍 and for the updates. will add this PR to our internal pipeline to be merged it to master (after all internal checks pass, which may take some time) |
The select function wrapper was rewritten to be non-blocking on Linux systems, as it was stealing all the CPU time from lower priority tasks when called from a higher priority task. This is because the FreeRTOS scheduler does not know that the task thread is sleeping during the system call.
This issue manifests all "slow" system calls on the Linux target, but handling the case of select fixes the problems for most ESP-IDF components.
The FreeRTOS POSIX port documentation lists this as a known issue, so user code is responsible handling this case if other system calls are used, even if unknowingly.
This closes the GH issue #14395 "select() blocks the FreeRTOS scheduler on Linux target".
Additional Notes