Skip to content

POSIX Simulator: Assert if vPortYield called from a non-FreeRTOS thread #1247

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

Merged
merged 1 commit into from
Feb 13, 2025

Conversation

johnboiles
Copy link
Contributor

Assert if vPortYield called from a non-FreeRTOS thread

Description

As requested by @aggarg here I'm adding an assert to obviously crash if vPortYield gets called from a non-FreeRTOS thread. This avoids intermittent freezes depending on the state of pxCurrentTCB where FreeRTOS may suspend the non-FreeRTOS thread (and never un-suspend it). Instead, with this PR, the program crashes, making the underlying issue more easily findable & fixable.

Test Steps

Call xTaskCreate outside of a FreeRTOS thread after the scheduler is started. Sometimes this will lead to the calling thread getting suspended forever.

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

#1237

@johnboiles johnboiles requested a review from a team as a code owner February 12, 2025 18:41
Copy link

@aggarg
Copy link
Member

aggarg commented Feb 13, 2025

Thank you for your contribution @johnboiles !

@johnboiles
Copy link
Contributor Author

I've been running this in our CI today. It exposed one spot where we were inadvertently calling xTimerStop from outside of FreeRTOS! Otherwise it's been working fine!

@aggarg aggarg merged commit 15ec8b8 into FreeRTOS:main Feb 13, 2025
17 checks passed
@johnboiles johnboiles deleted the posix-assert-vPortYield branch February 13, 2025 05:26
@johnboiles
Copy link
Contributor Author

johnboiles commented Feb 14, 2025

I got a couple of Linux CI crashes related to this. But I'm not sure how this is possible. The trace clearly has prvWaitForStart which always calls prvMarkAsFreeRTOSThread.

#20 0x000055acfefe09a3 in Catch::handleSignal (sig=6) at /home/runner/work/embedded-app/embedded-app/lib/Catch2/catch_amalgamated.cpp:4205
#21 <signal handler called>
#22 __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:44
#23 __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
#24 __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#25 0x00007f5233e4527e in __GI_raise (sig=6) at ../sysdeps/posix/raise.c:26
#26 0x000055acff12eb65 in vAssertCalled (pcFileName=0x55acff21a158 "/home/runner/work/embedded-app/embedded-app/lib/Simulator/stubs/freertos-posix/src/Source/portable/ThirdParty/GCC/Posix/port.c", ulLine=399) at /home/runner/work/embedded-app/embedded-app/lib/Simulator/stubs/freertos-posix/src/libfreertos.c:128
#27 0x000055acff126802 in vPortYield () at /home/runner/work/embedded-app/embedded-app/lib/Simulator/stubs/freertos-posix/src/Source/portable/ThirdParty/GCC/Posix/port.c:399
#28 0x000055acff12a759 in xTaskResumeAll () at /home/runner/work/embedded-app/embedded-app/lib/Simulator/stubs/freertos-posix/src/Source/tasks.c:2267
#29 0x000055acff12c014 in prvIdleTask (pvParameters=0x0) at /home/runner/work/embedded-app/embedded-app/lib/Simulator/stubs/freertos-posix/src/Source/tasks.c:3526
#30 0x000055acff126b32 in prvWaitForStart (pvParams=0x7f522c048168) at /home/runner/work/embedded-app/embedded-app/lib/Simulator/stubs/freertos-posix/src/Source/portable/ThirdParty/GCC/Posix/port.c:564
#31 0x00007f5233e9caa4 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:447
#32 0x00007f5233f29c3c in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants