2 Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in
13 the documentation and/or other materials provided with the
15 * Neither the name of Intel Corporation nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 Quality of Service (QoS) Framework
32 ==================================
34 This chapter describes the DPDK Quality of Service (QoS) framework.
36 Packet Pipeline with QoS Support
37 --------------------------------
39 An example of a complex packet processing pipeline with QoS support is shown in the following figure.
41 .. _figure_pkt_proc_pipeline_qos:
43 .. figure:: img/pkt_proc_pipeline_qos.*
45 Complex Packet Processing Pipeline with QoS Support
48 This pipeline can be built using reusable DPDK software libraries.
49 The main blocks implementing QoS in this pipeline are: the policer, the dropper and the scheduler.
50 A functional description of each block is provided in the following table.
54 .. table:: Packet Processing Pipeline Implementing QoS
56 +---+------------------------+--------------------------------------------------------------------------------+
57 | # | Block | Functional Description |
59 +===+========================+================================================================================+
60 | 1 | Packet I/O RX & TX | Packet reception/ transmission from/to multiple NIC ports. Poll mode drivers |
61 | | | (PMDs) for Intel 1 GbE/10 GbE NICs. |
63 +---+------------------------+--------------------------------------------------------------------------------+
64 | 2 | Packet parser | Identify the protocol stack of the input packet. Check the integrity of the |
65 | | | packet headers. |
67 +---+------------------------+--------------------------------------------------------------------------------+
68 | 3 | Flow classification | Map the input packet to one of the known traffic flows. Exact match table |
69 | | | lookup using configurable hash function (jhash, CRC and so on) and bucket |
70 | | | logic to handle collisions. |
72 +---+------------------------+--------------------------------------------------------------------------------+
73 | 4 | Policer | Packet metering using srTCM (RFC 2697) or trTCM (RFC2698) algorithms. |
75 +---+------------------------+--------------------------------------------------------------------------------+
76 | 5 | Load Balancer | Distribute the input packets to the application workers. Provide uniform load |
77 | | | to each worker. Preserve the affinity of traffic flows to workers and the |
78 | | | packet order within each flow. |
80 +---+------------------------+--------------------------------------------------------------------------------+
81 | 6 | Worker threads | Placeholders for the customer specific application workload (for example, IP |
82 | | | stack and so on). |
84 +---+------------------------+--------------------------------------------------------------------------------+
85 | 7 | Dropper | Congestion management using the Random Early Detection (RED) algorithm |
86 | | | (specified by the Sally Floyd - Van Jacobson paper) or Weighted RED (WRED). |
87 | | | Drop packets based on the current scheduler queue load level and packet |
88 | | | priority. When congestion is experienced, lower priority packets are dropped |
91 +---+------------------------+--------------------------------------------------------------------------------+
92 | 8 | Hierarchical Scheduler | 5-level hierarchical scheduler (levels are: output port, subport, pipe, |
93 | | | traffic class and queue) with thousands (typically 64K) leaf nodes (queues). |
94 | | | Implements traffic shaping (for subport and pipe levels), strict priority |
95 | | | (for traffic class level) and Weighted Round Robin (WRR) (for queues within |
96 | | | each pipe traffic class). |
98 +---+------------------------+--------------------------------------------------------------------------------+
100 The infrastructure blocks used throughout the packet processing pipeline are listed in the following table.
104 .. table:: Infrastructure Blocks Used by the Packet Processing Pipeline
106 +---+-----------------------+-----------------------------------------------------------------------+
107 | # | Block | Functional Description |
109 +===+=======================+=======================================================================+
110 | 1 | Buffer manager | Support for global buffer pools and private per-thread buffer caches. |
112 +---+-----------------------+-----------------------------------------------------------------------+
113 | 2 | Queue manager | Support for message passing between pipeline blocks. |
115 +---+-----------------------+-----------------------------------------------------------------------+
116 | 3 | Power saving | Support for power saving during low activity periods. |
118 +---+-----------------------+-----------------------------------------------------------------------+
120 The mapping of pipeline blocks to CPU cores is configurable based on the performance level required by each specific application
121 and the set of features enabled for each block.
122 Some blocks might consume more than one CPU core (with each CPU core running a different instance of the same block on different input packets),
123 while several other blocks could be mapped to the same CPU core.
125 Hierarchical Scheduler
126 ----------------------
128 The hierarchical scheduler block, when present, usually sits on the TX side just before the transmission stage.
129 Its purpose is to prioritize the transmission of packets from different users and different traffic classes
130 according to the policy specified by the Service Level Agreements (SLAs) of each network node.
135 The hierarchical scheduler block is similar to the traffic manager block used by network processors
136 that typically implement per flow (or per group of flows) packet queuing and scheduling.
137 It typically acts like a buffer that is able to temporarily store a large number of packets just before their transmission (enqueue operation);
138 as the NIC TX is requesting more packets for transmission,
139 these packets are later on removed and handed over to the NIC TX with the packet selection logic observing the predefined SLAs (dequeue operation).
141 .. _figure_hier_sched_blk:
143 .. figure:: img/hier_sched_blk.*
145 Hierarchical Scheduler Block Internal Diagram
148 The hierarchical scheduler is optimized for a large number of packet queues.
149 When only a small number of queues are needed, message passing queues should be used instead of this block.
150 See `Worst Case Scenarios for Performance`_ for a more detailed discussion.
155 The scheduling hierarchy is shown in :numref:`figure_sched_hier_per_port`.
156 The first level of the hierarchy is the Ethernet TX port 1/10/40 GbE,
157 with subsequent hierarchy levels defined as subport, pipe, traffic class and queue.
159 Typically, each subport represents a predefined group of users, while each pipe represents an individual user/subscriber.
160 Each traffic class is the representation of a different traffic type with specific loss rate,
161 delay and jitter requirements, such as voice, video or data transfers.
162 Each queue hosts packets from one or multiple connections of the same type belonging to the same user.
164 .. _figure_sched_hier_per_port:
166 .. figure:: img/sched_hier_per_port.*
168 Scheduling Hierarchy per Port
171 The functionality of each hierarchical level is detailed in the following table.
175 .. table:: Port Scheduling Hierarchy
177 +---+--------------------+----------------------------+---------------------------------------------------------------+
178 | # | Level | Siblings per Parent | Functional Description |
180 +===+====================+============================+===============================================================+
181 | 1 | Port | - | #. Output Ethernet port 1/10/40 GbE. |
183 | | | | #. Multiple ports are scheduled in round robin order with |
184 | | | | all ports having equal priority. |
186 +---+--------------------+----------------------------+---------------------------------------------------------------+
187 | 2 | Subport | Configurable (default: 8) | #. Traffic shaping using token bucket algorithm (one token |
188 | | | | bucket per subport). |
190 | | | | #. Upper limit enforced per Traffic Class (TC) at the |
191 | | | | subport level. |
193 | | | | #. Lower priority TCs able to reuse subport bandwidth |
194 | | | | currently unused by higher priority TCs. |
196 +---+--------------------+----------------------------+---------------------------------------------------------------+
197 | 3 | Pipe | Configurable (default: 4K) | #. Traffic shaping using the token bucket algorithm (one |
198 | | | | token bucket per pipe. |
200 +---+--------------------+----------------------------+---------------------------------------------------------------+
201 | 4 | Traffic Class (TC) | 4 | #. TCs of the same pipe handled in strict priority order. |
203 | | | | #. Upper limit enforced per TC at the pipe level. |
205 | | | | #. Lower priority TCs able to reuse pipe bandwidth currently |
206 | | | | unused by higher priority TCs. |
208 | | | | #. When subport TC is oversubscribed (configuration time |
209 | | | | event), pipe TC upper limit is capped to a dynamically |
210 | | | | adjusted value that is shared by all the subport pipes. |
212 +---+--------------------+----------------------------+---------------------------------------------------------------+
213 | 5 | Queue | 4 | #. Queues of the same TC are serviced using Weighted Round |
214 | | | | Robin (WRR) according to predefined weights. |
216 +---+--------------------+----------------------------+---------------------------------------------------------------+
218 Application Programming Interface (API)
219 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
221 Port Scheduler Configuration API
222 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
224 The rte_sched.h file contains configuration functions for port, subport and pipe.
226 Port Scheduler Enqueue API
227 ^^^^^^^^^^^^^^^^^^^^^^^^^^
229 The port scheduler enqueue API is very similar to the API of the DPDK PMD TX function.
233 int rte_sched_port_enqueue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts);
235 Port Scheduler Dequeue API
236 ^^^^^^^^^^^^^^^^^^^^^^^^^^
238 The port scheduler dequeue API is very similar to the API of the DPDK PMD RX function.
242 int rte_sched_port_dequeue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts);
249 /* File "application.c" */
253 #define NIC_RX_PORT 0
254 #define NIC_RX_QUEUE 0
255 #define NIC_TX_PORT 1
256 #define NIC_TX_QUEUE 0
258 struct rte_sched_port *port = NULL;
259 struct rte_mbuf *pkts_rx[N_PKTS_RX], *pkts_tx[N_PKTS_TX];
260 uint32_t n_pkts_rx, n_pkts_tx;
264 <initialization code>
268 /* Read packets from NIC RX queue */
270 n_pkts_rx = rte_eth_rx_burst(NIC_RX_PORT, NIC_RX_QUEUE, pkts_rx, N_PKTS_RX);
272 /* Hierarchical scheduler enqueue */
274 rte_sched_port_enqueue(port, pkts_rx, n_pkts_rx);
276 /* Hierarchical scheduler dequeue */
278 n_pkts_tx = rte_sched_port_dequeue(port, pkts_tx, N_PKTS_TX);
280 /* Write packets to NIC TX queue */
282 rte_eth_tx_burst(NIC_TX_PORT, NIC_TX_QUEUE, pkts_tx, n_pkts_tx);
288 Internal Data Structures per Port
289 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
291 A schematic of the internal data structures in shown in with details in.
293 .. _figure_data_struct_per_port:
295 .. figure:: img/data_struct_per_port.*
297 Internal Data Structures per Port
302 .. table:: Scheduler Internal Data Structures per Port
304 +---+----------------------+-------------------------+---------------------+------------------------------+---------------------------------------------------+
305 | # | Data structure | Size (bytes) | # per port | Access type | Description |
307 | | | | +-------------+----------------+---------------------------------------------------+
308 | | | | | Enq | Deq | |
310 +===+======================+=========================+=====================+=============+================+===================================================+
311 | 1 | Subport table entry | 64 | # subports per port | - | Rd, Wr | Persistent subport data (credits, etc). |
313 +---+----------------------+-------------------------+---------------------+-------------+----------------+---------------------------------------------------+
314 | 2 | Pipe table entry | 64 | # pipes per port | - | Rd, Wr | Persistent data for pipe, its TCs and its queues |
315 | | | | | | | (credits, etc) that is updated during run-time. |
317 | | | | | | | The pipe configuration parameters do not change |
318 | | | | | | | during run-time. The same pipe configuration |
319 | | | | | | | parameters are shared by multiple pipes, |
320 | | | | | | | therefore they are not part of pipe table entry. |
322 +---+----------------------+-------------------------+---------------------+-------------+----------------+---------------------------------------------------+
323 | 3 | Queue table entry | 4 | #queues per port | Rd, Wr | Rd, Wr | Persistent queue data (read and write pointers). |
324 | | | | | | | The queue size is the same per TC for all queues, |
325 | | | | | | | allowing the queue base address to be computed |
326 | | | | | | | using a fast formula, so these two parameters are |
327 | | | | | | | not part of queue table entry. |
329 | | | | | | | The queue table entries for any given pipe are |
330 | | | | | | | stored in the same cache line. |
332 +---+----------------------+-------------------------+---------------------+-------------+----------------+---------------------------------------------------+
333 | 4 | Queue storage area | Config (default: 64 x8) | # queues per port | Wr | Rd | Array of elements per queue; each element is 8 |
334 | | | | | | | byte in size (mbuf pointer). |
336 +---+----------------------+-------------------------+---------------------+-------------+----------------+---------------------------------------------------+
337 | 5 | Active queues bitmap | 1 bit per queue | 1 | Wr (Set) | Rd, Wr (Clear) | The bitmap maintains one status bit per queue: |
338 | | | | | | | queue not active (queue is empty) or queue active |
339 | | | | | | | (queue is not empty). |
341 | | | | | | | Queue bit is set by the scheduler enqueue and |
342 | | | | | | | cleared by the scheduler dequeue when queue |
343 | | | | | | | becomes empty. |
345 | | | | | | | Bitmap scan operation returns the next non-empty |
346 | | | | | | | pipe and its status (16-bit mask of active queue |
347 | | | | | | | in the pipe). |
349 +---+----------------------+-------------------------+---------------------+-------------+----------------+---------------------------------------------------+
350 | 6 | Grinder | ~128 | Config (default: 8) | - | Rd, Wr | Short list of active pipes currently under |
351 | | | | | | | processing. The grinder contains temporary data |
352 | | | | | | | during pipe processing. |
354 | | | | | | | Once the current pipe exhausts packets or |
355 | | | | | | | credits, it is replaced with another active pipe |
356 | | | | | | | from the bitmap. |
358 +---+----------------------+-------------------------+---------------------+-------------+----------------+---------------------------------------------------+
360 Multicore Scaling Strategy
361 ^^^^^^^^^^^^^^^^^^^^^^^^^^
363 The multicore scaling strategy is:
365 #. Running different physical ports on different threads. The enqueue and dequeue of the same port are run by the same thread.
367 #. Splitting the same physical port to different threads by running different sets of subports of the same physical port (virtual ports) on different threads.
368 Similarly, a subport can be split into multiple subports that are each run by a different thread.
369 The enqueue and dequeue of the same port are run by the same thread.
370 This is only required if, for performance reasons, it is not possible to handle a full port with a single core.
372 Enqueue and Dequeue for the Same Output Port
373 """"""""""""""""""""""""""""""""""""""""""""
375 Running enqueue and dequeue operations for the same output port from different cores is likely to cause significant impact on scheduler's performance
376 and it is therefore not recommended.
378 The port enqueue and dequeue operations share access to the following data structures:
380 #. Packet descriptors
384 #. Queue storage area
386 #. Bitmap of active queues
388 The expected drop in performance is due to:
390 #. Need to make the queue and bitmap operations thread safe,
391 which requires either using locking primitives for access serialization (for example, spinlocks/ semaphores) or
392 using atomic primitives for lockless access (for example, Test and Set, Compare And Swap, an so on).
393 The impact is much higher in the former case.
395 #. Ping-pong of cache lines storing the shared data structures between the cache hierarchies of the two cores
396 (done transparently by the MESI protocol cache coherency CPU hardware).
398 Therefore, the scheduler enqueue and dequeue operations have to be run from the same thread,
399 which allows the queues and the bitmap operations to be non-thread safe and
400 keeps the scheduler data structures internal to the same core.
405 Scaling up the number of NIC ports simply requires a proportional increase in the number of CPU cores to be used for traffic scheduling.
410 The sequence of steps per packet:
412 #. *Access* the mbuf to read the data fields required to identify the destination queue for the packet.
413 These fields are: port, subport, traffic class and queue within traffic class, and are typically set by the classification stage.
415 #. *Access* the queue structure to identify the write location in the queue array.
416 If the queue is full, then the packet is discarded.
418 #. *Access* the queue array location to store the packet (i.e. write the mbuf pointer).
420 It should be noted the strong data dependency between these steps, as steps 2 and 3 cannot start before the result from steps 1 and 2 becomes available,
421 which prevents the processor out of order execution engine to provide any significant performance optimizations.
423 Given the high rate of input packets and the large amount of queues,
424 it is expected that the data structures accessed to enqueue the current packet are not present
425 in the L1 or L2 data cache of the current core, thus the above 3 memory accesses would result (on average) in L1 and L2 data cache misses.
426 A number of 3 L1/L2 cache misses per packet is not acceptable for performance reasons.
428 The workaround is to prefetch the required data structures in advance. The prefetch operation has an execution latency during which
429 the processor should not attempt to access the data structure currently under prefetch, so the processor should execute other work.
430 The only other work available is to execute different stages of the enqueue sequence of operations on other input packets,
431 thus resulting in a pipelined implementation for the enqueue operation.
433 :numref:`figure_prefetch_pipeline` illustrates a pipelined implementation for the enqueue operation with 4 pipeline stages and each stage executing 2 different input packets.
434 No input packet can be part of more than one pipeline stage at a given time.
436 .. _figure_prefetch_pipeline:
438 .. figure:: img/prefetch_pipeline.*
440 Prefetch Pipeline for the Hierarchical Scheduler Enqueue Operation
443 The congestion management scheme implemented by the enqueue pipeline described above is very basic:
444 packets are enqueued until a specific queue becomes full,
445 then all the packets destined to the same queue are dropped until packets are consumed (by the dequeue operation).
446 This can be improved by enabling RED/WRED as part of the enqueue pipeline which looks at the queue occupancy and
447 packet priority in order to yield the enqueue/drop decision for a specific packet
448 (as opposed to enqueuing all packets / dropping all packets indiscriminately).
450 Dequeue State Machine
451 ^^^^^^^^^^^^^^^^^^^^^
453 The sequence of steps to schedule the next packet from the current pipe is:
455 #. Identify the next active pipe using the bitmap scan operation, *prefetch* pipe.
457 #. *Read* pipe data structure. Update the credits for the current pipe and its subport.
458 Identify the first active traffic class within the current pipe, select the next queue using WRR,
459 *prefetch* queue pointers for all the 16 queues of the current pipe.
461 #. *Read* next element from the current WRR queue and *prefetch* its packet descriptor.
463 #. *Read* the packet length from the packet descriptor (mbuf structure).
464 Based on the packet length and the available credits (of current pipe, pipe traffic class, subport and subport traffic class),
465 take the go/no go scheduling decision for the current packet.
467 To avoid the cache misses, the above data structures (pipe, queue, queue array, mbufs) are prefetched in advance of being accessed.
468 The strategy of hiding the latency of the prefetch operations is to switch from the current pipe (in grinder A) to another pipe
469 (in grinder B) immediately after a prefetch is issued for the current pipe.
470 This gives enough time to the prefetch operation to complete before the execution switches back to this pipe (in grinder A).
472 The dequeue pipe state machine exploits the data presence into the processor cache,
473 therefore it tries to send as many packets from the same pipe TC and pipe as possible (up to the available packets and credits) before
474 moving to the next active TC from the same pipe (if any) or to another active pipe.
476 .. _figure_pipe_prefetch_sm:
478 .. figure:: img/pipe_prefetch_sm.*
480 Pipe Prefetch State Machine for the Hierarchical Scheduler Dequeue
484 Timing and Synchronization
485 ^^^^^^^^^^^^^^^^^^^^^^^^^^
487 The output port is modeled as a conveyor belt of byte slots that need to be filled by the scheduler with data for transmission.
488 For 10 GbE, there are 1.25 billion byte slots that need to be filled by the port scheduler every second.
489 If the scheduler is not fast enough to fill the slots, provided that enough packets and credits exist,
490 then some slots will be left unused and bandwidth will be wasted.
492 In principle, the hierarchical scheduler dequeue operation should be triggered by NIC TX.
493 Usually, once the occupancy of the NIC TX input queue drops below a predefined threshold,
494 the port scheduler is woken up (interrupt based or polling based,
495 by continuously monitoring the queue occupancy) to push more packets into the queue.
497 Internal Time Reference
498 """""""""""""""""""""""
500 The scheduler needs to keep track of time advancement for the credit logic,
501 which requires credit updates based on time (for example, subport and pipe traffic shaping, traffic class upper limit enforcement, and so on).
503 Every time the scheduler decides to send a packet out to the NIC TX for transmission, the scheduler will increment its internal time reference accordingly.
504 Therefore, it is convenient to keep the internal time reference in units of bytes,
505 where a byte signifies the time duration required by the physical interface to send out a byte on the transmission medium.
506 This way, as a packet is scheduled for transmission, the time is incremented with (n + h),
507 where n is the packet length in bytes and h is the number of framing overhead bytes per packet.
509 Internal Time Reference Re-synchronization
510 """"""""""""""""""""""""""""""""""""""""""
512 The scheduler needs to align its internal time reference to the pace of the port conveyor belt.
513 The reason is to make sure that the scheduler does not feed the NIC TX with more bytes than the line rate of the physical medium in order to prevent packet drop
514 (by the scheduler, due to the NIC TX input queue being full, or later on, internally by the NIC TX).
516 The scheduler reads the current time on every dequeue invocation.
517 The CPU time stamp can be obtained by reading either the Time Stamp Counter (TSC) register or the High Precision Event Timer (HPET) register.
518 The current CPU time stamp is converted from number of CPU clocks to number of bytes:
519 *time_bytes = time_cycles / cycles_per_byte, where cycles_per_byte*
520 is the amount of CPU cycles that is equivalent to the transmission time for one byte on the wire
521 (e.g. for a CPU frequency of 2 GHz and a 10GbE port,*cycles_per_byte = 1.6*).
523 The scheduler maintains an internal time reference of the NIC time.
524 Whenever a packet is scheduled, the NIC time is incremented with the packet length (including framing overhead).
525 On every dequeue invocation, the scheduler checks its internal reference of the NIC time against the current time:
527 #. If NIC time is in the future (NIC time >= current time), no adjustment of NIC time is needed.
528 This means that scheduler is able to schedule NIC packets before the NIC actually needs those packets, so the NIC TX is well supplied with packets;
530 #. If NIC time is in the past (NIC time < current time), then NIC time should be adjusted by setting it to the current time.
531 This means that the scheduler is not able to keep up with the speed of the NIC byte conveyor belt,
532 so NIC bandwidth is wasted due to poor packet supply to the NIC TX.
534 Scheduler Accuracy and Granularity
535 """"""""""""""""""""""""""""""""""
537 The scheduler round trip delay (SRTD) is the time (number of CPU cycles) between two consecutive examinations of the same pipe by the scheduler.
539 To keep up with the output port (that is, avoid bandwidth loss),
540 the scheduler should be able to schedule n packets faster than the same n packets are transmitted by NIC TX.
542 The scheduler needs to keep up with the rate of each individual pipe,
543 as configured for the pipe token bucket, assuming that no port oversubscription is taking place.
544 This means that the size of the pipe token bucket should be set high enough to prevent it from overflowing due to big SRTD,
545 as this would result in credit loss (and therefore bandwidth loss) for the pipe.
553 The scheduling decision to send next packet from (subport S, pipe P, traffic class TC, queue Q) is favorable (packet is sent)
554 when all the conditions below are met:
556 * Pipe P of subport S is currently selected by one of the port grinders;
558 * Traffic class TC is the highest priority active traffic class of pipe P;
560 * Queue Q is the next queue selected by WRR within traffic class TC of pipe P;
562 * Subport S has enough credits to send the packet;
564 * Subport S has enough credits for traffic class TC to send the packet;
566 * Pipe P has enough credits to send the packet;
568 * Pipe P has enough credits for traffic class TC to send the packet.
570 If all the above conditions are met,
571 then the packet is selected for transmission and the necessary credits are subtracted from subport S,
572 subport S traffic class TC, pipe P, pipe P traffic class TC.
577 As the greatest common divisor for all packet lengths is one byte, the unit of credit is selected as one byte.
578 The number of credits required for the transmission of a packet of n bytes is equal to (n+h),
579 where h is equal to the number of framing overhead bytes per packet.
583 .. table:: Ethernet Frame Overhead Fields
585 +---+--------------------------------+----------------+---------------------------------------------------------------------------+
586 | # | Packet field | Length (bytes) | Comments |
588 +===+================================+================+===========================================================================+
589 | 1 | Preamble | 7 | |
591 +---+--------------------------------+----------------+---------------------------------------------------------------------------+
592 | 2 | Start of Frame Delimiter (SFD) | 1 | |
594 +---+--------------------------------+----------------+---------------------------------------------------------------------------+
595 | 3 | Frame Check Sequence (FCS) | 4 | Considered overhead only if not included in the mbuf packet length field. |
597 +---+--------------------------------+----------------+---------------------------------------------------------------------------+
598 | 4 | Inter Frame Gap (IFG) | 12 | |
600 +---+--------------------------------+----------------+---------------------------------------------------------------------------+
603 +---+--------------------------------+----------------+---------------------------------------------------------------------------+
608 The traffic shaping for subport and pipe is implemented using a token bucket per subport/per pipe.
609 Each token bucket is implemented using one saturated counter that keeps track of the number of available credits.
611 The token bucket generic parameters and operations are presented in :numref:`table_qos_6` and :numref:`table_qos_7`.
615 .. table:: Token Bucket Generic Parameters
617 +---+------------------------+--------------------+---------------------------------------------------------+
618 | # | Token Bucket Parameter | Unit | Description |
620 +===+========================+====================+=========================================================+
621 | 1 | bucket_rate | Credits per second | Rate of adding credits to the bucket. |
623 +---+------------------------+--------------------+---------------------------------------------------------+
624 | 2 | bucket_size | Credits | Max number of credits that can be stored in the bucket. |
626 +---+------------------------+--------------------+---------------------------------------------------------+
630 .. table:: Token Bucket Generic Operations
632 +---+------------------------+------------------------------------------------------------------------------+
633 | # | Token Bucket Operation | Description |
635 +===+========================+==============================================================================+
636 | 1 | Initialization | Bucket set to a predefined value, e.g. zero or half of the bucket size. |
638 +---+------------------------+------------------------------------------------------------------------------+
639 | 2 | Credit update | Credits are added to the bucket on top of existing ones, either periodically |
640 | | | or on demand, based on the bucket_rate. Credits cannot exceed the upper |
641 | | | limit defined by the bucket_size, so any credits to be added to the bucket |
642 | | | while the bucket is full are dropped. |
644 +---+------------------------+------------------------------------------------------------------------------+
645 | 3 | Credit consumption | As result of packet scheduling, the necessary number of credits is removed |
646 | | | from the bucket. The packet can only be sent if enough credits are in the |
647 | | | bucket to send the full packet (packet bytes and framing overhead for the |
650 +---+------------------------+------------------------------------------------------------------------------+
652 To implement the token bucket generic operations described above,
653 the current design uses the persistent data structure presented in :numref:`table_qos_8`,
654 while the implementation of the token bucket operations is described in :numref:`table_qos_9`.
658 .. table:: Token Bucket Persistent Data Structure
660 +---+------------------------+-------+----------------------------------------------------------------------+
661 | # | Token bucket field | Unit | Description |
663 +===+========================+=======+======================================================================+
664 | 1 | tb_time | Bytes | Time of the last credit update. Measured in bytes instead of seconds |
665 | | | | or CPU cycles for ease of credit consumption operation |
666 | | | | (as the current time is also maintained in bytes). |
668 | | | | See Section 26.2.4.5.1 "Internal Time Reference" for an |
669 | | | | explanation of why the time is maintained in byte units. |
671 +---+------------------------+-------+----------------------------------------------------------------------+
672 | 2 | tb_period | Bytes | Time period that should elapse since the last credit update in order |
673 | | | | for the bucket to be awarded tb_credits_per_period worth or credits. |
675 +---+------------------------+-------+----------------------------------------------------------------------+
676 | 3 | tb_credits_per_period | Bytes | Credit allowance per tb_period. |
678 +---+------------------------+-------+----------------------------------------------------------------------+
679 | 4 | tb_size | Bytes | Bucket size, i.e. upper limit for the tb_credits. |
681 +---+------------------------+-------+----------------------------------------------------------------------+
682 | 5 | tb_credits | Bytes | Number of credits currently in the bucket. |
684 +---+------------------------+-------+----------------------------------------------------------------------+
686 The bucket rate (in bytes per second) can be computed with the following formula:
688 *bucket_rate = (tb_credits_per_period / tb_period) * r*
690 where, r = port line rate (in bytes per second).
694 .. table:: Token Bucket Operations
696 +---+-------------------------+-----------------------------------------------------------------------------+
697 | # | Token bucket operation | Description |
699 +===+=========================+=============================================================================+
700 | 1 | Initialization | *tb_credits = 0; or tb_credits = tb_size / 2;* |
702 +---+-------------------------+-----------------------------------------------------------------------------+
703 | 2 | Credit update | Credit update options: |
705 | | | * Every time a packet is sent for a port, update the credits of all the |
706 | | | the subports and pipes of that port. Not feasible. |
708 | | | * Every time a packet is sent, update the credits for the pipe and |
709 | | | subport. Very accurate, but not needed (a lot of calculations). |
711 | | | * Every time a pipe is selected (that is, picked by one |
712 | | | of the grinders), update the credits for the pipe and its subport. |
714 | | | The current implementation is using option 3. According to Section |
715 | | | `Dequeue State Machine`_, the pipe and subport credits are |
716 | | | updated every time a pipe is selected by the dequeue process before the |
717 | | | pipe and subport credits are actually used. |
719 | | | The implementation uses a tradeoff between accuracy and speed by updating |
720 | | | the bucket credits only when at least a full *tb_period* has elapsed since |
721 | | | the last update. |
723 | | | * Full accuracy can be achieved by selecting the value for *tb_period* |
724 | | | for which *tb_credits_per_period = 1*. |
726 | | | * When full accuracy is not required, better performance is achieved by |
727 | | | setting *tb_credits* to a larger value. |
729 | | | Update operations: |
731 | | | * n_periods = (time - tb_time) / tb_period; |
733 | | | * tb_credits += n_periods * tb_credits_per_period; |
735 | | | * tb_credits = min(tb_credits, tb_size); |
737 | | | * tb_time += n_periods * tb_period; |
739 +---+-------------------------+-----------------------------------------------------------------------------+
740 | 3 | Credit consumption | As result of packet scheduling, the necessary number of credits is removed |
741 | | (on packet scheduling) | from the bucket. The packet can only be sent if enough credits are in the |
742 | | | bucket to send the full packet (packet bytes and framing overhead for the |
745 | | | Scheduling operations: |
747 | | | pkt_credits = pkt_len + frame_overhead; |
748 | | | if (tb_credits >= pkt_credits){tb_credits -= pkt_credits;} |
750 +---+-------------------------+-----------------------------------------------------------------------------+
755 Implementation of Strict Priority Scheduling
756 ''''''''''''''''''''''''''''''''''''''''''''
758 Strict priority scheduling of traffic classes within the same pipe is implemented by the pipe dequeue state machine,
759 which selects the queues in ascending order.
760 Therefore, queues 0..3 (associated with TC 0, highest priority TC) are handled before
761 queues 4..7 (TC 1, lower priority than TC 0),
762 which are handled before queues 8..11 (TC 2),
763 which are handled before queues 12..15 (TC 3, lowest priority TC).
765 Upper Limit Enforcement
766 '''''''''''''''''''''''
768 The traffic classes at the pipe and subport levels are not traffic shaped,
769 so there is no token bucket maintained in this context.
770 The upper limit for the traffic classes at the subport and
771 pipe levels is enforced by periodically refilling the subport / pipe traffic class credit counter,
772 out of which credits are consumed every time a packet is scheduled for that subport / pipe,
773 as described in :numref:`table_qos_10` and :numref:`table_qos_11`.
777 .. table:: Subport/Pipe Traffic Class Upper Limit Enforcement Persistent Data Structure
779 +---+-----------------------+-------+-----------------------------------------------------------------------+
780 | # | Subport or pipe field | Unit | Description |
782 +===+=======================+=======+=======================================================================+
783 | 1 | tc_time | Bytes | Time of the next update (upper limit refill) for the 4 TCs of the |
784 | | | | current subport / pipe. |
786 | | | | See Section `Internal Time Reference`_ for the |
787 | | | | explanation of why the time is maintained in byte units. |
789 +---+-----------------------+-------+-----------------------------------------------------------------------+
790 | 2 | tc_period | Bytes | Time between two consecutive updates for the 4 TCs of the current |
791 | | | | subport / pipe. This is expected to be many times bigger than the |
792 | | | | typical value of the token bucket tb_period. |
794 +---+-----------------------+-------+-----------------------------------------------------------------------+
795 | 3 | tc_credits_per_period | Bytes | Upper limit for the number of credits allowed to be consumed by the |
796 | | | | current TC during each enforcement period tc_period. |
798 +---+-----------------------+-------+-----------------------------------------------------------------------+
799 | 4 | tc_credits | Bytes | Current upper limit for the number of credits that can be consumed by |
800 | | | | the current traffic class for the remainder of the current |
801 | | | | enforcement period. |
803 +---+-----------------------+-------+-----------------------------------------------------------------------+
807 .. table:: Subport/Pipe Traffic Class Upper Limit Enforcement Operations
809 +---+--------------------------+----------------------------------------------------------------------------+
810 | # | Traffic Class Operation | Description |
812 +===+==========================+============================================================================+
813 | 1 | Initialization | tc_credits = tc_credits_per_period; |
815 | | | tc_time = tc_period; |
817 +---+--------------------------+----------------------------------------------------------------------------+
818 | 2 | Credit update | Update operations: |
820 | | | if (time >= tc_time) { |
822 | | | tc_credits = tc_credits_per_period; |
824 | | | tc_time = time + tc_period; |
828 +---+--------------------------+----------------------------------------------------------------------------+
829 | 3 | Credit consumption | As result of packet scheduling, the TC limit is decreased with the |
830 | | (on packet scheduling) | necessary number of credits. The packet can only be sent if enough credits |
831 | | | are currently available in the TC limit to send the full packet |
832 | | | (packet bytes and framing overhead for the packet). |
834 | | | Scheduling operations: |
836 | | | pkt_credits = pk_len + frame_overhead; |
838 | | | if (tc_credits >= pkt_credits) {tc_credits -= pkt_credits;} |
840 +---+--------------------------+----------------------------------------------------------------------------+
842 Weighted Round Robin (WRR)
843 """"""""""""""""""""""""""
845 The evolution of the WRR design solution from simple to complex is shown in :numref:`table_qos_12`.
849 .. table:: Weighted Round Robin (WRR)
851 +---+------------+-----------------+-------------+----------------------------------------------------------+
852 | # | All Queues | Equal Weights | All Packets | Strategy |
853 | | Active? | for All Queues? | Equal? | |
854 +===+============+=================+=============+==========================================================+
855 | 1 | Yes | Yes | Yes | **Byte level round robin** |
857 | | | | | *Next queue* queue #i, i = *(i + 1) % n* |
859 +---+------------+-----------------+-------------+----------------------------------------------------------+
860 | 2 | Yes | Yes | No | **Packet level round robin** |
862 | | | | | Consuming one byte from queue #i requires consuming |
863 | | | | | exactly one token for queue #i. |
865 | | | | | T(i) = Accumulated number of tokens previously consumed |
866 | | | | | from queue #i. Every time a packet is consumed from |
867 | | | | | queue #i, T(i) is updated as: T(i) += *pkt_len*. |
869 | | | | | *Next queue* : queue with the smallest T. |
872 +---+------------+-----------------+-------------+----------------------------------------------------------+
873 | 3 | Yes | No | No | **Packet level weighted round robin** |
875 | | | | | This case can be reduced to the previous case by |
876 | | | | | introducing a cost per byte that is different for each |
877 | | | | | queue. Queues with lower weights have a higher cost per |
878 | | | | | byte. This way, it is still meaningful to compare the |
879 | | | | | consumption amongst different queues in order to select |
880 | | | | | the next queue. |
882 | | | | | w(i) = Weight of queue #i |
884 | | | | | t(i) = Tokens per byte for queue #i, defined as the |
885 | | | | | inverse weight of queue #i. |
886 | | | | | For example, if w[0..3] = [1:2:4:8], |
887 | | | | | then t[0..3] = [8:4:2:1]; if w[0..3] = [1:4:15:20], |
888 | | | | | then t[0..3] = [60:15:4:3]. |
889 | | | | | Consuming one byte from queue #i requires consuming t(i) |
890 | | | | | tokens for queue #i. |
892 | | | | | T(i) = Accumulated number of tokens previously consumed |
893 | | | | | from queue #i. Every time a packet is consumed from |
894 | | | | | queue #i, T(i) is updated as: *T(i) += pkt_len * t(i)*. |
895 | | | | | *Next queue* : queue with the smallest T. |
897 +---+------------+-----------------+-------------+----------------------------------------------------------+
898 | 4 | No | No | No | **Packet level weighted round robin with variable queue |
901 | | | | | Reduce this case to the previous case by setting the |
902 | | | | | consumption of inactive queues to a high number, so that |
903 | | | | | the inactive queues will never be selected by the |
904 | | | | | smallest T logic. |
906 | | | | | To prevent T from overflowing as result of successive |
907 | | | | | accumulations, T(i) is truncated after each packet |
908 | | | | | consumption for all queues. |
909 | | | | | For example, T[0..3] = [1000, 1100, 1200, 1300] |
910 | | | | | is truncated to T[0..3] = [0, 100, 200, 300] |
911 | | | | | by subtracting the min T from T(i), i = 0..n. |
913 | | | | | This requires having at least one active queue in the |
914 | | | | | set of input queues, which is guaranteed by the dequeue |
915 | | | | | state machine never selecting an inactive traffic class. |
917 | | | | | *mask(i) = Saturation mask for queue #i, defined as:* |
919 | | | | | mask(i) = (queue #i is active)? 0 : 0xFFFFFFFF; |
921 | | | | | w(i) = Weight of queue #i |
923 | | | | | t(i) = Tokens per byte for queue #i, defined as the |
924 | | | | | inverse weight of queue #i. |
926 | | | | | T(i) = Accumulated numbers of tokens previously consumed |
927 | | | | | from queue #i. |
929 | | | | | *Next queue* : queue with smallest T. |
931 | | | | | Before packet consumption from queue #i: |
933 | | | | | *T(i) |= mask(i)* |
935 | | | | | After packet consumption from queue #i: |
937 | | | | | T(j) -= T(i), j != i |
939 | | | | | T(i) = pkt_len * t(i) |
941 | | | | | Note: T(j) uses the T(i) value before T(i) is updated. |
943 +---+------------+-----------------+-------------+----------------------------------------------------------+
945 Subport Traffic Class Oversubscription
946 """"""""""""""""""""""""""""""""""""""
951 Oversubscription for subport traffic class X is a configuration-time event that occurs when
952 more bandwidth is allocated for traffic class X at the level of subport member pipes than
953 allocated for the same traffic class at the parent subport level.
955 The existence of the oversubscription for a specific subport and
956 traffic class is solely the result of pipe and
957 subport-level configuration as opposed to being created due
958 to dynamic evolution of the traffic load at run-time (as congestion is).
960 When the overall demand for traffic class X for the current subport is low,
961 the existence of the oversubscription condition does not represent a problem,
962 as demand for traffic class X is completely satisfied for all member pipes.
963 However, this can no longer be achieved when the aggregated demand for traffic class X
964 for all subport member pipes exceeds the limit configured at the subport level.
969 summarizes some of the possible approaches for handling this problem,
970 with the third approach selected for implementation.
974 .. table:: Subport Traffic Class Oversubscription
976 +-----+---------------------------+-------------------------------------------------------------------------+
977 | No. | Approach | Description |
979 +=====+===========================+=========================================================================+
980 | 1 | Don't care | First come, first served. |
982 | | | This approach is not fair amongst subport member pipes, as pipes that |
983 | | | are served first will use up as much bandwidth for TC X as they need, |
984 | | | while pipes that are served later will receive poor service due to |
985 | | | bandwidth for TC X at the subport level being scarce. |
987 +-----+---------------------------+-------------------------------------------------------------------------+
988 | 2 | Scale down all pipes | All pipes within the subport have their bandwidth limit for TC X scaled |
989 | | | down by the same factor. |
991 | | | This approach is not fair among subport member pipes, as the low end |
992 | | | pipes (that is, pipes configured with low bandwidth) can potentially |
993 | | | experience severe service degradation that might render their service |
994 | | | unusable (if available bandwidth for these pipes drops below the |
995 | | | minimum requirements for a workable service), while the service |
996 | | | degradation for high end pipes might not be noticeable at all. |
998 +-----+---------------------------+-------------------------------------------------------------------------+
999 | 3 | Cap the high demand pipes | Each subport member pipe receives an equal share of the bandwidth |
1000 | | | available at run-time for TC X at the subport level. Any bandwidth left |
1001 | | | unused by the low-demand pipes is redistributed in equal portions to |
1002 | | | the high-demand pipes. This way, the high-demand pipes are truncated |
1003 | | | while the low-demand pipes are not impacted. |
1005 +-----+---------------------------+-------------------------------------------------------------------------+
1007 Typically, the subport TC oversubscription feature is enabled only for the lowest priority traffic class (TC 3),
1008 which is typically used for best effort traffic,
1009 with the management plane preventing this condition from occurring for the other (higher priority) traffic classes.
1011 To ease implementation, it is also assumed that the upper limit for subport TC 3 is set to 100% of the subport rate,
1012 and that the upper limit for pipe TC 3 is set to 100% of pipe rate for all subport member pipes.
1014 Implementation Overview
1015 '''''''''''''''''''''''
1017 The algorithm computes a watermark, which is periodically updated based on the current demand experienced by the subport member pipes,
1018 whose purpose is to limit the amount of traffic that each pipe is allowed to send for TC 3.
1019 The watermark is computed at the subport level at the beginning of each traffic class upper limit enforcement period and
1020 the same value is used by all the subport member pipes throughout the current enforcement period.
1021 illustrates how the watermark computed as subport level at the beginning of each period is propagated to all subport member pipes.
1023 At the beginning of the current enforcement period (which coincides with the end of the previous enforcement period),
1024 the value of the watermark is adjusted based on the amount of bandwidth allocated to TC 3 at the beginning of the previous period that
1025 was not left unused by the subport member pipes at the end of the previous period.
1027 If there was subport TC 3 bandwidth left unused,
1028 the value of the watermark for the current period is increased to encourage the subport member pipes to consume more bandwidth.
1029 Otherwise, the value of the watermark is decreased to enforce equality of bandwidth consumption among subport member pipes for TC 3.
1031 The increase or decrease in the watermark value is done in small increments,
1032 so several enforcement periods might be required to reach the equilibrium state.
1033 This state can change at any moment due to variations in the demand experienced by the subport member pipes for TC 3, for example,
1034 as a result of demand increase (when the watermark needs to be lowered) or demand decrease (when the watermark needs to be increased).
1036 When demand is low, the watermark is set high to prevent it from impeding the subport member pipes from consuming more bandwidth.
1037 The highest value for the watermark is picked as the highest rate configured for a subport member pipe.
1038 :numref:`table_qos_14` and :numref:`table_qos_15` illustrates the watermark operation.
1042 .. table:: Watermark Propagation from Subport Level to Member Pipes at the Beginning of Each Traffic Class Upper Limit Enforcement Period
1044 +-----+---------------------------------+----------------------------------------------------+
1045 | No. | Subport Traffic Class Operation | Description |
1047 +=====+=================================+====================================================+
1048 | 1 | Initialization | **Subport level**: subport_period_id= 0 |
1050 | | | **Pipe level**: pipe_period_id = 0 |
1052 +-----+---------------------------------+----------------------------------------------------+
1053 | 2 | Credit update | **Subport Level**: |
1055 | | | if (time>=subport_tc_time) |
1058 | | | subport_wm = water_mark_update(); |
1060 | | | subport_tc_time = time + subport_tc_period; |
1062 | | | subport_period_id++; |
1066 | | | **Pipelevel:** |
1068 | | | if(pipe_period_id != subport_period_id) |
1072 | | | pipe_ov_credits = subport_wm \* pipe_weight; |
1074 | | | pipe_period_id = subport_period_id; |
1078 +-----+---------------------------------+----------------------------------------------------+
1079 | 3 | Credit consumption | **Pipe level:** |
1080 | | (on packet scheduling) | |
1081 | | | pkt_credits = pk_len + frame_overhead; |
1083 | | | if(pipe_ov_credits >= pkt_credits{ |
1085 | | | pipe_ov_credits -= pkt_credits; |
1089 +-----+---------------------------------+----------------------------------------------------+
1093 .. table:: Watermark Calculation
1095 +-----+------------------+----------------------------------------------------------------------------------+
1096 | No. | Subport Traffic | Description |
1097 | | Class Operation | |
1098 +=====+==================+==================================================================================+
1099 | 1 | Initialization | **Subport level:** |
1103 +-----+------------------+----------------------------------------------------------------------------------+
1104 | 2 | Credit update | **Subport level (water_mark_update):** |
1106 | | | tc0_cons = subport_tc0_credits_per_period - subport_tc0_credits; |
1108 | | | tc1_cons = subport_tc1_credits_per_period - subport_tc1_credits; |
1110 | | | tc2_cons = subport_tc2_credits_per_period - subport_tc2_credits; |
1112 | | | tc3_cons = subport_tc3_credits_per_period - subport_tc3_credits; |
1114 | | | tc3_cons_max = subport_tc3_credits_per_period - (tc0_cons + tc1_cons + |
1117 | | | if(tc3_consumption > (tc3_consumption_max - MTU)){ |
1119 | | | wm -= wm >> 7; |
1121 | | | if(wm < WM_MIN) wm = WM_MIN; |
1125 | | | wm += (wm >> 7) + 1; |
1127 | | | if(wm > WM_MAX) wm = WM_MAX; |
1131 +-----+------------------+----------------------------------------------------------------------------------+
1133 Worst Case Scenarios for Performance
1134 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1136 Lots of Active Queues with Not Enough Credits
1137 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1139 The more queues the scheduler has to examine for packets and credits in order to select one packet,
1140 the lower the performance of the scheduler is.
1142 The scheduler maintains the bitmap of active queues, which skips the non-active queues,
1143 but in order to detect whether a specific pipe has enough credits,
1144 the pipe has to be drilled down using the pipe dequeue state machine,
1145 which consumes cycles regardless of the scheduling result
1146 (no packets are produced or at least one packet is produced).
1148 This scenario stresses the importance of the policer for the scheduler performance:
1149 if the pipe does not have enough credits,
1150 its packets should be dropped as soon as possible (before they reach the hierarchical scheduler),
1151 thus rendering the pipe queues as not active,
1152 which allows the dequeue side to skip that pipe with no cycles being spent on investigating the pipe credits
1153 that would result in a "not enough credits" status.
1155 Single Queue with 100% Line Rate
1156 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1158 The port scheduler performance is optimized for a large number of queues.
1159 If the number of queues is small,
1160 then the performance of the port scheduler for the same level of active traffic is expected to be worse than
1161 the performance of a small set of message passing queues.
1168 The purpose of the DPDK dropper is to drop packets arriving at a packet scheduler to avoid congestion.
1169 The dropper supports the Random Early Detection (RED),
1170 Weighted Random Early Detection (WRED) and tail drop algorithms.
1171 :numref:`figure_blk_diag_dropper` illustrates how the dropper integrates with the scheduler.
1172 The DPDK currently does not support congestion management
1173 so the dropper provides the only method for congestion avoidance.
1175 .. _figure_blk_diag_dropper:
1177 .. figure:: img/blk_diag_dropper.*
1179 High-level Block Diagram of the DPDK Dropper
1182 The dropper uses the Random Early Detection (RED) congestion avoidance algorithm as documented in the reference publication.
1183 The purpose of the RED algorithm is to monitor a packet queue,
1184 determine the current congestion level in the queue and decide whether an arriving packet should be enqueued or dropped.
1185 The RED algorithm uses an Exponential Weighted Moving Average (EWMA) filter to compute average queue size which
1186 gives an indication of the current congestion level in the queue.
1188 For each enqueue operation, the RED algorithm compares the average queue size to minimum and maximum thresholds.
1189 Depending on whether the average queue size is below, above or in between these thresholds,
1190 the RED algorithm calculates the probability that an arriving packet should be dropped and
1191 makes a random decision based on this probability.
1193 The dropper also supports Weighted Random Early Detection (WRED) by allowing the scheduler to select
1194 different RED configurations for the same packet queue at run-time.
1195 In the case of severe congestion, the dropper resorts to tail drop.
1196 This occurs when a packet queue has reached maximum capacity and cannot store any more packets.
1197 In this situation, all arriving packets are dropped.
1199 The flow through the dropper is illustrated in :numref:`figure_flow_tru_droppper`.
1200 The RED/WRED algorithm is exercised first and tail drop second.
1202 .. _figure_flow_tru_droppper:
1204 .. figure:: img/flow_tru_droppper.*
1206 Flow Through the Dropper
1209 The use cases supported by the dropper are:
1211 * * Initialize configuration data
1213 * * Initialize run-time data
1215 * * Enqueue (make a decision to enqueue or drop an arriving packet)
1217 * * Mark empty (record the time at which a packet queue becomes empty)
1219 The configuration use case is explained in :ref:`Section2.23.3.1 <Configuration>`,
1220 the enqueue operation is explained in :ref:`Section 2.23.3.2 <Enqueue_Operation>`
1221 and the mark empty operation is explained in :ref:`Section 2.23.3.3 <Queue_Empty_Operation>`.
1228 A RED configuration contains the parameters given in :numref:`table_qos_16`.
1232 .. table:: RED Configuration Parameters
1234 +--------------------------+---------+---------+------------------+
1235 | Parameter | Minimum | Maximum | Typical |
1237 +==========================+=========+=========+==================+
1238 | Minimum Threshold | 0 | 1022 | 1/4 x queue size |
1240 +--------------------------+---------+---------+------------------+
1241 | Maximum Threshold | 1 | 1023 | 1/2 x queue size |
1243 +--------------------------+---------+---------+------------------+
1244 | Inverse Mark Probability | 1 | 255 | 10 |
1246 +--------------------------+---------+---------+------------------+
1247 | EWMA Filter Weight | 1 | 12 | 9 |
1249 +--------------------------+---------+---------+------------------+
1251 The meaning of these parameters is explained in more detail in the following sections.
1252 The format of these parameters as specified to the dropper module API
1253 corresponds to the format used by Cisco* in their RED implementation.
1254 The minimum and maximum threshold parameters are specified to the dropper module in terms of number of packets.
1255 The mark probability parameter is specified as an inverse value, for example,
1256 an inverse mark probability parameter value of 10 corresponds
1257 to a mark probability of 1/10 (that is, 1 in 10 packets will be dropped).
1258 The EWMA filter weight parameter is specified as an inverse log value,
1259 for example, a filter weight parameter value of 9 corresponds to a filter weight of 1/29.
1261 .. _Enqueue_Operation:
1266 In the example shown in :numref:`figure_ex_data_flow_tru_dropper`, q (actual queue size) is the input value,
1267 avg (average queue size) and count (number of packets since the last drop) are run-time values,
1268 decision is the output value and the remaining values are configuration parameters.
1270 .. _figure_ex_data_flow_tru_dropper:
1272 .. figure:: img/ex_data_flow_tru_dropper.*
1274 Example Data Flow Through Dropper
1277 EWMA Filter Microblock
1278 ^^^^^^^^^^^^^^^^^^^^^^
1280 The purpose of the EWMA Filter microblock is to filter queue size values to smooth out transient changes
1281 that result from "bursty" traffic.
1282 The output value is the average queue size which gives a more stable view of the current congestion level in the queue.
1284 The EWMA filter has one configuration parameter, filter weight, which determines how quickly
1285 or slowly the average queue size output responds to changes in the actual queue size input.
1286 Higher values of filter weight mean that the average queue size responds more quickly to changes in actual queue size.
1288 Average Queue Size Calculation when the Queue is not Empty
1289 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""
1291 The definition of the EWMA filter is given in the following equation.
1293 .. image:: img/ewma_filter_eq_1.*
1297 * *avg* = average queue size
1299 * *wq* = filter weight
1301 * *q* = actual queue size
1305 The filter weight, wq = 1/2^n, where n is the filter weight parameter value passed to the dropper module
1306 on configuration (see :ref:`Section2.23.3.1 <Configuration>` ).
1308 Average Queue Size Calculation when the Queue is Empty
1309 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1311 The EWMA filter does not read time stamps and instead assumes that enqueue operations will happen quite regularly.
1312 Special handling is required when the queue becomes empty as the queue could be empty for a short time or a long time.
1313 When the queue becomes empty, average queue size should decay gradually to zero instead of dropping suddenly to zero
1314 or remaining stagnant at the last computed value.
1315 When a packet is enqueued on an empty queue, the average queue size is computed using the following formula:
1317 .. image:: img/ewma_filter_eq_2.*
1321 * *m* = the number of enqueue operations that could have occurred on this queue while the queue was empty
1323 In the dropper module, *m* is defined as:
1325 .. image:: img/m_definition.*
1329 * *time* = current time
1331 * *qtime* = time the queue became empty
1333 * *s* = typical time between successive enqueue operations on this queue
1335 The time reference is in units of bytes,
1336 where a byte signifies the time duration required by the physical interface to send out a byte on the transmission medium
1337 (see Section `Internal Time Reference`_).
1338 The parameter s is defined in the dropper module as a constant with the value: s=2^22.
1339 This corresponds to the time required by every leaf node in a hierarchy with 64K leaf nodes
1340 to transmit one 64-byte packet onto the wire and represents the worst case scenario.
1341 For much smaller scheduler hierarchies,
1342 it may be necessary to reduce the parameter s, which is defined in the red header source file (rte_red.h) as:
1348 Since the time reference is in bytes, the port speed is implied in the expression: *time-qtime*.
1349 The dropper does not have to be configured with the actual port speed.
1350 It adjusts automatically to low speed and high speed links.
1355 A numerical method is used to compute the factor (1-wq)^m that appears in Equation 2.
1357 This method is based on the following identity:
1359 .. image:: img/eq2_factor.*
1362 This allows us to express the following:
1364 .. image:: img/eq2_expression.*
1367 In the dropper module, a look-up table is used to compute log2(1-wq) for each value of wq supported by the dropper module.
1368 The factor (1-wq)^m can then be obtained by multiplying the table value by *m* and applying shift operations.
1369 To avoid overflow in the multiplication, the value, *m*, and the look-up table values are limited to 16 bits.
1370 The total size of the look-up table is 56 bytes.
1371 Once the factor (1-wq)^m is obtained using this method, the average queue size can be calculated from Equation 2.
1373 Alternative Approaches
1374 """"""""""""""""""""""
1376 Other methods for calculating the factor (1-wq)^m in the expression for computing average queue size
1377 when the queue is empty (Equation 2) were considered.
1378 These approaches include:
1380 * Floating-point evaluation
1382 * Fixed-point evaluation using a small look-up table (512B) and up to 16 multiplications
1383 (this is the approach used in the FreeBSD* ALTQ RED implementation)
1385 * Fixed-point evaluation using a small look-up table (512B) and 16 SSE multiplications
1386 (SSE optimized version of the approach used in the FreeBSD* ALTQ RED implementation)
1388 * Large look-up table (76 KB)
1390 The method that was finally selected (described above in Section 26.3.2.2.1) out performs all of these approaches
1391 in terms of run-time performance and memory requirements and
1392 also achieves accuracy comparable to floating-point evaluation.
1393 :numref:`table_qos_17` lists the performance of each of these alternative approaches relative to the method that is used in the dropper.
1394 As can be seen, the floating-point implementation achieved the worst performance.
1398 .. table:: Relative Performance of Alternative Approaches
1400 +------------------------------------------------------------------------------------+----------------------+
1401 | Method | Relative Performance |
1403 +====================================================================================+======================+
1404 | Current dropper method (see :ref:`Section 23.3.2.1.3 <Dropper>`) | 100% |
1406 +------------------------------------------------------------------------------------+----------------------+
1407 | Fixed-point method with small (512B) look-up table | 148% |
1409 +------------------------------------------------------------------------------------+----------------------+
1410 | SSE method with small (512B) look-up table | 114% |
1412 +------------------------------------------------------------------------------------+----------------------+
1413 | Large (76KB) look-up table | 118% |
1415 +------------------------------------------------------------------------------------+----------------------+
1416 | Floating-point | 595% |
1418 +------------------------------------------------------------------------------------+----------------------+
1419 | **Note**: In this case, since performance is expressed as time spent executing the operation in a |
1420 | specific condition, any relative performance value above 100% runs slower than the reference method. |
1422 +-----------------------------------------------------------------------------------------------------------+
1427 The Drop Decision block:
1429 * Compares the average queue size with the minimum and maximum thresholds
1431 * Calculates a packet drop probability
1433 * Makes a random decision to enqueue or drop an arriving packet
1435 The calculation of the drop probability occurs in two stages.
1436 An initial drop probability is calculated based on the average queue size,
1437 the minimum and maximum thresholds and the mark probability.
1438 An actual drop probability is then computed from the initial drop probability.
1439 The actual drop probability takes the count run-time value into consideration
1440 so that the actual drop probability increases as more packets arrive to the packet queue
1441 since the last packet was dropped.
1443 Initial Packet Drop Probability
1444 """""""""""""""""""""""""""""""
1446 The initial drop probability is calculated using the following equation.
1448 .. image:: img/drop_probability_eq3.*
1452 * *maxp* = mark probability
1454 * *avg* = average queue size
1456 * *minth* = minimum threshold
1458 * *maxth* = maximum threshold
1460 The calculation of the packet drop probability using Equation 3 is illustrated in :numref:`figure_pkt_drop_probability`.
1461 If the average queue size is below the minimum threshold, an arriving packet is enqueued.
1462 If the average queue size is at or above the maximum threshold, an arriving packet is dropped.
1463 If the average queue size is between the minimum and maximum thresholds,
1464 a drop probability is calculated to determine if the packet should be enqueued or dropped.
1466 .. _figure_pkt_drop_probability:
1468 .. figure:: img/pkt_drop_probability.*
1470 Packet Drop Probability for a Given RED Configuration
1473 Actual Drop Probability
1474 """""""""""""""""""""""
1476 If the average queue size is between the minimum and maximum thresholds,
1477 then the actual drop probability is calculated from the following equation.
1479 .. image:: img/drop_probability_eq4.*
1483 * *Pb* = initial drop probability (from Equation 3)
1485 * *count* = number of packets that have arrived since the last drop
1487 The constant 2, in Equation 4 is the only deviation from the drop probability formulae
1488 given in the reference document where a value of 1 is used instead.
1489 It should be noted that the value pa computed from can be negative or greater than 1.
1490 If this is the case, then a value of 1 should be used instead.
1492 The initial and actual drop probabilities are shown in :numref:`figure_drop_probability_graph`.
1493 The actual drop probability is shown for the case where
1494 the formula given in the reference document1 is used (blue curve)
1495 and also for the case where the formula implemented in the dropper module,
1496 is used (red curve).
1497 The formula in the reference document results in a significantly higher drop rate
1498 compared to the mark probability configuration parameter specified by the user.
1499 The choice to deviate from the reference document is simply a design decision and
1500 one that has been taken by other RED implementations, for example, FreeBSD* ALTQ RED.
1502 .. _figure_drop_probability_graph:
1504 .. figure:: img/drop_probability_graph.*
1506 Initial Drop Probability (pb), Actual Drop probability (pa) Computed Using
1507 a Factor 1 (Blue Curve) and a Factor 2 (Red Curve)
1510 .. _Queue_Empty_Operation:
1512 Queue Empty Operation
1513 ~~~~~~~~~~~~~~~~~~~~~
1515 The time at which a packet queue becomes empty must be recorded and saved with the RED run-time data
1516 so that the EWMA filter block can calculate the average queue size on the next enqueue operation.
1517 It is the responsibility of the calling application to inform the dropper module
1518 through the API that a queue has become empty.
1520 Source Files Location
1521 ~~~~~~~~~~~~~~~~~~~~~
1523 The source files for the DPDK dropper are located at:
1525 * DPDK/lib/librte_sched/rte_red.h
1527 * DPDK/lib/librte_sched/rte_red.c
1529 Integration with the DPDK QoS Scheduler
1530 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1532 RED functionality in the DPDK QoS scheduler is disabled by default.
1533 To enable it, use the DPDK configuration parameter:
1537 CONFIG_RTE_SCHED_RED=y
1539 This parameter must be set to y.
1540 The parameter is found in the build configuration files in the DPDK/config directory,
1541 for example, DPDK/config/common_linuxapp.
1542 RED configuration parameters are specified in the rte_red_params structure within the rte_sched_port_params structure
1543 that is passed to the scheduler on initialization.
1544 RED parameters are specified separately for four traffic classes and three packet colors (green, yellow and red)
1545 allowing the scheduler to implement Weighted Random Early Detection (WRED).
1547 Integration with the DPDK QoS Scheduler Sample Application
1548 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1550 The DPDK QoS Scheduler Application reads a configuration file on start-up.
1551 The configuration file includes a section containing RED parameters.
1552 The format of these parameters is described in :ref:`Section2.23.3.1 <Configuration>`.
1553 A sample RED configuration is shown below. In this example, the queue size is 64 packets.
1557 For correct operation, the same EWMA filter weight parameter (wred weight) should be used
1558 for each packet color (green, yellow, red) in the same traffic class (tc).
1562 ; RED params per traffic class and color (Green / Yellow / Red)
1565 tc 0 wred min = 28 22 16
1566 tc 0 wred max = 32 32 32
1567 tc 0 wred inv prob = 10 10 10
1568 tc 0 wred weight = 9 9 9
1570 tc 1 wred min = 28 22 16
1571 tc 1 wred max = 32 32 32
1572 tc 1 wred inv prob = 10 10 10
1573 tc 1 wred weight = 9 9 9
1575 tc 2 wred min = 28 22 16
1576 tc 2 wred max = 32 32 32
1577 tc 2 wred inv prob = 10 10 10
1578 tc 2 wred weight = 9 9 9
1580 tc 3 wred min = 28 22 16
1581 tc 3 wred max = 32 32 32
1582 tc 3 wred inv prob = 10 10 10
1583 tc 3 wred weight = 9 9 9
1585 With this configuration file, the RED configuration that applies to green,
1586 yellow and red packets in traffic class 0 is shown in :numref:`table_qos_18`.
1590 .. table:: RED Configuration Corresponding to RED Configuration File
1592 +--------------------+--------------------+-------+--------+-----+
1593 | RED Parameter | Configuration Name | Green | Yellow | Red |
1595 +====================+====================+=======+========+=====+
1596 | Minimum Threshold | tc 0 wred min | 28 | 22 | 16 |
1598 +--------------------+--------------------+-------+--------+-----+
1599 | Maximum Threshold | tc 0 wred max | 32 | 32 | 32 |
1601 +--------------------+--------------------+-------+--------+-----+
1602 | Mark Probability | tc 0 wred inv prob | 10 | 10 | 10 |
1604 +--------------------+--------------------+-------+--------+-----+
1605 | EWMA Filter Weight | tc 0 wred weight | 9 | 9 | 9 |
1607 +--------------------+--------------------+-------+--------+-----+
1609 Application Programming Interface (API)
1610 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1615 The syntax of the enqueue API is as follows:
1619 int rte_red_enqueue(const struct rte_red_config *red_cfg, struct rte_red *red, const unsigned q, const uint64_t time)
1622 The arguments passed to the enqueue API are configuration data, run-time data,
1623 the current size of the packet queue (in packets) and a value representing the current time.
1624 The time reference is in units of bytes,
1625 where a byte signifies the time duration required by the physical interface to send out a byte on the transmission medium
1626 (see Section 26.2.4.5.1 "Internal Time Reference" ).
1627 The dropper reuses the scheduler time stamps for performance reasons.
1632 The syntax of the empty API is as follows:
1636 void rte_red_mark_queue_empty(struct rte_red *red, const uint64_t time)
1638 The arguments passed to the empty API are run-time data and the current time in bytes.
1643 The traffic metering component implements the Single Rate Three Color Marker (srTCM) and
1644 Two Rate Three Color Marker (trTCM) algorithms, as defined by IETF RFC 2697 and 2698 respectively.
1645 These algorithms meter the stream of incoming packets based on the allowance defined in advance for each traffic flow.
1646 As result, each incoming packet is tagged as green,
1647 yellow or red based on the monitored consumption of the flow the packet belongs to.
1652 The srTCM algorithm defines two token buckets for each traffic flow,
1653 with the two buckets sharing the same token update rate:
1655 * Committed (C) bucket: fed with tokens at the rate defined by the Committed Information Rate (CIR) parameter
1656 (measured in IP packet bytes per second).
1657 The size of the C bucket is defined by the Committed Burst Size (CBS) parameter (measured in bytes);
1659 * Excess (E) bucket: fed with tokens at the same rate as the C bucket.
1660 The size of the E bucket is defined by the Excess Burst Size (EBS) parameter (measured in bytes).
1662 The trTCM algorithm defines two token buckets for each traffic flow,
1663 with the two buckets being updated with tokens at independent rates:
1665 * Committed (C) bucket: fed with tokens at the rate defined by the Committed Information Rate (CIR) parameter
1666 (measured in bytes of IP packet per second).
1667 The size of the C bucket is defined by the Committed Burst Size (CBS) parameter (measured in bytes);
1669 * Peak (P) bucket: fed with tokens at the rate defined by the Peak Information Rate (PIR) parameter
1670 (measured in IP packet bytes per second).
1671 The size of the P bucket is defined by the Peak Burst Size (PBS) parameter (measured in bytes).
1673 Please refer to RFC 2697 (for srTCM) and RFC 2698 (for trTCM) for details on how tokens are consumed
1674 from the buckets and how the packet color is determined.
1676 Color Blind and Color Aware Modes
1677 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1679 For both algorithms, the color blind mode is functionally equivalent to the color aware mode with input color set as green.
1680 For color aware mode, a packet with red input color can only get the red output color,
1681 while a packet with yellow input color can only get the yellow or red output colors.
1683 The reason why the color blind mode is still implemented distinctly than the color aware mode is
1684 that color blind mode can be implemented with fewer operations than the color aware mode.
1686 Implementation Overview
1687 ~~~~~~~~~~~~~~~~~~~~~~~
1689 For each input packet, the steps for the srTCM / trTCM algorithms are:
1691 * Update the C and E / P token buckets. This is done by reading the current time (from the CPU timestamp counter),
1692 identifying the amount of time since the last bucket update and computing the associated number of tokens
1693 (according to the pre-configured bucket rate).
1694 The number of tokens in the bucket is limited by the pre-configured bucket size;
1696 * Identify the output color for the current packet based on the size of the IP packet
1697 and the amount of tokens currently available in the C and E / P buckets; for color aware mode only,
1698 the input color of the packet is also considered.
1699 When the output color is not red, a number of tokens equal to the length of the IP packet are
1700 subtracted from the C or E /P or both buckets, depending on the algorithm and the output color of the packet.