-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
POSIX Simulator: Handle pthread
s not created by FreeRTOS differently
#1223
POSIX Simulator: Handle pthread
s not created by FreeRTOS differently
#1223
Conversation
pthread_sigmask
on pthread
s not created by FreeRTOSpthread
s not created by FreeRTOS differently
6f630dc
to
aa8fcad
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1223 +/- ##
==========================================
- Coverage 91.64% 91.61% -0.03%
==========================================
Files 6 6
Lines 3254 3257 +3
Branches 903 901 -2
==========================================
+ Hits 2982 2984 +2
Misses 132 132
- Partials 140 141 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
pthread
s not created by FreeRTOS differentlypthread
s not created by FreeRTOS differently
The aim of the POSIX port is to aid development of FreeRTOS applications. Why would you want to create native pthreads in a FreeRTOS application? |
A simulator program may need other threads to simulate peripheral hardware. For example I need another thread to run my virtual display window that simulates my hardware display. My main FreeRTOS application does not need to know about my display simulator. On some platforms (I'm experimenting with iOS) the system frameworks create several threads at startup so there are already other threads existing when user code is run. Running my FreeRTOS code on iOS is useful to me as it allows me to easily prototype peripherals like touch screens and HDMI output without bringing up the target hardware (which we haven't received yet). The current FreeRTOS implementation eventually causes all other threads to lock up. |
We’re also using separate (non-FreeRTOS) pthreads to simulate various interrupt sources, and this change aligns well with a pull request we plan to submit. In our case, the interrupt pthreads call different FreeRTOS ISR APIs to inject data into the FreeRTOS application. For this to work, we’ve added an additional port mutex layer to prevent ISR APIs from being executed while FreeRTOS is in a critical section. It would be great to see this patch merged in some form so that we can rebase our planned pull request onto it. |
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 is a great change, and its clear that other users find it valuable as well. Thank you! I just had some minor comments regarding early returns - mainly just to make static analyzers happy since MISRA C will flag it.
Quality Gate passedIssues Measures |
Hmm a check is failing but it doesn't seem related to your change... I will look into it. |
For now, we will merge this as there is no action needed on this PR. Thanks @johnboiles! |
Thanks for getting this in there! |
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Are leak checks a port of the CI? After switching to
Edit: Seems to only happen in one of our test suites so I think it's something on our end. |
Thank you for sharing! Which tool are you using for finding these leaks? |
Avoid calling
pthread_sigmask
onpthread
s not created by FreeRTOS. Also avoids waiting forever onvPortEndScheduler
if that's called from a non-FreeRTOS thread.Description
This PR modifies the behavior of the FreeRTOS POSIX simulator. The tick handler (via
sigaction
) might happen on any thread in the current process. This can cause hangs with non-FreeRTOS threads (because they can get hung whenprvSuspendSelf
is called on them.Test Steps
Run this program against the
main
branch, notice that it hangs on shutdown.Now run it again with this change and notice that it shuts down cleanly.
Checklist:
I still need to read up on the test suite. Looking for directional feedback first.