Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Homepage FreeRTOS+ Products FreeRTOS Labs Integration Services Contact / Enquiries

Network Buffers Allocation Schemes
and their implication on CPU load and throughput performance

Summary Bullet Points

  • FreeRTOS+UDP has a very efficient zero copy architecture. Depending on the implementation of the embedded Ethernet peripheral driver, and the user's choice of API calling semantics, Ethernet packets can be passed by reference from the receiving DMA buffer, through the stack, all the way back to the transmitting DMA buffer.

  • Performance limiting factors:

    1. Reentrancy

      FreeRTOS+UDP is fully reentrant and thread aware, meaning the IP stack can be safely used by all the RTOS tasks simultaneously. The flexibility does however come with the small time penalty introduced by the message passing and context switching that is necessary to ensure accesses to the IP stack are serialised (happen in a controlled manner so as not to cause corruption).

    2. Buffer Allocation

      Data that is received by the embedded Ethernet (or other embedded networking) peripheral is placed into buffers that are pre-allocated by the IP stack. When the user sends a message the message contents are placed in a buffer that is allocated by the IP stack. Different buffer allocation schemes suite different embedded applications. FreeRTOS+UDP currently includes two buffer allocation schemes - each with different trade offs between simplicity, RAM usage efficiency, and performance. The two schemes are described on this page.

Buffer Allocation Schemes

The C source files that implement the buffer allocation schemes are located in the FreeRTOS-Plus/FreeRTOS-Plus-UDP/portable/BufferManagement directory. Only one scheme can be used at a time.

Scheme 1: Implemented by BufferAllocation_1.c

  • Ethernet buffer descriptors are statically allocated by the IP stack (at compile time).
  • Ethernet buffers are statically allocated by the embedded Ethernet peripheral driver (at compile time). This ensures the buffers can be aligned as required by the specific Ethernet hardware.

  • Fast run time performance.
  • Ethernet buffers can be allocated and freed from interrupts, allowing for more efficient embedded Ethernet peripheral drivers.
  • Inefficient use of RAM - all the buffers are the same size making BufferAllocation_1.c unsuitable for some RAM constrained embedded systems.
  • More complex to configure and tune than the scheme implemented by BufferAllocation_2.
  • Simpler to achieve any special buffer alignment requirements imposed by the embedded Ethernet peripheral DMA.
  • Requires support from the network interface driver (see the description bullet points above).

  • The ipconfigNUM_NETWORK_BUFFERS constant (defined in FreeRTOSIPConfig.h) defines the total number of available buffers.
  • The ipconfigNETWORK_MTU constant (defined in FreeRTOSIPConfig.h) defines the size of each Ethernet frame (the total size being the defined MTU size plus the number of bytes needed by the Ethernet header).

Scheme 2: Implemented by BufferAllocation_2.c

  • Ethernet buffer descriptors are statically allocated by the IP stack (at compile time). This allows the user to limit the total number of Ethernet frames that can exist at any time to prevent memory exhaustion.
  • Ethernet buffers of exactly the required size are dynamically allocated and freed as required.

  • Dynamic allocation results in slower run time performance when compared with the scheme implemented by BufferAllocation_1.c.
  • Ethernet buffers cannot be allocated and freed from interrupts, necessitating the use of deferred interrupt handling tasks in embedded Ethernet peripheral drivers.
  • Very efficient RAM usage - only the exact amount of RAM required is allocated making BufferAllocation_2.c particularly suited for RAM constrained small embedded systems.
  • Easier to configure and tune than the scheme implemented by BufferAllocation_1.

  • The ipconfigNUM_NETWORK_BUFFERS constant (defined in FreeRTOSIPConfig.h) defines the total number of available network buffer descriptors. The descriptors contain pointers to Ethernet buffers, but do not actually contain buffers themselves. Buffers are allocated as required.
  • Ethernet buffers are allocated from the FreeRTOS heap. To avoid memory fragmentation problems, BufferAllocation_2.c can only be used reliably with a memory allocation scheme that combines free blocks of heap memory (a coalescence algorithm). The FreeRTOS memory allocation scheme implemented in heap_4.c is suitable.
  • The IP stack will recover from an attempt to allocate a network buffer failing because there is too little heap memory. Such a failure will however result in the malloc failed hook function being called (if configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h).

[ Back to the top ]    [ About FreeRTOS ]    [ FreeRTOS+ Sitemap ]    [ Main FreeRTOS Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.