-
Notifications
You must be signed in to change notification settings - Fork 163
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
[RFC] Add priority queues #925
base: dev/IPv6_integration
Are you sure you want to change the base?
Conversation
This enables strict priority based scheduling of packets within the stack. The user can define a socket/packet priority mapping for each queue. This allows certain high priority traffic to overtake packets or low priority traffic to fill the rest of the bandwidth.
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.
Hello @go2sh,
This is a very interesting prospect/suggestion.
While we discuss this PR with our team, I have an initial review with a couple of questions/concerns.
Thanks for taking the time to contribute to FreeRTOS+TCP.
-Aniruddha
|
||
#ifndef ipconfigPACKET_PRIORITY_MAPPING | ||
#if ipconfigPACKET_PRIORITIES == 8 && ipconfigEVENT_QUEUES == 3 | ||
#define ipconfigPACKET_PRIORITY_MAPPING { 0, 1, 1, 1, 2, 2, 2, 2, } |
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.
Just trying to understand this scheme here. Please do correct me if I am wrong.
All messages with priority 0 will be added to Queue 0.
And all messages with priority 1-3 will be added to Queue 1.
And all messages with priority 4-7 will be added to Queue 2.
Is that right?
If so, then what is the point of having 8 different priorites if you just have 3 queues?
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.
The idea is based on the current linux implementation, where tc-prio has 3 fifos. The 8 comes from the size of the vlan pcp which has 3 bits so 8 priorities. I do hw mappings inside of the driver and add vlan tags with the priority.
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.
Could you please add a bit of comment about the solution here? It is confusing to see 3 queues, and 8 different priorities.
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.
Add added a big comment below. I will add comment in the code as well.
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.
Wouldn't it be better to have the number of priorities and the number queues to be equal in the default configuration (if we are keeping a default mapping), to avoid users getting confused about packets with different priorites getting into the same queue (depending on the mapping) and processed together regardless of their actual priorities.
BaseType_t xQueue = ipconfigEVENT_QUEUES - 1; | ||
|
||
if( ( pxEvent->eEventType == eNetworkRxEvent ) || ( pxEvent->eEventType == eNetworkTxEvent ) || ( pxEvent->eEventType == eStackTxEvent ) ) | ||
{ | ||
NetworkBufferDescriptor_t * pxBuffer = ( NetworkBufferDescriptor_t * ) pxEvent->pvData; | ||
xQueue = xQueueMapping[ pxBuffer->ucPriority ]; | ||
} | ||
|
||
xReturn = xQueueSendToBack( xNetworkEventQueues[ xQueue ], pxEvent, uxUseTimeout ); |
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.
Does this mean that all non-data-related events (like a eNetworkDown
event) are highest priority and will be processed first?
I am not sure whether that will cause any unforeseen race conditions... It should not... But I am still thinking about it :)
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.
Exactly. Initially I thought to flush the other queues but that is not possible. , since there might be other interfaces.
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.
Hi @go2sh, this looks like a useful addition: priorities. It is a good idea to use TaskNotify in combination with uxQueueMessagesWaiting()
.
Do you have an application that needs priorities? I am curious to hear how it works for you, with and without multiple queues.
As I write here below, eNetworkRxEvent
packets have just arrived in the interface, and they do not have a specific priority. So you don't have to test it, just let them travel with the highest priority in order to avoid congestion.
Thank you very much for this contribution.
Hein
#if ipconfigEVENT_QUEUES > 1 | ||
BaseType_t xQueue = ipconfigEVENT_QUEUES - 1; | ||
|
||
if( ( pxEvent->eEventType == eNetworkRxEvent ) || ( pxEvent->eEventType == eNetworkTxEvent ) || ( pxEvent->eEventType == eStackTxEvent ) ) |
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.
When pxEvent->eEventType == eNetworkRxEvent
, I think that pxBuffer->ucPriority
always has its default value of ipconfigPACKET_PRIORITY_DEFAULT
. It was assigned in BufferAllocation_x.c
Here, the packet has just been received by NetworkInterface.c, and it has not been matched with a receiving socket yet. I think it is useless to test its priority.
In general it is good to give a higher priority to incoming traffic in order to avoid congestion.
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.
See the big comment below. The incoming priority in my case is set by the NetworkInterface based on the VLAN PCP field.
|
||
#ifndef ipconfigPACKET_PRIORITY_MAPPING | ||
#if ipconfigPACKET_PRIORITIES == 8 && ipconfigEVENT_QUEUES == 3 | ||
#define ipconfigPACKET_PRIORITY_MAPPING { 0, 1, 1, 1, 2, 2, 2, 2, } |
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.
Could you please add a bit of comment about the solution here? It is confusing to see 3 queues, and 8 different priorities.
A general comment about priorities and queues:
I don't mind the numbers at all. A just wanted to choose a reasonable default, since anybody can overwrite it relatively easy. A comment on the application: I work at Infineon and I port FreeRTOS+TCP on our TC3 and TC4 microcontroller. These are rather powerful devices with a lot of cores (up to 6), a lot of SRAM (a few MB) and up to 5G Ethernet MACs with 8 DMA and 8 Hardware Queues each for RX and TX). We run relativly complex applications with multiple tasks working on network traffic with diffrent application domains. From SOTA, CAN Tunneling, Service Handling (like SOMEIP or MQTT) and real time data like Audio and Video (or Radar) streams. These patch is a first step off removing some bottlenecks with the stack and to fulfill the real-time requirements. As an concrete example: I have an app which runs some low priority Debug Instrumentation, an MQTT Client and some Audio Processing. Since the system has a lot of ram, the number of NetworkBuffers is high (eg. 128). This lead to the instrumentaion filling up the single queue and the audio task had no chance of meeting the real time latency requirement. With this multiple queue approach: The instrumentation runs in the lowest priority and gets rest of the bandwith. Its no problem if a packets waits a bit. The overall bandwidth of the system is sufficient. The MQTT traffic runs in the middle priority and the audio and timesync traffic in the highest. (Only a few 100 kBit/s but very latency sensitive). With this multiple queues approach, I don't need take any measures within the software to meet my real-time goals. I hope this makes this a bit more clear. :) |
One more comment regarding: RX Events. The problem why I also added the priorities for RX events is the following: Think about a lot of NetworkBuffers and your IP Tasks start blocking until a descriptor entry is free inside the descriptor table. During that time no RX packet handling will happen as the IP task is blocking. The high priority queue makes it possible, that an high priority packet is processed a bit earlier than otherwise. The ideal solution would be to split RX and TX Packet processing. Then no extra queues for RX would be needed, as the traffic comes in prioritized already. |
Thanks Christoph for creating the PR. |
|
That is my final step of my TSN chain. I would see this functionality as part of the network interface. In my case, the driver checks the NetworkBuffer ucPriority and has a custom mapping array for mapping the packets to the different DMA queues. But each devices does it differently and I know that alot of other devices support multiple hw queues, which are already part of FreeRTOS+TCP. |
Add priority queues.
Description
This PR adds priorities to socket and packets and multiple event queues to handle packets. This change enables multiple things with in the time sensitive networking space:
Test Steps
Enable the feature via ipconfigPRIORITIES && ipconfigEVENT_QUEUES and add two udp sockets. The first socket gets a higher priority (e.g. 5). The second socket sends a lot of packets and the first socket afterwards one. This packet should overtake some of the packets of the second socket.
Checklist:
Related Issue
#894
TODOs
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.