1 .. SPDX-License-Identifier: BSD-3-Clause
2 Copyright(c) 2010-2014 Intel Corporation.
4 Quality of Service (QoS) Framework
5 ==================================
7 This chapter describes the DPDK Quality of Service (QoS) framework.
9 Packet Pipeline with QoS Support
10 --------------------------------
12 An example of a complex packet processing pipeline with QoS support is shown in the following figure.
14 .. _figure_pkt_proc_pipeline_qos:
16 .. figure:: img/pkt_proc_pipeline_qos.*
18 Complex Packet Processing Pipeline with QoS Support
21 This pipeline can be built using reusable DPDK software libraries.
22 The main blocks implementing QoS in this pipeline are: the policer, the dropper and the scheduler.
23 A functional description of each block is provided in the following table.
27 .. table:: Packet Processing Pipeline Implementing QoS
29 +---+------------------------+--------------------------------------------------------------------------------+
30 | # | Block | Functional Description |
32 +===+========================+================================================================================+
33 | 1 | Packet I/O RX & TX | Packet reception/ transmission from/to multiple NIC ports. Poll mode drivers |
34 | | | (PMDs) for Intel 1 GbE/10 GbE NICs. |
36 +---+------------------------+--------------------------------------------------------------------------------+
37 | 2 | Packet parser | Identify the protocol stack of the input packet. Check the integrity of the |
38 | | | packet headers. |
40 +---+------------------------+--------------------------------------------------------------------------------+
41 | 3 | Flow classification | Map the input packet to one of the known traffic flows. Exact match table |
42 | | | lookup using configurable hash function (jhash, CRC and so on) and bucket |
43 | | | logic to handle collisions. |
45 +---+------------------------+--------------------------------------------------------------------------------+
46 | 4 | Policer | Packet metering using srTCM (RFC 2697) or trTCM (RFC2698) algorithms. |
48 +---+------------------------+--------------------------------------------------------------------------------+
49 | 5 | Load Balancer | Distribute the input packets to the application workers. Provide uniform load |
50 | | | to each worker. Preserve the affinity of traffic flows to workers and the |
51 | | | packet order within each flow. |
53 +---+------------------------+--------------------------------------------------------------------------------+
54 | 6 | Worker threads | Placeholders for the customer specific application workload (for example, IP |
55 | | | stack and so on). |
57 +---+------------------------+--------------------------------------------------------------------------------+
58 | 7 | Dropper | Congestion management using the Random Early Detection (RED) algorithm |
59 | | | (specified by the Sally Floyd - Van Jacobson paper) or Weighted RED (WRED). |
60 | | | Drop packets based on the current scheduler queue load level and packet |
61 | | | priority. When congestion is experienced, lower priority packets are dropped |
64 +---+------------------------+--------------------------------------------------------------------------------+
65 | 8 | Hierarchical Scheduler | 5-level hierarchical scheduler (levels are: output port, subport, pipe, |
66 | | | traffic class and queue) with thousands (typically 64K) leaf nodes (queues). |
67 | | | Implements traffic shaping (for subport and pipe levels), strict priority |
68 | | | (for traffic class level) and Weighted Round Robin (WRR) (for queues within |
69 | | | each pipe traffic class). |
71 +---+------------------------+--------------------------------------------------------------------------------+
73 The infrastructure blocks used throughout the packet processing pipeline are listed in the following table.
77 .. table:: Infrastructure Blocks Used by the Packet Processing Pipeline
79 +---+-----------------------+-----------------------------------------------------------------------+
80 | # | Block | Functional Description |
82 +===+=======================+=======================================================================+
83 | 1 | Buffer manager | Support for global buffer pools and private per-thread buffer caches. |
85 +---+-----------------------+-----------------------------------------------------------------------+
86 | 2 | Queue manager | Support for message passing between pipeline blocks. |
88 +---+-----------------------+-----------------------------------------------------------------------+
89 | 3 | Power saving | Support for power saving during low activity periods. |
91 +---+-----------------------+-----------------------------------------------------------------------+
93 The mapping of pipeline blocks to CPU cores is configurable based on the performance level required by each specific application
94 and the set of features enabled for each block.
95 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),
96 while several other blocks could be mapped to the same CPU core.
98 Hierarchical Scheduler
99 ----------------------
101 The hierarchical scheduler block, when present, usually sits on the TX side just before the transmission stage.
102 Its purpose is to prioritize the transmission of packets from different users and different traffic classes
103 according to the policy specified by the Service Level Agreements (SLAs) of each network node.
108 The hierarchical scheduler block is similar to the traffic manager block used by network processors
109 that typically implement per flow (or per group of flows) packet queuing and scheduling.
110 It typically acts like a buffer that is able to temporarily store a large number of packets just before their transmission (enqueue operation);
111 as the NIC TX is requesting more packets for transmission,
112 these packets are later on removed and handed over to the NIC TX with the packet selection logic observing the predefined SLAs (dequeue operation).
114 .. _figure_hier_sched_blk:
116 .. figure:: img/hier_sched_blk.*
118 Hierarchical Scheduler Block Internal Diagram
121 The hierarchical scheduler is optimized for a large number of packet queues.
122 When only a small number of queues are needed, message passing queues should be used instead of this block.
123 See `Worst Case Scenarios for Performance`_ for a more detailed discussion.
128 The scheduling hierarchy is shown in :numref:`figure_sched_hier_per_port`.
129 The first level of the hierarchy is the Ethernet TX port 1/10/40 GbE,
130 with subsequent hierarchy levels defined as subport, pipe, traffic class and queue.
132 Typically, each subport represents a predefined group of users, while each pipe represents an individual user/subscriber.
133 Each traffic class is the representation of a different traffic type with specific loss rate,
134 delay and jitter requirements, such as voice, video or data transfers.
135 Each queue hosts packets from one or multiple connections of the same type belonging to the same user.
137 .. _figure_sched_hier_per_port:
139 .. figure:: img/sched_hier_per_port.*
141 Scheduling Hierarchy per Port
144 The functionality of each hierarchical level is detailed in the following table.
148 .. table:: Port Scheduling Hierarchy
150 +---+--------------------+----------------------------+---------------------------------------------------------------+
151 | # | Level | Siblings per Parent | Functional Description |
153 +===+====================+============================+===============================================================+
154 | 1 | Port | - | #. Output Ethernet port 1/10/40 GbE. |
156 | | | | #. Multiple ports are scheduled in round robin order with |
157 | | | | all ports having equal priority. |
159 +---+--------------------+----------------------------+---------------------------------------------------------------+
160 | 2 | Subport | Configurable (default: 8) | #. Traffic shaping using token bucket algorithm (one token |
161 | | | | bucket per subport). |
163 | | | | #. Upper limit enforced per Traffic Class (TC) at the |
164 | | | | subport level. |
166 | | | | #. Lower priority TCs able to reuse subport bandwidth |
167 | | | | currently unused by higher priority TCs. |
169 +---+--------------------+----------------------------+---------------------------------------------------------------+
170 | 3 | Pipe | Configurable (default: 4K) | #. Traffic shaping using the token bucket algorithm (one |
171 | | | | token bucket per pipe. |
173 +---+--------------------+----------------------------+---------------------------------------------------------------+
174 | 4 | Traffic Class (TC) | 4 | #. TCs of the same pipe handled in strict priority order. |
176 | | | | #. Upper limit enforced per TC at the pipe level. |
178 | | | | #. Lower priority TCs able to reuse pipe bandwidth currently |
179 | | | | unused by higher priority TCs. |
181 | | | | #. When subport TC is oversubscribed (configuration time |
182 | | | | event), pipe TC upper limit is capped to a dynamically |
183 | | | | adjusted value that is shared by all the subport pipes. |
185 +---+--------------------+----------------------------+---------------------------------------------------------------+
186 | 5 | Queue | 4 | #. Queues of the same TC are serviced using Weighted Round |
187 | | | | Robin (WRR) according to predefined weights. |
189 +---+--------------------+----------------------------+---------------------------------------------------------------+
191 Application Programming Interface (API)
192 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
194 Port Scheduler Configuration API
195 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
197 The rte_sched.h file contains configuration functions for port, subport and pipe.
199 Port Scheduler Enqueue API
200 ^^^^^^^^^^^^^^^^^^^^^^^^^^
202 The port scheduler enqueue API is very similar to the API of the DPDK PMD TX function.
206 int rte_sched_port_enqueue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts);
208 Port Scheduler Dequeue API
209 ^^^^^^^^^^^^^^^^^^^^^^^^^^
211 The port scheduler dequeue API is very similar to the API of the DPDK PMD RX function.
215 int rte_sched_port_dequeue(struct rte_sched_port *port, struct rte_mbuf **pkts, uint32_t n_pkts);
222 /* File "application.c" */
226 #define NIC_RX_PORT 0
227 #define NIC_RX_QUEUE 0
228 #define NIC_TX_PORT 1
229 #define NIC_TX_QUEUE 0
231 struct rte_sched_port *port = NULL;
232 struct rte_mbuf *pkts_rx[N_PKTS_RX], *pkts_tx[N_PKTS_TX];
233 uint32_t n_pkts_rx, n_pkts_tx;
237 <initialization code>
241 /* Read packets from NIC RX queue */
243 n_pkts_rx = rte_eth_rx_burst(NIC_RX_PORT, NIC_RX_QUEUE, pkts_rx, N_PKTS_RX);
245 /* Hierarchical scheduler enqueue */
247 rte_sched_port_enqueue(port, pkts_rx, n_pkts_rx);
249 /* Hierarchical scheduler dequeue */
251 n_pkts_tx = rte_sched_port_dequeue(port, pkts_tx, N_PKTS_TX);
253 /* Write packets to NIC TX queue */
255 rte_eth_tx_burst(NIC_TX_PORT, NIC_TX_QUEUE, pkts_tx, n_pkts_tx);
261 Internal Data Structures per Port
262 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
264 A schematic of the internal data structures in shown in with details in.
266 .. _figure_data_struct_per_port:
268 .. figure:: img/data_struct_per_port.*
270 Internal Data Structures per Port
275 .. table:: Scheduler Internal Data Structures per Port
277 +---+----------------------+-------------------------+---------------------+------------------------------+---------------------------------------------------+
278 | # | Data structure | Size (bytes) | # per port | Access type | Description |
280 | | | | +-------------+----------------+---------------------------------------------------+
281 | | | | | Enq | Deq | |
283 +===+======================+=========================+=====================+=============+================+===================================================+
284 | 1 | Subport table entry | 64 | # subports per port | - | Rd, Wr | Persistent subport data (credits, etc). |
286 +---+----------------------+-------------------------+---------------------+-------------+----------------+---------------------------------------------------+
287 | 2 | Pipe table entry | 64 | # pipes per port | - | Rd, Wr | Persistent data for pipe, its TCs and its queues |
288 | | | | | | | (credits, etc) that is updated during run-time. |
290 | | | | | | | The pipe configuration parameters do not change |
291 | | | | | | | during run-time. The same pipe configuration |
292 | | | | | | | parameters are shared by multiple pipes, |
293 | | | | | | | therefore they are not part of pipe table entry. |
295 +---+----------------------+-------------------------+---------------------+-------------+----------------+---------------------------------------------------+
296 | 3 | Queue table entry | 4 | #queues per port | Rd, Wr | Rd, Wr | Persistent queue data (read and write pointers). |
297 | | | | | | | The queue size is the same per TC for all queues, |
298 | | | | | | | allowing the queue base address to be computed |
299 | | | | | | | using a fast formula, so these two parameters are |
300 | | | | | | | not part of queue table entry. |
302 | | | | | | | The queue table entries for any given pipe are |
303 | | | | | | | stored in the same cache line. |
305 +---+----------------------+-------------------------+---------------------+-------------+----------------+---------------------------------------------------+
306 | 4 | Queue storage area | Config (default: 64 x8) | # queues per port | Wr | Rd | Array of elements per queue; each element is 8 |
307 | | | | | | | byte in size (mbuf pointer). |
309 +---+----------------------+-------------------------+---------------------+-------------+----------------+---------------------------------------------------+
310 | 5 | Active queues bitmap | 1 bit per queue | 1 | Wr (Set) | Rd, Wr (Clear) | The bitmap maintains one status bit per queue: |
311 | | | | | | | queue not active (queue is empty) or queue active |
312 | | | | | | | (queue is not empty). |
314 | | | | | | | Queue bit is set by the scheduler enqueue and |
315 | | | | | | | cleared by the scheduler dequeue when queue |
316 | | | | | | | becomes empty. |
318 | | | | | | | Bitmap scan operation returns the next non-empty |
319 | | | | | | | pipe and its status (16-bit mask of active queue |
320 | | | | | | | in the pipe). |
322 +---+----------------------+-------------------------+---------------------+-------------+----------------+---------------------------------------------------+
323 | 6 | Grinder | ~128 | Config (default: 8) | - | Rd, Wr | Short list of active pipes currently under |
324 | | | | | | | processing. The grinder contains temporary data |
325 | | | | | | | during pipe processing. |
327 | | | | | | | Once the current pipe exhausts packets or |
328 | | | | | | | credits, it is replaced with another active pipe |
329 | | | | | | | from the bitmap. |
331 +---+----------------------+-------------------------+---------------------+-------------+----------------+---------------------------------------------------+
333 Multicore Scaling Strategy
334 ^^^^^^^^^^^^^^^^^^^^^^^^^^
336 The multicore scaling strategy is:
338 #. Running different physical ports on different threads. The enqueue and dequeue of the same port are run by the same thread.
340 #. Splitting the same physical port to different threads by running different sets of subports of the same physical port (virtual ports) on different threads.
341 Similarly, a subport can be split into multiple subports that are each run by a different thread.
342 The enqueue and dequeue of the same port are run by the same thread.
343 This is only required if, for performance reasons, it is not possible to handle a full port with a single core.
345 Enqueue and Dequeue for the Same Output Port
346 """"""""""""""""""""""""""""""""""""""""""""
348 Running enqueue and dequeue operations for the same output port from different cores is likely to cause significant impact on scheduler's performance
349 and it is therefore not recommended.
351 The port enqueue and dequeue operations share access to the following data structures:
353 #. Packet descriptors
357 #. Queue storage area
359 #. Bitmap of active queues
361 The expected drop in performance is due to:
363 #. Need to make the queue and bitmap operations thread safe,
364 which requires either using locking primitives for access serialization (for example, spinlocks/ semaphores) or
365 using atomic primitives for lockless access (for example, Test and Set, Compare And Swap, an so on).
366 The impact is much higher in the former case.
368 #. Ping-pong of cache lines storing the shared data structures between the cache hierarchies of the two cores
369 (done transparently by the MESI protocol cache coherency CPU hardware).
371 Therefore, the scheduler enqueue and dequeue operations have to be run from the same thread,
372 which allows the queues and the bitmap operations to be non-thread safe and
373 keeps the scheduler data structures internal to the same core.
378 Scaling up the number of NIC ports simply requires a proportional increase in the number of CPU cores to be used for traffic scheduling.
383 The sequence of steps per packet:
385 #. *Access* the mbuf to read the data fields required to identify the destination queue for the packet.
386 These fields are: port, subport, traffic class and queue within traffic class, and are typically set by the classification stage.
388 #. *Access* the queue structure to identify the write location in the queue array.
389 If the queue is full, then the packet is discarded.
391 #. *Access* the queue array location to store the packet (i.e. write the mbuf pointer).
393 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,
394 which prevents the processor out of order execution engine to provide any significant performance optimizations.
396 Given the high rate of input packets and the large amount of queues,
397 it is expected that the data structures accessed to enqueue the current packet are not present
398 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.
399 A number of 3 L1/L2 cache misses per packet is not acceptable for performance reasons.
401 The workaround is to prefetch the required data structures in advance. The prefetch operation has an execution latency during which
402 the processor should not attempt to access the data structure currently under prefetch, so the processor should execute other work.
403 The only other work available is to execute different stages of the enqueue sequence of operations on other input packets,
404 thus resulting in a pipelined implementation for the enqueue operation.
406 :numref:`figure_prefetch_pipeline` illustrates a pipelined implementation for the enqueue operation with 4 pipeline stages and each stage executing 2 different input packets.
407 No input packet can be part of more than one pipeline stage at a given time.
409 .. _figure_prefetch_pipeline:
411 .. figure:: img/prefetch_pipeline.*
413 Prefetch Pipeline for the Hierarchical Scheduler Enqueue Operation
416 The congestion management scheme implemented by the enqueue pipeline described above is very basic:
417 packets are enqueued until a specific queue becomes full,
418 then all the packets destined to the same queue are dropped until packets are consumed (by the dequeue operation).
419 This can be improved by enabling RED/WRED as part of the enqueue pipeline which looks at the queue occupancy and
420 packet priority in order to yield the enqueue/drop decision for a specific packet
421 (as opposed to enqueuing all packets / dropping all packets indiscriminately).
423 Dequeue State Machine
424 ^^^^^^^^^^^^^^^^^^^^^
426 The sequence of steps to schedule the next packet from the current pipe is:
428 #. Identify the next active pipe using the bitmap scan operation, *prefetch* pipe.
430 #. *Read* pipe data structure. Update the credits for the current pipe and its subport.
431 Identify the first active traffic class within the current pipe, select the next queue using WRR,
432 *prefetch* queue pointers for all the 16 queues of the current pipe.
434 #. *Read* next element from the current WRR queue and *prefetch* its packet descriptor.
436 #. *Read* the packet length from the packet descriptor (mbuf structure).
437 Based on the packet length and the available credits (of current pipe, pipe traffic class, subport and subport traffic class),
438 take the go/no go scheduling decision for the current packet.
440 To avoid the cache misses, the above data structures (pipe, queue, queue array, mbufs) are prefetched in advance of being accessed.
441 The strategy of hiding the latency of the prefetch operations is to switch from the current pipe (in grinder A) to another pipe
442 (in grinder B) immediately after a prefetch is issued for the current pipe.
443 This gives enough time to the prefetch operation to complete before the execution switches back to this pipe (in grinder A).
445 The dequeue pipe state machine exploits the data presence into the processor cache,
446 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
447 moving to the next active TC from the same pipe (if any) or to another active pipe.
449 .. _figure_pipe_prefetch_sm:
451 .. figure:: img/pipe_prefetch_sm.*
453 Pipe Prefetch State Machine for the Hierarchical Scheduler Dequeue
457 Timing and Synchronization
458 ^^^^^^^^^^^^^^^^^^^^^^^^^^
460 The output port is modeled as a conveyor belt of byte slots that need to be filled by the scheduler with data for transmission.
461 For 10 GbE, there are 1.25 billion byte slots that need to be filled by the port scheduler every second.
462 If the scheduler is not fast enough to fill the slots, provided that enough packets and credits exist,
463 then some slots will be left unused and bandwidth will be wasted.
465 In principle, the hierarchical scheduler dequeue operation should be triggered by NIC TX.
466 Usually, once the occupancy of the NIC TX input queue drops below a predefined threshold,
467 the port scheduler is woken up (interrupt based or polling based,
468 by continuously monitoring the queue occupancy) to push more packets into the queue.
470 Internal Time Reference
471 """""""""""""""""""""""
473 The scheduler needs to keep track of time advancement for the credit logic,
474 which requires credit updates based on time (for example, subport and pipe traffic shaping, traffic class upper limit enforcement, and so on).
476 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.
477 Therefore, it is convenient to keep the internal time reference in units of bytes,
478 where a byte signifies the time duration required by the physical interface to send out a byte on the transmission medium.
479 This way, as a packet is scheduled for transmission, the time is incremented with (n + h),
480 where n is the packet length in bytes and h is the number of framing overhead bytes per packet.
482 Internal Time Reference Re-synchronization
483 """"""""""""""""""""""""""""""""""""""""""
485 The scheduler needs to align its internal time reference to the pace of the port conveyor belt.
486 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
487 (by the scheduler, due to the NIC TX input queue being full, or later on, internally by the NIC TX).
489 The scheduler reads the current time on every dequeue invocation.
490 The CPU time stamp can be obtained by reading either the Time Stamp Counter (TSC) register or the High Precision Event Timer (HPET) register.
491 The current CPU time stamp is converted from number of CPU clocks to number of bytes:
492 *time_bytes = time_cycles / cycles_per_byte, where cycles_per_byte*
493 is the amount of CPU cycles that is equivalent to the transmission time for one byte on the wire
494 (e.g. for a CPU frequency of 2 GHz and a 10GbE port,*cycles_per_byte = 1.6*).
496 The scheduler maintains an internal time reference of the NIC time.
497 Whenever a packet is scheduled, the NIC time is incremented with the packet length (including framing overhead).
498 On every dequeue invocation, the scheduler checks its internal reference of the NIC time against the current time:
500 #. If NIC time is in the future (NIC time >= current time), no adjustment of NIC time is needed.
501 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;
503 #. If NIC time is in the past (NIC time < current time), then NIC time should be adjusted by setting it to the current time.
504 This means that the scheduler is not able to keep up with the speed of the NIC byte conveyor belt,
505 so NIC bandwidth is wasted due to poor packet supply to the NIC TX.
507 Scheduler Accuracy and Granularity
508 """"""""""""""""""""""""""""""""""
510 The scheduler round trip delay (SRTD) is the time (number of CPU cycles) between two consecutive examinations of the same pipe by the scheduler.
512 To keep up with the output port (that is, avoid bandwidth loss),
513 the scheduler should be able to schedule n packets faster than the same n packets are transmitted by NIC TX.
515 The scheduler needs to keep up with the rate of each individual pipe,
516 as configured for the pipe token bucket, assuming that no port oversubscription is taking place.
517 This means that the size of the pipe token bucket should be set high enough to prevent it from overflowing due to big SRTD,
518 as this would result in credit loss (and therefore bandwidth loss) for the pipe.
526 The scheduling decision to send next packet from (subport S, pipe P, traffic class TC, queue Q) is favorable (packet is sent)
527 when all the conditions below are met:
529 * Pipe P of subport S is currently selected by one of the port grinders;
531 * Traffic class TC is the highest priority active traffic class of pipe P;
533 * Queue Q is the next queue selected by WRR within traffic class TC of pipe P;
535 * Subport S has enough credits to send the packet;
537 * Subport S has enough credits for traffic class TC to send the packet;
539 * Pipe P has enough credits to send the packet;
541 * Pipe P has enough credits for traffic class TC to send the packet.
543 If all the above conditions are met,
544 then the packet is selected for transmission and the necessary credits are subtracted from subport S,
545 subport S traffic class TC, pipe P, pipe P traffic class TC.
550 As the greatest common divisor for all packet lengths is one byte, the unit of credit is selected as one byte.
551 The number of credits required for the transmission of a packet of n bytes is equal to (n+h),
552 where h is equal to the number of framing overhead bytes per packet.
556 .. table:: Ethernet Frame Overhead Fields
558 +---+--------------------------------+----------------+---------------------------------------------------------------------------+
559 | # | Packet field | Length (bytes) | Comments |
561 +===+================================+================+===========================================================================+
562 | 1 | Preamble | 7 | |
564 +---+--------------------------------+----------------+---------------------------------------------------------------------------+
565 | 2 | Start of Frame Delimiter (SFD) | 1 | |
567 +---+--------------------------------+----------------+---------------------------------------------------------------------------+
568 | 3 | Frame Check Sequence (FCS) | 4 | Considered overhead only if not included in the mbuf packet length field. |
570 +---+--------------------------------+----------------+---------------------------------------------------------------------------+
571 | 4 | Inter Frame Gap (IFG) | 12 | |
573 +---+--------------------------------+----------------+---------------------------------------------------------------------------+
576 +---+--------------------------------+----------------+---------------------------------------------------------------------------+
581 The traffic shaping for subport and pipe is implemented using a token bucket per subport/per pipe.
582 Each token bucket is implemented using one saturated counter that keeps track of the number of available credits.
584 The token bucket generic parameters and operations are presented in :numref:`table_qos_6` and :numref:`table_qos_7`.
588 .. table:: Token Bucket Generic Parameters
590 +---+------------------------+--------------------+---------------------------------------------------------+
591 | # | Token Bucket Parameter | Unit | Description |
593 +===+========================+====================+=========================================================+
594 | 1 | bucket_rate | Credits per second | Rate of adding credits to the bucket. |
596 +---+------------------------+--------------------+---------------------------------------------------------+
597 | 2 | bucket_size | Credits | Max number of credits that can be stored in the bucket. |
599 +---+------------------------+--------------------+---------------------------------------------------------+
603 .. table:: Token Bucket Generic Operations
605 +---+------------------------+------------------------------------------------------------------------------+
606 | # | Token Bucket Operation | Description |
608 +===+========================+==============================================================================+
609 | 1 | Initialization | Bucket set to a predefined value, e.g. zero or half of the bucket size. |
611 +---+------------------------+------------------------------------------------------------------------------+
612 | 2 | Credit update | Credits are added to the bucket on top of existing ones, either periodically |
613 | | | or on demand, based on the bucket_rate. Credits cannot exceed the upper |
614 | | | limit defined by the bucket_size, so any credits to be added to the bucket |
615 | | | while the bucket is full are dropped. |
617 +---+------------------------+------------------------------------------------------------------------------+
618 | 3 | Credit consumption | As result of packet scheduling, the necessary number of credits is removed |
619 | | | from the bucket. The packet can only be sent if enough credits are in the |
620 | | | bucket to send the full packet (packet bytes and framing overhead for the |
623 +---+------------------------+------------------------------------------------------------------------------+
625 To implement the token bucket generic operations described above,
626 the current design uses the persistent data structure presented in :numref:`table_qos_8`,
627 while the implementation of the token bucket operations is described in :numref:`table_qos_9`.
631 .. table:: Token Bucket Persistent Data Structure
633 +---+------------------------+-------+----------------------------------------------------------------------+
634 | # | Token bucket field | Unit | Description |
636 +===+========================+=======+======================================================================+
637 | 1 | tb_time | Bytes | Time of the last credit update. Measured in bytes instead of seconds |
638 | | | | or CPU cycles for ease of credit consumption operation |
639 | | | | (as the current time is also maintained in bytes). |
641 | | | | See Section 26.2.4.5.1 "Internal Time Reference" for an |
642 | | | | explanation of why the time is maintained in byte units. |
644 +---+------------------------+-------+----------------------------------------------------------------------+
645 | 2 | tb_period | Bytes | Time period that should elapse since the last credit update in order |
646 | | | | for the bucket to be awarded tb_credits_per_period worth or credits. |
648 +---+------------------------+-------+----------------------------------------------------------------------+
649 | 3 | tb_credits_per_period | Bytes | Credit allowance per tb_period. |
651 +---+------------------------+-------+----------------------------------------------------------------------+
652 | 4 | tb_size | Bytes | Bucket size, i.e. upper limit for the tb_credits. |
654 +---+------------------------+-------+----------------------------------------------------------------------+
655 | 5 | tb_credits | Bytes | Number of credits currently in the bucket. |
657 +---+------------------------+-------+----------------------------------------------------------------------+
659 The bucket rate (in bytes per second) can be computed with the following formula:
661 *bucket_rate = (tb_credits_per_period / tb_period) * r*
663 where, r = port line rate (in bytes per second).
667 .. table:: Token Bucket Operations
669 +---+-------------------------+-----------------------------------------------------------------------------+
670 | # | Token bucket operation | Description |
672 +===+=========================+=============================================================================+
673 | 1 | Initialization | *tb_credits = 0; or tb_credits = tb_size / 2;* |
675 +---+-------------------------+-----------------------------------------------------------------------------+
676 | 2 | Credit update | Credit update options: |
678 | | | * Every time a packet is sent for a port, update the credits of all the |
679 | | | the subports and pipes of that port. Not feasible. |
681 | | | * Every time a packet is sent, update the credits for the pipe and |
682 | | | subport. Very accurate, but not needed (a lot of calculations). |
684 | | | * Every time a pipe is selected (that is, picked by one |
685 | | | of the grinders), update the credits for the pipe and its subport. |
687 | | | The current implementation is using option 3. According to Section |
688 | | | `Dequeue State Machine`_, the pipe and subport credits are |
689 | | | updated every time a pipe is selected by the dequeue process before the |
690 | | | pipe and subport credits are actually used. |
692 | | | The implementation uses a tradeoff between accuracy and speed by updating |
693 | | | the bucket credits only when at least a full *tb_period* has elapsed since |
694 | | | the last update. |
696 | | | * Full accuracy can be achieved by selecting the value for *tb_period* |
697 | | | for which *tb_credits_per_period = 1*. |
699 | | | * When full accuracy is not required, better performance is achieved by |
700 | | | setting *tb_credits* to a larger value. |
702 | | | Update operations: |
704 | | | * n_periods = (time - tb_time) / tb_period; |
706 | | | * tb_credits += n_periods * tb_credits_per_period; |
708 | | | * tb_credits = min(tb_credits, tb_size); |
710 | | | * tb_time += n_periods * tb_period; |
712 +---+-------------------------+-----------------------------------------------------------------------------+
713 | 3 | Credit consumption | As result of packet scheduling, the necessary number of credits is removed |
714 | | (on packet scheduling) | from the bucket. The packet can only be sent if enough credits are in the |
715 | | | bucket to send the full packet (packet bytes and framing overhead for the |
718 | | | Scheduling operations: |
720 | | | pkt_credits = pkt_len + frame_overhead; |
721 | | | if (tb_credits >= pkt_credits){tb_credits -= pkt_credits;} |
723 +---+-------------------------+-----------------------------------------------------------------------------+
728 Implementation of Strict Priority Scheduling
729 ''''''''''''''''''''''''''''''''''''''''''''
731 Strict priority scheduling of traffic classes within the same pipe is implemented by the pipe dequeue state machine,
732 which selects the queues in ascending order.
733 Therefore, queues 0..3 (associated with TC 0, highest priority TC) are handled before
734 queues 4..7 (TC 1, lower priority than TC 0),
735 which are handled before queues 8..11 (TC 2),
736 which are handled before queues 12..15 (TC 3, lowest priority TC).
738 Upper Limit Enforcement
739 '''''''''''''''''''''''
741 The traffic classes at the pipe and subport levels are not traffic shaped,
742 so there is no token bucket maintained in this context.
743 The upper limit for the traffic classes at the subport and
744 pipe levels is enforced by periodically refilling the subport / pipe traffic class credit counter,
745 out of which credits are consumed every time a packet is scheduled for that subport / pipe,
746 as described in :numref:`table_qos_10` and :numref:`table_qos_11`.
750 .. table:: Subport/Pipe Traffic Class Upper Limit Enforcement Persistent Data Structure
752 +---+-----------------------+-------+-----------------------------------------------------------------------+
753 | # | Subport or pipe field | Unit | Description |
755 +===+=======================+=======+=======================================================================+
756 | 1 | tc_time | Bytes | Time of the next update (upper limit refill) for the 4 TCs of the |
757 | | | | current subport / pipe. |
759 | | | | See Section `Internal Time Reference`_ for the |
760 | | | | explanation of why the time is maintained in byte units. |
762 +---+-----------------------+-------+-----------------------------------------------------------------------+
763 | 2 | tc_period | Bytes | Time between two consecutive updates for the 4 TCs of the current |
764 | | | | subport / pipe. This is expected to be many times bigger than the |
765 | | | | typical value of the token bucket tb_period. |
767 +---+-----------------------+-------+-----------------------------------------------------------------------+
768 | 3 | tc_credits_per_period | Bytes | Upper limit for the number of credits allowed to be consumed by the |
769 | | | | current TC during each enforcement period tc_period. |
771 +---+-----------------------+-------+-----------------------------------------------------------------------+
772 | 4 | tc_credits | Bytes | Current upper limit for the number of credits that can be consumed by |
773 | | | | the current traffic class for the remainder of the current |
774 | | | | enforcement period. |
776 +---+-----------------------+-------+-----------------------------------------------------------------------+
780 .. table:: Subport/Pipe Traffic Class Upper Limit Enforcement Operations
782 +---+--------------------------+----------------------------------------------------------------------------+
783 | # | Traffic Class Operation | Description |
785 +===+==========================+============================================================================+
786 | 1 | Initialization | tc_credits = tc_credits_per_period; |
788 | | | tc_time = tc_period; |
790 +---+--------------------------+----------------------------------------------------------------------------+
791 | 2 | Credit update | Update operations: |
793 | | | if (time >= tc_time) { |
795 | | | tc_credits = tc_credits_per_period; |
797 | | | tc_time = time + tc_period; |
801 +---+--------------------------+----------------------------------------------------------------------------+
802 | 3 | Credit consumption | As result of packet scheduling, the TC limit is decreased with the |
803 | | (on packet scheduling) | necessary number of credits. The packet can only be sent if enough credits |
804 | | | are currently available in the TC limit to send the full packet |
805 | | | (packet bytes and framing overhead for the packet). |
807 | | | Scheduling operations: |
809 | | | pkt_credits = pk_len + frame_overhead; |
811 | | | if (tc_credits >= pkt_credits) {tc_credits -= pkt_credits;} |
813 +---+--------------------------+----------------------------------------------------------------------------+
815 Weighted Round Robin (WRR)
816 """"""""""""""""""""""""""
818 The evolution of the WRR design solution from simple to complex is shown in :numref:`table_qos_12`.
822 .. table:: Weighted Round Robin (WRR)
824 +---+------------+-----------------+-------------+----------------------------------------------------------+
825 | # | All Queues | Equal Weights | All Packets | Strategy |
826 | | Active? | for All Queues? | Equal? | |
827 +===+============+=================+=============+==========================================================+
828 | 1 | Yes | Yes | Yes | **Byte level round robin** |
830 | | | | | *Next queue* queue #i, i = *(i + 1) % n* |
832 +---+------------+-----------------+-------------+----------------------------------------------------------+
833 | 2 | Yes | Yes | No | **Packet level round robin** |
835 | | | | | Consuming one byte from queue #i requires consuming |
836 | | | | | exactly one token for queue #i. |
838 | | | | | T(i) = Accumulated number of tokens previously consumed |
839 | | | | | from queue #i. Every time a packet is consumed from |
840 | | | | | queue #i, T(i) is updated as: T(i) += *pkt_len*. |
842 | | | | | *Next queue* : queue with the smallest T. |
845 +---+------------+-----------------+-------------+----------------------------------------------------------+
846 | 3 | Yes | No | No | **Packet level weighted round robin** |
848 | | | | | This case can be reduced to the previous case by |
849 | | | | | introducing a cost per byte that is different for each |
850 | | | | | queue. Queues with lower weights have a higher cost per |
851 | | | | | byte. This way, it is still meaningful to compare the |
852 | | | | | consumption amongst different queues in order to select |
853 | | | | | the next queue. |
855 | | | | | w(i) = Weight of queue #i |
857 | | | | | t(i) = Tokens per byte for queue #i, defined as the |
858 | | | | | inverse weight of queue #i. |
859 | | | | | For example, if w[0..3] = [1:2:4:8], |
860 | | | | | then t[0..3] = [8:4:2:1]; if w[0..3] = [1:4:15:20], |
861 | | | | | then t[0..3] = [60:15:4:3]. |
862 | | | | | Consuming one byte from queue #i requires consuming t(i) |
863 | | | | | tokens 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 * t(i)*. |
868 | | | | | *Next queue* : queue with the smallest T. |
870 +---+------------+-----------------+-------------+----------------------------------------------------------+
871 | 4 | No | No | No | **Packet level weighted round robin with variable queue |
874 | | | | | Reduce this case to the previous case by setting the |
875 | | | | | consumption of inactive queues to a high number, so that |
876 | | | | | the inactive queues will never be selected by the |
877 | | | | | smallest T logic. |
879 | | | | | To prevent T from overflowing as result of successive |
880 | | | | | accumulations, T(i) is truncated after each packet |
881 | | | | | consumption for all queues. |
882 | | | | | For example, T[0..3] = [1000, 1100, 1200, 1300] |
883 | | | | | is truncated to T[0..3] = [0, 100, 200, 300] |
884 | | | | | by subtracting the min T from T(i), i = 0..n. |
886 | | | | | This requires having at least one active queue in the |
887 | | | | | set of input queues, which is guaranteed by the dequeue |
888 | | | | | state machine never selecting an inactive traffic class. |
890 | | | | | *mask(i) = Saturation mask for queue #i, defined as:* |
892 | | | | | mask(i) = (queue #i is active)? 0 : 0xFFFFFFFF; |
894 | | | | | w(i) = Weight of queue #i |
896 | | | | | t(i) = Tokens per byte for queue #i, defined as the |
897 | | | | | inverse weight of queue #i. |
899 | | | | | T(i) = Accumulated numbers of tokens previously consumed |
900 | | | | | from queue #i. |
902 | | | | | *Next queue* : queue with smallest T. |
904 | | | | | Before packet consumption from queue #i: |
906 | | | | | *T(i) |= mask(i)* |
908 | | | | | After packet consumption from queue #i: |
910 | | | | | T(j) -= T(i), j != i |
912 | | | | | T(i) = pkt_len * t(i) |
914 | | | | | Note: T(j) uses the T(i) value before T(i) is updated. |
916 +---+------------+-----------------+-------------+----------------------------------------------------------+
918 Subport Traffic Class Oversubscription
919 """"""""""""""""""""""""""""""""""""""
924 Oversubscription for subport traffic class X is a configuration-time event that occurs when
925 more bandwidth is allocated for traffic class X at the level of subport member pipes than
926 allocated for the same traffic class at the parent subport level.
928 The existence of the oversubscription for a specific subport and
929 traffic class is solely the result of pipe and
930 subport-level configuration as opposed to being created due
931 to dynamic evolution of the traffic load at run-time (as congestion is).
933 When the overall demand for traffic class X for the current subport is low,
934 the existence of the oversubscription condition does not represent a problem,
935 as demand for traffic class X is completely satisfied for all member pipes.
936 However, this can no longer be achieved when the aggregated demand for traffic class X
937 for all subport member pipes exceeds the limit configured at the subport level.
942 summarizes some of the possible approaches for handling this problem,
943 with the third approach selected for implementation.
947 .. table:: Subport Traffic Class Oversubscription
949 +-----+---------------------------+-------------------------------------------------------------------------+
950 | No. | Approach | Description |
952 +=====+===========================+=========================================================================+
953 | 1 | Don't care | First come, first served. |
955 | | | This approach is not fair amongst subport member pipes, as pipes that |
956 | | | are served first will use up as much bandwidth for TC X as they need, |
957 | | | while pipes that are served later will receive poor service due to |
958 | | | bandwidth for TC X at the subport level being scarce. |
960 +-----+---------------------------+-------------------------------------------------------------------------+
961 | 2 | Scale down all pipes | All pipes within the subport have their bandwidth limit for TC X scaled |
962 | | | down by the same factor. |
964 | | | This approach is not fair among subport member pipes, as the low end |
965 | | | pipes (that is, pipes configured with low bandwidth) can potentially |
966 | | | experience severe service degradation that might render their service |
967 | | | unusable (if available bandwidth for these pipes drops below the |
968 | | | minimum requirements for a workable service), while the service |
969 | | | degradation for high end pipes might not be noticeable at all. |
971 +-----+---------------------------+-------------------------------------------------------------------------+
972 | 3 | Cap the high demand pipes | Each subport member pipe receives an equal share of the bandwidth |
973 | | | available at run-time for TC X at the subport level. Any bandwidth left |
974 | | | unused by the low-demand pipes is redistributed in equal portions to |
975 | | | the high-demand pipes. This way, the high-demand pipes are truncated |
976 | | | while the low-demand pipes are not impacted. |
978 +-----+---------------------------+-------------------------------------------------------------------------+
980 Typically, the subport TC oversubscription feature is enabled only for the lowest priority traffic class (TC 3),
981 which is typically used for best effort traffic,
982 with the management plane preventing this condition from occurring for the other (higher priority) traffic classes.
984 To ease implementation, it is also assumed that the upper limit for subport TC 3 is set to 100% of the subport rate,
985 and that the upper limit for pipe TC 3 is set to 100% of pipe rate for all subport member pipes.
987 Implementation Overview
988 '''''''''''''''''''''''
990 The algorithm computes a watermark, which is periodically updated based on the current demand experienced by the subport member pipes,
991 whose purpose is to limit the amount of traffic that each pipe is allowed to send for TC 3.
992 The watermark is computed at the subport level at the beginning of each traffic class upper limit enforcement period and
993 the same value is used by all the subport member pipes throughout the current enforcement period.
994 illustrates how the watermark computed as subport level at the beginning of each period is propagated to all subport member pipes.
996 At the beginning of the current enforcement period (which coincides with the end of the previous enforcement period),
997 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
998 was not left unused by the subport member pipes at the end of the previous period.
1000 If there was subport TC 3 bandwidth left unused,
1001 the value of the watermark for the current period is increased to encourage the subport member pipes to consume more bandwidth.
1002 Otherwise, the value of the watermark is decreased to enforce equality of bandwidth consumption among subport member pipes for TC 3.
1004 The increase or decrease in the watermark value is done in small increments,
1005 so several enforcement periods might be required to reach the equilibrium state.
1006 This state can change at any moment due to variations in the demand experienced by the subport member pipes for TC 3, for example,
1007 as a result of demand increase (when the watermark needs to be lowered) or demand decrease (when the watermark needs to be increased).
1009 When demand is low, the watermark is set high to prevent it from impeding the subport member pipes from consuming more bandwidth.
1010 The highest value for the watermark is picked as the highest rate configured for a subport member pipe.
1011 :numref:`table_qos_14` and :numref:`table_qos_15` illustrates the watermark operation.
1015 .. table:: Watermark Propagation from Subport Level to Member Pipes at the Beginning of Each Traffic Class Upper Limit Enforcement Period
1017 +-----+---------------------------------+----------------------------------------------------+
1018 | No. | Subport Traffic Class Operation | Description |
1020 +=====+=================================+====================================================+
1021 | 1 | Initialization | **Subport level**: subport_period_id= 0 |
1023 | | | **Pipe level**: pipe_period_id = 0 |
1025 +-----+---------------------------------+----------------------------------------------------+
1026 | 2 | Credit update | **Subport Level**: |
1028 | | | if (time>=subport_tc_time) |
1031 | | | subport_wm = water_mark_update(); |
1033 | | | subport_tc_time = time + subport_tc_period; |
1035 | | | subport_period_id++; |
1039 | | | **Pipelevel:** |
1041 | | | if(pipe_period_id != subport_period_id) |
1045 | | | pipe_ov_credits = subport_wm \* pipe_weight; |
1047 | | | pipe_period_id = subport_period_id; |
1051 +-----+---------------------------------+----------------------------------------------------+
1052 | 3 | Credit consumption | **Pipe level:** |
1053 | | (on packet scheduling) | |
1054 | | | pkt_credits = pk_len + frame_overhead; |
1056 | | | if(pipe_ov_credits >= pkt_credits{ |
1058 | | | pipe_ov_credits -= pkt_credits; |
1062 +-----+---------------------------------+----------------------------------------------------+
1066 .. table:: Watermark Calculation
1068 +-----+------------------+----------------------------------------------------------------------------------+
1069 | No. | Subport Traffic | Description |
1070 | | Class Operation | |
1071 +=====+==================+==================================================================================+
1072 | 1 | Initialization | **Subport level:** |
1076 +-----+------------------+----------------------------------------------------------------------------------+
1077 | 2 | Credit update | **Subport level (water_mark_update):** |
1079 | | | tc0_cons = subport_tc0_credits_per_period - subport_tc0_credits; |
1081 | | | tc1_cons = subport_tc1_credits_per_period - subport_tc1_credits; |
1083 | | | tc2_cons = subport_tc2_credits_per_period - subport_tc2_credits; |
1085 | | | tc3_cons = subport_tc3_credits_per_period - subport_tc3_credits; |
1087 | | | tc3_cons_max = subport_tc3_credits_per_period - (tc0_cons + tc1_cons + |
1090 | | | if(tc3_consumption > (tc3_consumption_max - MTU)){ |
1092 | | | wm -= wm >> 7; |
1094 | | | if(wm < WM_MIN) wm = WM_MIN; |
1098 | | | wm += (wm >> 7) + 1; |
1100 | | | if(wm > WM_MAX) wm = WM_MAX; |
1104 +-----+------------------+----------------------------------------------------------------------------------+
1106 Worst Case Scenarios for Performance
1107 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1109 Lots of Active Queues with Not Enough Credits
1110 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1112 The more queues the scheduler has to examine for packets and credits in order to select one packet,
1113 the lower the performance of the scheduler is.
1115 The scheduler maintains the bitmap of active queues, which skips the non-active queues,
1116 but in order to detect whether a specific pipe has enough credits,
1117 the pipe has to be drilled down using the pipe dequeue state machine,
1118 which consumes cycles regardless of the scheduling result
1119 (no packets are produced or at least one packet is produced).
1121 This scenario stresses the importance of the policer for the scheduler performance:
1122 if the pipe does not have enough credits,
1123 its packets should be dropped as soon as possible (before they reach the hierarchical scheduler),
1124 thus rendering the pipe queues as not active,
1125 which allows the dequeue side to skip that pipe with no cycles being spent on investigating the pipe credits
1126 that would result in a "not enough credits" status.
1128 Single Queue with 100% Line Rate
1129 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1131 The port scheduler performance is optimized for a large number of queues.
1132 If the number of queues is small,
1133 then the performance of the port scheduler for the same level of active traffic is expected to be worse than
1134 the performance of a small set of message passing queues.
1141 The purpose of the DPDK dropper is to drop packets arriving at a packet scheduler to avoid congestion.
1142 The dropper supports the Random Early Detection (RED),
1143 Weighted Random Early Detection (WRED) and tail drop algorithms.
1144 :numref:`figure_blk_diag_dropper` illustrates how the dropper integrates with the scheduler.
1145 The DPDK currently does not support congestion management
1146 so the dropper provides the only method for congestion avoidance.
1148 .. _figure_blk_diag_dropper:
1150 .. figure:: img/blk_diag_dropper.*
1152 High-level Block Diagram of the DPDK Dropper
1155 The dropper uses the Random Early Detection (RED) congestion avoidance algorithm as documented in the reference publication.
1156 The purpose of the RED algorithm is to monitor a packet queue,
1157 determine the current congestion level in the queue and decide whether an arriving packet should be enqueued or dropped.
1158 The RED algorithm uses an Exponential Weighted Moving Average (EWMA) filter to compute average queue size which
1159 gives an indication of the current congestion level in the queue.
1161 For each enqueue operation, the RED algorithm compares the average queue size to minimum and maximum thresholds.
1162 Depending on whether the average queue size is below, above or in between these thresholds,
1163 the RED algorithm calculates the probability that an arriving packet should be dropped and
1164 makes a random decision based on this probability.
1166 The dropper also supports Weighted Random Early Detection (WRED) by allowing the scheduler to select
1167 different RED configurations for the same packet queue at run-time.
1168 In the case of severe congestion, the dropper resorts to tail drop.
1169 This occurs when a packet queue has reached maximum capacity and cannot store any more packets.
1170 In this situation, all arriving packets are dropped.
1172 The flow through the dropper is illustrated in :numref:`figure_flow_tru_droppper`.
1173 The RED/WRED algorithm is exercised first and tail drop second.
1175 .. _figure_flow_tru_droppper:
1177 .. figure:: img/flow_tru_droppper.*
1179 Flow Through the Dropper
1182 The use cases supported by the dropper are:
1184 * * Initialize configuration data
1186 * * Initialize run-time data
1188 * * Enqueue (make a decision to enqueue or drop an arriving packet)
1190 * * Mark empty (record the time at which a packet queue becomes empty)
1192 The configuration use case is explained in :ref:`Section2.23.3.1 <Configuration>`,
1193 the enqueue operation is explained in :ref:`Section 2.23.3.2 <Enqueue_Operation>`
1194 and the mark empty operation is explained in :ref:`Section 2.23.3.3 <Queue_Empty_Operation>`.
1201 A RED configuration contains the parameters given in :numref:`table_qos_16`.
1205 .. table:: RED Configuration Parameters
1207 +--------------------------+---------+---------+------------------+
1208 | Parameter | Minimum | Maximum | Typical |
1210 +==========================+=========+=========+==================+
1211 | Minimum Threshold | 0 | 1022 | 1/4 x queue size |
1213 +--------------------------+---------+---------+------------------+
1214 | Maximum Threshold | 1 | 1023 | 1/2 x queue size |
1216 +--------------------------+---------+---------+------------------+
1217 | Inverse Mark Probability | 1 | 255 | 10 |
1219 +--------------------------+---------+---------+------------------+
1220 | EWMA Filter Weight | 1 | 12 | 9 |
1222 +--------------------------+---------+---------+------------------+
1224 The meaning of these parameters is explained in more detail in the following sections.
1225 The format of these parameters as specified to the dropper module API
1226 corresponds to the format used by Cisco* in their RED implementation.
1227 The minimum and maximum threshold parameters are specified to the dropper module in terms of number of packets.
1228 The mark probability parameter is specified as an inverse value, for example,
1229 an inverse mark probability parameter value of 10 corresponds
1230 to a mark probability of 1/10 (that is, 1 in 10 packets will be dropped).
1231 The EWMA filter weight parameter is specified as an inverse log value,
1232 for example, a filter weight parameter value of 9 corresponds to a filter weight of 1/29.
1234 .. _Enqueue_Operation:
1239 In the example shown in :numref:`figure_ex_data_flow_tru_dropper`, q (actual queue size) is the input value,
1240 avg (average queue size) and count (number of packets since the last drop) are run-time values,
1241 decision is the output value and the remaining values are configuration parameters.
1243 .. _figure_ex_data_flow_tru_dropper:
1245 .. figure:: img/ex_data_flow_tru_dropper.*
1247 Example Data Flow Through Dropper
1250 EWMA Filter Microblock
1251 ^^^^^^^^^^^^^^^^^^^^^^
1253 The purpose of the EWMA Filter microblock is to filter queue size values to smooth out transient changes
1254 that result from "bursty" traffic.
1255 The output value is the average queue size which gives a more stable view of the current congestion level in the queue.
1257 The EWMA filter has one configuration parameter, filter weight, which determines how quickly
1258 or slowly the average queue size output responds to changes in the actual queue size input.
1259 Higher values of filter weight mean that the average queue size responds more quickly to changes in actual queue size.
1261 Average Queue Size Calculation when the Queue is not Empty
1262 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""
1264 The definition of the EWMA filter is given in the following equation.
1266 .. image:: img/ewma_filter_eq_1.*
1270 * *avg* = average queue size
1272 * *wq* = filter weight
1274 * *q* = actual queue size
1278 The filter weight, wq = 1/2^n, where n is the filter weight parameter value passed to the dropper module
1279 on configuration (see :ref:`Section2.23.3.1 <Configuration>` ).
1281 Average Queue Size Calculation when the Queue is Empty
1282 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1284 The EWMA filter does not read time stamps and instead assumes that enqueue operations will happen quite regularly.
1285 Special handling is required when the queue becomes empty as the queue could be empty for a short time or a long time.
1286 When the queue becomes empty, average queue size should decay gradually to zero instead of dropping suddenly to zero
1287 or remaining stagnant at the last computed value.
1288 When a packet is enqueued on an empty queue, the average queue size is computed using the following formula:
1290 .. image:: img/ewma_filter_eq_2.*
1294 * *m* = the number of enqueue operations that could have occurred on this queue while the queue was empty
1296 In the dropper module, *m* is defined as:
1298 .. image:: img/m_definition.*
1302 * *time* = current time
1304 * *qtime* = time the queue became empty
1306 * *s* = typical time between successive enqueue operations on this queue
1308 The time reference is in units of bytes,
1309 where a byte signifies the time duration required by the physical interface to send out a byte on the transmission medium
1310 (see Section `Internal Time Reference`_).
1311 The parameter s is defined in the dropper module as a constant with the value: s=2^22.
1312 This corresponds to the time required by every leaf node in a hierarchy with 64K leaf nodes
1313 to transmit one 64-byte packet onto the wire and represents the worst case scenario.
1314 For much smaller scheduler hierarchies,
1315 it may be necessary to reduce the parameter s, which is defined in the red header source file (rte_red.h) as:
1321 Since the time reference is in bytes, the port speed is implied in the expression: *time-qtime*.
1322 The dropper does not have to be configured with the actual port speed.
1323 It adjusts automatically to low speed and high speed links.
1328 A numerical method is used to compute the factor (1-wq)^m that appears in Equation 2.
1330 This method is based on the following identity:
1332 .. image:: img/eq2_factor.*
1335 This allows us to express the following:
1337 .. image:: img/eq2_expression.*
1340 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.
1341 The factor (1-wq)^m can then be obtained by multiplying the table value by *m* and applying shift operations.
1342 To avoid overflow in the multiplication, the value, *m*, and the look-up table values are limited to 16 bits.
1343 The total size of the look-up table is 56 bytes.
1344 Once the factor (1-wq)^m is obtained using this method, the average queue size can be calculated from Equation 2.
1346 Alternative Approaches
1347 """"""""""""""""""""""
1349 Other methods for calculating the factor (1-wq)^m in the expression for computing average queue size
1350 when the queue is empty (Equation 2) were considered.
1351 These approaches include:
1353 * Floating-point evaluation
1355 * Fixed-point evaluation using a small look-up table (512B) and up to 16 multiplications
1356 (this is the approach used in the FreeBSD* ALTQ RED implementation)
1358 * Fixed-point evaluation using a small look-up table (512B) and 16 SSE multiplications
1359 (SSE optimized version of the approach used in the FreeBSD* ALTQ RED implementation)
1361 * Large look-up table (76 KB)
1363 The method that was finally selected (described above in Section 26.3.2.2.1) out performs all of these approaches
1364 in terms of run-time performance and memory requirements and
1365 also achieves accuracy comparable to floating-point evaluation.
1366 :numref:`table_qos_17` lists the performance of each of these alternative approaches relative to the method that is used in the dropper.
1367 As can be seen, the floating-point implementation achieved the worst performance.
1371 .. table:: Relative Performance of Alternative Approaches
1373 +------------------------------------------------------------------------------------+----------------------+
1374 | Method | Relative Performance |
1376 +====================================================================================+======================+
1377 | Current dropper method (see :ref:`Section 23.3.2.1.3 <Dropper>`) | 100% |
1379 +------------------------------------------------------------------------------------+----------------------+
1380 | Fixed-point method with small (512B) look-up table | 148% |
1382 +------------------------------------------------------------------------------------+----------------------+
1383 | SSE method with small (512B) look-up table | 114% |
1385 +------------------------------------------------------------------------------------+----------------------+
1386 | Large (76KB) look-up table | 118% |
1388 +------------------------------------------------------------------------------------+----------------------+
1389 | Floating-point | 595% |
1391 +------------------------------------------------------------------------------------+----------------------+
1392 | **Note**: In this case, since performance is expressed as time spent executing the operation in a |
1393 | specific condition, any relative performance value above 100% runs slower than the reference method. |
1395 +-----------------------------------------------------------------------------------------------------------+
1400 The Drop Decision block:
1402 * Compares the average queue size with the minimum and maximum thresholds
1404 * Calculates a packet drop probability
1406 * Makes a random decision to enqueue or drop an arriving packet
1408 The calculation of the drop probability occurs in two stages.
1409 An initial drop probability is calculated based on the average queue size,
1410 the minimum and maximum thresholds and the mark probability.
1411 An actual drop probability is then computed from the initial drop probability.
1412 The actual drop probability takes the count run-time value into consideration
1413 so that the actual drop probability increases as more packets arrive to the packet queue
1414 since the last packet was dropped.
1416 Initial Packet Drop Probability
1417 """""""""""""""""""""""""""""""
1419 The initial drop probability is calculated using the following equation.
1421 .. image:: img/drop_probability_eq3.*
1425 * *maxp* = mark probability
1427 * *avg* = average queue size
1429 * *minth* = minimum threshold
1431 * *maxth* = maximum threshold
1433 The calculation of the packet drop probability using Equation 3 is illustrated in :numref:`figure_pkt_drop_probability`.
1434 If the average queue size is below the minimum threshold, an arriving packet is enqueued.
1435 If the average queue size is at or above the maximum threshold, an arriving packet is dropped.
1436 If the average queue size is between the minimum and maximum thresholds,
1437 a drop probability is calculated to determine if the packet should be enqueued or dropped.
1439 .. _figure_pkt_drop_probability:
1441 .. figure:: img/pkt_drop_probability.*
1443 Packet Drop Probability for a Given RED Configuration
1446 Actual Drop Probability
1447 """""""""""""""""""""""
1449 If the average queue size is between the minimum and maximum thresholds,
1450 then the actual drop probability is calculated from the following equation.
1452 .. image:: img/drop_probability_eq4.*
1456 * *Pb* = initial drop probability (from Equation 3)
1458 * *count* = number of packets that have arrived since the last drop
1460 The constant 2, in Equation 4 is the only deviation from the drop probability formulae
1461 given in the reference document where a value of 1 is used instead.
1462 It should be noted that the value pa computed from can be negative or greater than 1.
1463 If this is the case, then a value of 1 should be used instead.
1465 The initial and actual drop probabilities are shown in :numref:`figure_drop_probability_graph`.
1466 The actual drop probability is shown for the case where
1467 the formula given in the reference document1 is used (blue curve)
1468 and also for the case where the formula implemented in the dropper module,
1469 is used (red curve).
1470 The formula in the reference document results in a significantly higher drop rate
1471 compared to the mark probability configuration parameter specified by the user.
1472 The choice to deviate from the reference document is simply a design decision and
1473 one that has been taken by other RED implementations, for example, FreeBSD* ALTQ RED.
1475 .. _figure_drop_probability_graph:
1477 .. figure:: img/drop_probability_graph.*
1479 Initial Drop Probability (pb), Actual Drop probability (pa) Computed Using
1480 a Factor 1 (Blue Curve) and a Factor 2 (Red Curve)
1483 .. _Queue_Empty_Operation:
1485 Queue Empty Operation
1486 ~~~~~~~~~~~~~~~~~~~~~
1488 The time at which a packet queue becomes empty must be recorded and saved with the RED run-time data
1489 so that the EWMA filter block can calculate the average queue size on the next enqueue operation.
1490 It is the responsibility of the calling application to inform the dropper module
1491 through the API that a queue has become empty.
1493 Source Files Location
1494 ~~~~~~~~~~~~~~~~~~~~~
1496 The source files for the DPDK dropper are located at:
1498 * DPDK/lib/librte_sched/rte_red.h
1500 * DPDK/lib/librte_sched/rte_red.c
1502 Integration with the DPDK QoS Scheduler
1503 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1505 RED functionality in the DPDK QoS scheduler is disabled by default.
1506 To enable it, use the DPDK configuration parameter:
1510 CONFIG_RTE_SCHED_RED=y
1512 This parameter must be set to y.
1513 The parameter is found in the build configuration files in the DPDK/config directory,
1514 for example, DPDK/config/common_linux.
1515 RED configuration parameters are specified in the rte_red_params structure within the rte_sched_port_params structure
1516 that is passed to the scheduler on initialization.
1517 RED parameters are specified separately for four traffic classes and three packet colors (green, yellow and red)
1518 allowing the scheduler to implement Weighted Random Early Detection (WRED).
1520 Integration with the DPDK QoS Scheduler Sample Application
1521 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1523 The DPDK QoS Scheduler Application reads a configuration file on start-up.
1524 The configuration file includes a section containing RED parameters.
1525 The format of these parameters is described in :ref:`Section2.23.3.1 <Configuration>`.
1526 A sample RED configuration is shown below. In this example, the queue size is 64 packets.
1530 For correct operation, the same EWMA filter weight parameter (wred weight) should be used
1531 for each packet color (green, yellow, red) in the same traffic class (tc).
1535 ; RED params per traffic class and color (Green / Yellow / Red)
1538 tc 0 wred min = 28 22 16
1539 tc 0 wred max = 32 32 32
1540 tc 0 wred inv prob = 10 10 10
1541 tc 0 wred weight = 9 9 9
1543 tc 1 wred min = 28 22 16
1544 tc 1 wred max = 32 32 32
1545 tc 1 wred inv prob = 10 10 10
1546 tc 1 wred weight = 9 9 9
1548 tc 2 wred min = 28 22 16
1549 tc 2 wred max = 32 32 32
1550 tc 2 wred inv prob = 10 10 10
1551 tc 2 wred weight = 9 9 9
1553 tc 3 wred min = 28 22 16
1554 tc 3 wred max = 32 32 32
1555 tc 3 wred inv prob = 10 10 10
1556 tc 3 wred weight = 9 9 9
1558 With this configuration file, the RED configuration that applies to green,
1559 yellow and red packets in traffic class 0 is shown in :numref:`table_qos_18`.
1563 .. table:: RED Configuration Corresponding to RED Configuration File
1565 +--------------------+--------------------+-------+--------+-----+
1566 | RED Parameter | Configuration Name | Green | Yellow | Red |
1568 +====================+====================+=======+========+=====+
1569 | Minimum Threshold | tc 0 wred min | 28 | 22 | 16 |
1571 +--------------------+--------------------+-------+--------+-----+
1572 | Maximum Threshold | tc 0 wred max | 32 | 32 | 32 |
1574 +--------------------+--------------------+-------+--------+-----+
1575 | Mark Probability | tc 0 wred inv prob | 10 | 10 | 10 |
1577 +--------------------+--------------------+-------+--------+-----+
1578 | EWMA Filter Weight | tc 0 wred weight | 9 | 9 | 9 |
1580 +--------------------+--------------------+-------+--------+-----+
1582 Application Programming Interface (API)
1583 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1588 The syntax of the enqueue API is as follows:
1592 int rte_red_enqueue(const struct rte_red_config *red_cfg, struct rte_red *red, const unsigned q, const uint64_t time)
1595 The arguments passed to the enqueue API are configuration data, run-time data,
1596 the current size of the packet queue (in packets) and a value representing the current time.
1597 The time reference is in units of bytes,
1598 where a byte signifies the time duration required by the physical interface to send out a byte on the transmission medium
1599 (see Section 26.2.4.5.1 "Internal Time Reference" ).
1600 The dropper reuses the scheduler time stamps for performance reasons.
1605 The syntax of the empty API is as follows:
1609 void rte_red_mark_queue_empty(struct rte_red *red, const uint64_t time)
1611 The arguments passed to the empty API are run-time data and the current time in bytes.
1616 The traffic metering component implements the Single Rate Three Color Marker (srTCM) and
1617 Two Rate Three Color Marker (trTCM) algorithms, as defined by IETF RFC 2697 and 2698 respectively.
1618 These algorithms meter the stream of incoming packets based on the allowance defined in advance for each traffic flow.
1619 As result, each incoming packet is tagged as green,
1620 yellow or red based on the monitored consumption of the flow the packet belongs to.
1625 The srTCM algorithm defines two token buckets for each traffic flow,
1626 with the two buckets sharing the same token update rate:
1628 * Committed (C) bucket: fed with tokens at the rate defined by the Committed Information Rate (CIR) parameter
1629 (measured in IP packet bytes per second).
1630 The size of the C bucket is defined by the Committed Burst Size (CBS) parameter (measured in bytes);
1632 * Excess (E) bucket: fed with tokens at the same rate as the C bucket.
1633 The size of the E bucket is defined by the Excess Burst Size (EBS) parameter (measured in bytes).
1635 The trTCM algorithm defines two token buckets for each traffic flow,
1636 with the two buckets being updated with tokens at independent rates:
1638 * Committed (C) bucket: fed with tokens at the rate defined by the Committed Information Rate (CIR) parameter
1639 (measured in bytes of IP packet per second).
1640 The size of the C bucket is defined by the Committed Burst Size (CBS) parameter (measured in bytes);
1642 * Peak (P) bucket: fed with tokens at the rate defined by the Peak Information Rate (PIR) parameter
1643 (measured in IP packet bytes per second).
1644 The size of the P bucket is defined by the Peak Burst Size (PBS) parameter (measured in bytes).
1646 Please refer to RFC 2697 (for srTCM) and RFC 2698 (for trTCM) for details on how tokens are consumed
1647 from the buckets and how the packet color is determined.
1649 Color Blind and Color Aware Modes
1650 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1652 For both algorithms, the color blind mode is functionally equivalent to the color aware mode with input color set as green.
1653 For color aware mode, a packet with red input color can only get the red output color,
1654 while a packet with yellow input color can only get the yellow or red output colors.
1656 The reason why the color blind mode is still implemented distinctly than the color aware mode is
1657 that color blind mode can be implemented with fewer operations than the color aware mode.
1659 Implementation Overview
1660 ~~~~~~~~~~~~~~~~~~~~~~~
1662 For each input packet, the steps for the srTCM / trTCM algorithms are:
1664 * Update the C and E / P token buckets. This is done by reading the current time (from the CPU timestamp counter),
1665 identifying the amount of time since the last bucket update and computing the associated number of tokens
1666 (according to the pre-configured bucket rate).
1667 The number of tokens in the bucket is limited by the pre-configured bucket size;
1669 * Identify the output color for the current packet based on the size of the IP packet
1670 and the amount of tokens currently available in the C and E / P buckets; for color aware mode only,
1671 the input color of the packet is also considered.
1672 When the output color is not red, a number of tokens equal to the length of the IP packet are
1673 subtracted from the C or E /P or both buckets, depending on the algorithm and the output color of the packet.