blob: e8f0e039b8ea122eb1be54949eb168bfa068783e [file] [log] [blame]
Mohsin Kazmi78699852023-05-05 12:32:59 +00001.. _TX_Queue_doc:
2
3Transmit Queues
4===============
5
6Overview
7________
8
9VPP implements Transmit queues infra to access and manage them. It provides
10common registration functions to register or unregister interfaces transmit
11queues. It also provides functions for queues placement on given thread(s).
12
13The TXQ Infrastructure
14_______________________
15
16Infra registers each queue using a unique key which is formed by concatenating
17the hardware interface index ``hw_if_index`` and unique queue identifier for
18given interface ``queue_id``. As a result of registration of queue, infra
19returns back a unique global ``queue_index`` which can be used by driver to
20access that queue later.
21
22Interface output node uses pre-computed ``output_node_thread_runtime`` data
23which provides essential information related to queue placements on given
24thread of given interface. Transmit queue infra implements an algorithm to
25pre-compute this information. It also pre-computes scalar arguments of frame
26``vnet_hw_if_tx_frame_t``. It also pre-calculates a ``lookup_table`` for
27thread if there are multiple transmit queues are placed on that thread.
28Interface drivers call ``vnet_hw_if_update_runtime_data()`` to execute that
29algorithm after registering the transmit queues to TXQ infra.
30
31The algorithm makes the copy of existing runtime data and iterate through them
32for each vpp main and worker thread. In each iteration, algorithm loop through
33all the tx queues of given interface to fill the information in the frame data
34structure ``vnet_hw_if_tx_frame_t``. Algorithm also updates the information
35related to number of transmit queues of given interface on given vpp thread in
36data structure ``output_node_thread_runtime``. As a consequence of any update
37to the copy, triggers the function to update the actual working copy by taking
38the worker barrier and free the old copy of ``output_node_thread_runtime``.
39
40Multi-TXQ infra
41^^^^^^^^^^^^^^^
42
43Interface output node uses packet flow hash using hash infra in case of multi-txq
44on given thread. Each hardware interface class contains type of the hash required
45for interfaces from that hardware interface class i.e. ethernet interface hardware
46class contains type ``VNET_HASH_FN_TYPE_ETHERNET``. Though, the hash function
47itself is contained by hardware interface data structure of given interface. Default
48hashing function is selected upon interface creation based on priority. User can
49configure a different hash to an interface for multi-txq use case.
50
51Interface output node uses packet flow hash as an index to the pre-calculated lookup
52table to get the queue identifier for given transmit queue. Interface output node
53enqueues the packets to respective frame and also copies the ``vnet_hw_if_tx_frame_t``
54to frame scalar arguments. Drivers use scalar arguments ``vnet_hw_if_tx_frame_t``
55of the given frame to extract the information about the transmit queue to be used to
56transmit the packets. Drivers may need to acquire a lock on given queue before
57transmitting the packets based on the ``shared_queue`` bit status.
58
59Data structures
60^^^^^^^^^^^^^^^
61
62Queue information is stored in data structure ``vnet_hw_if_tx_queue_t``:
63
64.. code:: c
65
66 typedef struct
67 {
68 /* either this queue is shared among multiple threads */
69 u8 shared_queue : 1;
70 /* hw interface index */
71 u32 hw_if_index;
72
73 /* hardware queue identifier */
74 u32 queue_id;
75
76 /* bitmap of threads which use this queue */
77 clib_bitmap_t *threads;
78 } vnet_hw_if_tx_queue_t;
79
80
81Frame information is stored in data structure: ``vnet_hw_if_tx_frame_t``:
82
83.. code:: c
84
85 typedef enum
86 {
87 VNET_HW_IF_TX_FRAME_HINT_NOT_CHAINED = (1 << 0),
88 VNET_HW_IF_TX_FRAME_HINT_NO_GSO = (1 << 1),
89 VNET_HW_IF_TX_FRAME_HINT_NO_CKSUM_OFFLOAD = (1 << 2),
90 } vnet_hw_if_tx_frame_hint_t;
91
92 typedef struct
93 {
94 u8 shared_queue : 1;
95 vnet_hw_if_tx_frame_hint_t hints : 16;
96 u32 queue_id;
97 } vnet_hw_if_tx_frame_t;
98
99Output node runtime information is stored in data structure: ``output_node_thread_runtime``:
100
101.. code:: c
102
103 typedef struct
104 {
105 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
106 vnet_hw_if_tx_frame_t *frame;
107 u32 *lookup_table;
108 u32 n_queues;
109 } vnet_hw_if_output_node_runtime_t;
110
111
112MultiTXQ API
113^^^^^^^^^^^^
114
115This API message is used to place tx queue of an interface to vpp main or worker(s) thread(s).
116
117.. code:: c
118
119 autoendian autoreply define sw_interface_set_tx_placement
120 {
121 u32 client_index;
122 u32 context;
123 vl_api_interface_index_t sw_if_index;
124 u32 queue_id;
125 u32 array_size;
126 u32 threads[array_size];
127 option vat_help = "<interface | sw_if_index <index>> queue <n> [threads <list> | mask <hex>]";
128 };
129
130Multi-TXQ CLI
131^^^^^^^^^^^^^
132
133::
134
135 set interface tx-queue set interface tx-queue <interface> queue <n> [threads <list>]
136 set interface tx-hash set interface tx-hash <interface> hash-name <hash-name>
137
138::
139
140 show hardware-interfaces
141
142 Name Idx Link Hardware
143 tap0 1 up tap0
144 Link speed: unknown
145 RX Queues:
146 queue thread mode
147 0 main (0) polling
148 TX Queues:
149 TX Hash: [name: crc32c-5tuple priority: 50 description: IPv4/IPv6 header and TCP/UDP ports]
150 queue shared thread(s)
151 0 no 0
152 Ethernet address 02:fe:27:69:5a:b5
153 VIRTIO interface
154 instance 0
155 RX QUEUE : Total Packets
156 0 : 0
157 TX QUEUE : Total Packets
158 0 : 0
159