-
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
Update task notification scheduler suspension usage #982
Update task notification scheduler suspension usage #982
Conversation
371657e
to
0fe4f0f
Compare
This commit updates the CMock unit tests according to the changes introduced to FreeRTOS/FreeRTOS-Kernel#982.
Previously ulTaskGenericNotifyTake() and xTaskGenericNotifyWait() would suspend the scheduler while inside a critical section. This commit changes the order by wrapping the critical sections in a scheduler suspension block. This logic is more inuitive and allows the SMP scheduler suspension logic to be simplified.
0fe4f0f
to
8cd19b4
Compare
@chinglee-iot I've updated the CMock unit tests as well. PTAL. |
tasks.c
Outdated
/* This must never be called from inside a critical section */ | ||
configASSERT( portGET_CRITICAL_NESTING_COUNT() == 0 ); |
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.
Is this change alright? I know some ports such as the ARM_CRx_No_GIC push the critical nesting count as part of the task context:
/* Push the critical nesting count. */
LDR R2, ulCriticalNestingConst
LDR R1, [R2]
PUSH {R1}
I'm worried that this change might be a breaking change for some ports/applications and was hoping for a deeper look into this PR from you two
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.
Using portGET_CRITICAL_NESTING_COUNT() here is okay to me. Sharing my observation here.
Critical nesting count should only be modified in critical section and context switch inside a critical section is not allowed in SMP. Use the following scenarios for discussion:
- portGET_CRITICAL_NESTING_COUNT() is greater than 1. This task is in a critical section and can read or update the critical nesting count without problem.
- portGET_CRITICAL_NESTING_COUNT() is 0. The task A may get preempted by task B while reading critical nesting count. Critical nesting count will be restore to 0 when the task B left critical section.
07cb29d
This commit updates the CMock unit tests according to the changes introduced to FreeRTOS/FreeRTOS-Kernel#982. Co-authored-by: chinglee-iot <[email protected]> Co-authored-by: Rahul Kar <[email protected]>
* Prevent potential NULL pointer access when scheduler is not running
Quality Gate passedThe SonarCloud Quality Gate passed, but some issues were introduced. 2 New issues |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #982 +/- ##
==========================================
- Coverage 93.55% 93.52% -0.03%
==========================================
Files 6 6
Lines 3197 3199 +2
Branches 887 889 +2
==========================================
+ Hits 2991 2992 +1
Misses 92 92
- Partials 114 115 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
* Update task notification scheduler suspension Previously ulTaskGenericNotifyTake() and xTaskGenericNotifyWait() would suspend the scheduler while inside a critical section. This commit changes the order by wrapping the critical sections in a scheduler suspension block. This logic is more inuitive and allows the SMP scheduler suspension logic to be simplified. * tasks.c: Fix typo * Use a complete sentence in comment * Check portGET_CRITICAL_NESTING_COUNT when scheduler is running * Prevent potential NULL pointer access when scheduler is not running --------- Co-authored-by: Paul Bartell <[email protected]> Co-authored-by: chinglee-iot <[email protected]> Co-authored-by: Ching-Hsin Lee <[email protected]>
* Add reg tests for CORTEX_MPU_M3_NUCLEO_L152RE Signed-off-by: Gaurav Aggarwal <[email protected]> Co-authored-by: kar-rahul-aws <[email protected]>
Description
#612 fixed an issue with
ulTaskGenericNotifyTake()
andxTaskGenericNotifyWait()
being non deterministic by ensuring that those functions callprvAddCurrentTaskToDelayedList()
while the scheduler was suspended. The merged fix would suspend the scheduler while still in a critical section, then exit the critical section while the scheduler was suspended:The method above technically works but is a bit unintuitive due to interleaving critical sections and scheduler suspension.
This PR updates the behavior described above by wrapping the critical section in a scheduler suspension block:
This method is more intuitive. As an added bonus, it also allows the SMP implementation of
vTaskSuspendAll()
to be simplified (as we can assume thevTaskSuspendAll()
is now never called in a critical section). As such, an extra assert has been added tovTaskSuspendAll()
to ensure that it is never called in a critical section.Related Issue
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.