Skip to content
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

Avoid critical sections where possible #1063

Merged

Conversation

htibosch
Copy link
Contributor

Description

Recently, there was a request in #1058: "Please document how the synchronisation works".
This was about the socket's List_t that stores UDP packets, called xWaitingPacketsList.

I showed that the addition and removal of packets is protected by a critical section, and/or a suspended scheduler.
Non protected access is only seen when listCURRENT_LIST_LENGTH() is called. That is OK because a variable of type UBaseType_t is read.

These are the proposed changes:

In FreeRTOS_UDP_IPv4.c and in FreeRTOS_UDP_IPv6.c :

 vTaskSuspendAll();
 {
-    taskENTER_CRITICAL();
-    {
        /* Add the network packet to the list of packets to be
         * processed by the socket. */
        vListInsertEnd( &( pxSocket->u.xUDP.xWaitingPacketsList ), &( pxNetworkBuffer->xBufferListItem ) );
-    }
-    taskEXIT_CRITICAL();
 }
( void ) xTaskResumeAll();

And here in FreeRTOS_Sockets.c :

-    taskENTER_CRITICAL();
+    vTaskSuspendAll();
     {
         ( void ) uxListRemove( &( pxNetworkBuffer->xBufferListItem ) );
     }
-    taskEXIT_CRITICAL();
+    ( void ) xTaskResumeAll();

Test Steps

I tested the changes by using ncat: I started multiple instances and had it exchange UDP packets with the DUT. I added stress by running iperf3 at the same time.

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

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

@htibosch htibosch requested a review from a team as a code owner December 13, 2023 05:04
tony-josi-aws
tony-josi-aws previously approved these changes Dec 19, 2023
@tony-josi-aws tony-josi-aws merged commit af07ccf into FreeRTOS:main Jan 2, 2024
10 checks passed
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.

5 participants