Skip to content

Fix SMP task self void run state change #984

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

Conversation

chinglee-iot
Copy link
Member

@chinglee-iot chinglee-iot commented Feb 6, 2024

Description

PRs #958 and #959 introduced a problem - when a task attempts to delete/suspend a task running on another core, there is a time window in which the task being deleted or suspended can take an action which puts it back on the ready list, thereby nullifying the delete/suspend operation.

The following example explains the problem:

/* TaskA, running on core0, deletes taskB running on core1. */
void vTaskA( void * params )
{
    vTaskSuspend( task B );
    ...
}

void vTaskB( void * params )
{
    /* Task B was at this point when it was deleted. */

    /* Task B does an action (like calling xQueueReceive) which puts the
     * task on ready/state/event list. The correct implementation of vTaskDelete
     * must ensure that xQueueReceive is not be called after the task has been
     * deleted. */
    xQueueReceive( ... );
}

The root cause of the problem is that the task being deleted/suspended is evicted from the core after exiting the critical section. The task can put itself back on the ready list after we exit the critical section and before we evict it. This PR fixes the problem by evicting the task from within the critical section.

Test Steps

Before this PR, there are errors when running RP2040 standard SMP full demo.

FreeRTOS SMP on both cores:
 Starting tests:
  - Interrupt Queue
  - Blocking Queue
  - Block Time
  - Counting Semaphore
  - Generic Queue
  - Recursive Mutex
  - Semaphore
  - Math
  - Timer
  - Queue Overwrite
  - Event Group
  - Interrupt Semaphore
  - Task Notify
  - Register
  - Death
Iterations: 2; Errors now 00000001
Iterations: 3; Errors now 00001011
Iterations: 4; Errors now 000011d1

After the PR, there are no errors.

Checklist:

Related Issue

#958, #959

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

* Request a task to yield after been suspended or deleted to prevent
  this task puts itself back to another list
@chinglee-iot chinglee-iot requested a review from a team as a code owner February 6, 2024 10:25
@chinglee-iot chinglee-iot changed the title Fix task self void run state change Fix SMP task self void run state change Feb 6, 2024
Copy link

sonarqubecloud bot commented Feb 6, 2024

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@chinglee-iot chinglee-iot merged commit 57a5ed7 into FreeRTOS:main Feb 6, 2024
laroche pushed a commit to laroche/FreeRTOS-Kernel that referenced this pull request Apr 18, 2024
Set configMAX_SYSCALL_INTERRUPT_PRIORITY to 4 instead of 5 to avoid hitting the assert in `Source/portable/GCC/ARM_CM3/port.c` (`configASSERT( ( configMAX_SYSCALL_INTERRUPT_PRIORITY & 0x1U ) == 0U ); `)
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