| 1 |
.. SPDX-License-Identifier: BSD-2-Clause |
| 2 |
.. |
| 3 |
.. Copyright (C) 2025 Linutronix GmbH |
| 4 |
.. |
| 5 |
.. Processing latency documentation. |
| 6 |
.. |
| 7 |
|
| 8 |
.. _ProcessingLatency: |
| 9 |
|
| 10 |
Processing Latency |
| 11 |
================== |
| 12 |
|
| 13 |
Processing latency metrics quantify how long the Mirror DUT takes to process a full cycle |
| 14 |
of packets. It is measured from the hardware RX timestamp of the first packet in the cycle |
| 15 |
to the hardware TX timestamp of the response packet(s). These measurements work only in |
| 16 |
Mirror mode and only when AF_XDP and hardware timestamping are enabled. |
| 17 |
|
| 18 |
These metrics allow evaluating Mirror-side timing behavior for both: |
| 19 |
|
| 20 |
- Pure forwarding scenarios (no workload) |
| 21 |
- Sense-compute-actuate scenarios (once-per-cycle workload execution) |
| 22 |
|
| 23 |
|
| 24 |
Timestamp Flow |
| 25 |
^^^^^^^^^^^^^^ |
| 26 |
|
| 27 |
The following diagram shows where timestamps are captured and what the processing |
| 28 |
latency metrics measure: |
| 29 |
|
| 30 |
.. code-block:: text |
| 31 |
|
| 32 |
RX Path Processing TX Path |
| 33 |
-------- ---------- ------- |
| 34 |
|
| 35 |
[Wire] ──> [NIC] ────> [XDP] ────> [Mirror App] ────> [NIC] ────> [Wire] |
| 36 |
| | │ │ │ |
| 37 |
| | Workload │ |
| 38 |
| RX SW TS (optional) | |
| 39 |
| | | | |
| 40 |
| | | | |
| 41 |
RX HW TS RX App TS TX SW TS TX HW TS |
| 42 |
| | |
| 43 |
| | |
| 44 |
[Pkt 1 RX] ◄────────── ProcFirst ──────────► [Pkt 1 TX] |
| 45 |
[Pkt 1 RX] ◄────────── ProcBatch ──────────► [Pkt N TX] |
| 46 |
|
| 47 |
Timestamp Details |
| 48 |
^^^^^^^^^^^^^^^^^ |
| 49 |
|
| 50 |
The table below provides precise details for each timestamp capture point: |
| 51 |
|
| 52 |
.. list-table:: Timestamp Capture Points |
| 53 |
:widths: 12 18 20 50 |
| 54 |
:header-rows: 1 |
| 55 |
|
| 56 |
* - Timestamp |
| 57 |
- Capture Location |
| 58 |
- When Captured |
| 59 |
- Technical Notes |
| 60 |
* - **RX HW TS** |
| 61 |
- NIC Hardware |
| 62 |
- Packet arrival |
| 63 |
- HW timestamp at NIC |
| 64 |
* - **RX SW TS** |
| 65 |
- XDP Hook |
| 66 |
- After DMA completion |
| 67 |
- XDP program timestamp |
| 68 |
* - **RX App TS** |
| 69 |
- Userspace |
| 70 |
- After XSK polling |
| 71 |
- App extraction timestamp |
| 72 |
* - **TX SW TS** |
| 73 |
- Userspace |
| 74 |
- After TX ring submit |
| 75 |
- Pre-wakeup timestamp |
| 76 |
* - **TX HW TS** |
| 77 |
- NIC Hardware |
| 78 |
- Packet transmission |
| 79 |
- HW timestamp at NIC |
| 80 |
|
| 81 |
|
| 82 |
**RX HW TS:** Exact hardware capture point varies by NIC (MAC layer, PHY, or DMA descriptor write). |
| 83 |
|
| 84 |
**RX SW TS:** Timestamp is taken when the XDP program executes after the NIC DMA completes. |
| 85 |
|
| 86 |
**RX App TS:** Timestamp is captured at stat_frame_received(), after userspace dequeues the packet. |
| 87 |
|
| 88 |
**TX SW TS:** Timestamp represents the moment the TX descriptors are submitted to the TX ring. |
| 89 |
|
| 90 |
**TX HW TS:** Exact capture point varies by NIC (MAC egress, PHY, or descriptor completion). |
| 91 |
|
| 92 |
.. note:: |
| 93 |
On the RX path, an intermediate software timestamp (RX SW TS) is available because, |
| 94 |
in AF_XDP mode, all packets are processed by the XDP program before they are |
| 95 |
delivered to userspace. |
| 96 |
|
| 97 |
On the TX path there is no equivalent midpoint timestamp: with AF_XDP, packets are |
| 98 |
transmitted directly from userspace via the TX ring, so only the userspace |
| 99 |
submission timestamp (TX SW TS) and the NIC hardware transmit timestamp (TX HW TS) |
| 100 |
are available. |
| 101 |
|
| 102 |
|
| 103 |
Processing Latency Metrics |
| 104 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 105 |
|
| 106 |
The following metrics are available in Mirror mode with AF_XDP when both RX and TX |
| 107 |
hardware timestamping are enabled: |
| 108 |
|
| 109 |
|
| 110 |
.. list-table:: Primary Processing Latency Metrics |
| 111 |
:widths: 20 30 50 |
| 112 |
:header-rows: 1 |
| 113 |
|
| 114 |
* - Metric |
| 115 |
- Calculation |
| 116 |
- Meaning |
| 117 |
* - **ProcFirst** |
| 118 |
- First TX HW TS - First RX HW TS |
| 119 |
- First-packet processing latency |
| 120 |
* - **ProcBatch** |
| 121 |
- Last TX HW TS - First RX HW TS |
| 122 |
- Full-cycle processing latency |
| 123 |
|
| 124 |
|
| 125 |
**ProcFirst:** |
| 126 |
Measures how long the Mirror DUT takes to process the *first* packet of each cycle, |
| 127 |
from the first RX hardware timestamp to the first TX hardware timestamp. |
| 128 |
This is the primary metric for evaluating the DUT's internal end-to-end processing |
| 129 |
responsiveness. |
| 130 |
|
| 131 |
**ProcBatch:** |
| 132 |
Measures the total processing time for the entire batch of packets in the cycle, |
| 133 |
from the first RX hardware timestamp to the last TX hardware timestamp. |
| 134 |
Useful for scenarios with multiple packets per cycle where overall cycle-completion |
| 135 |
time matters. |
| 136 |
|
| 137 |
.. note:: |
| 138 |
For cycles that contain only one packet, only ``ProcFirst`` is reported. |
| 139 |
``ProcBatch`` is omitted because it would be identical to ``ProcFirst``. |
| 140 |
|
| 141 |
Configuration |
| 142 |
^^^^^^^^^^^^^ |
| 143 |
|
| 144 |
Dependencies |
| 145 |
------------ |
| 146 |
|
| 147 |
Processing latency metrics require both RX and TX hardware timestamp support. |
| 148 |
The following table summarizes all dependencies: |
| 149 |
|
| 150 |
.. list-table:: Hardware Timestamp Dependencies |
| 151 |
:widths: 15 20 20 |
| 152 |
:header-rows: 1 |
| 153 |
|
| 154 |
* - Component |
| 155 |
- RX Hardware Timestamp |
| 156 |
- TX Hardware Timestamp |
| 157 |
* - **Linux Kernel** |
| 158 |
- >= 6.3 |
| 159 |
- >= 6.8 |
| 160 |
* - **libbpf** |
| 161 |
- >= 1.2 |
| 162 |
- Any version |
| 163 |
* - **libxdp** |
| 164 |
- Any version |
| 165 |
- >= 1.4.1 |
| 166 |
* - **NIC Driver Feature** |
| 167 |
- bpf_xdp_metadata_rx_timestamp() |
| 168 |
- XDP_TXMD_FLAGS_TIMESTAMP |
| 169 |
|
| 170 |
.. note:: |
| 171 |
The minimum Linux kernel versions listed in the table indicate when the XDP |
| 172 |
timestamping capabilities first became available in the kernel. Real support |
| 173 |
depends on NIC driver implementation. |
| 174 |
|
| 175 |
Build Configuration |
| 176 |
------------------- |
| 177 |
|
| 178 |
To enable processing latency metrics, build with both RX and TX timestamp support: |
| 179 |
|
| 180 |
.. code-block:: bash |
| 181 |
|
| 182 |
cmake -DCMAKE_BUILD_TYPE=Release -DRX_TIMESTAMP=TRUE -DTX_TIMESTAMP=TRUE .. |
| 183 |
|
| 184 |
Enable TX hardware timestamping for your traffic class in the YAML configuration. |
| 185 |
For example, to enable it for TsnHigh: |
| 186 |
|
| 187 |
.. code-block:: yaml |
| 188 |
|
| 189 |
TsnHighXdpEnabled: true |
| 190 |
TsnHighTxTimeStampEnabled: true |
| 191 |
|
| 192 |
.. Note:: Hardware timestamping must be supported by the NIC. If unsupported, |
| 193 |
ProcFirst and ProcBatch will not populate. Check ``ethtool -T <interface>`` |
| 194 |
to verify hardware timestamping capabilities. |
| 195 |
|
| 196 |
Example Output |
| 197 |
^^^^^^^^^^^^^^ |
| 198 |
|
| 199 |
Example Mirror-mode log output with processing latency metrics (3 TsnHigh packets |
| 200 |
per cycle): |
| 201 |
|
| 202 |
.. code-block:: text |
| 203 |
|
| 204 |
# Processing Latency Metrics |
| 205 |
TsnHighProcFirstMin=999 [us] |
| 206 |
TsnHighProcFirstMax=1001 [us] |
| 207 |
TsnHighProcFirstAvg=999.198684 [us] |
| 208 |
|
| 209 |
TsnHighProcBatchMin=1002 [us] |
| 210 |
TsnHighProcBatchMax=1003 [us] |
| 211 |
TsnHighProcBatchAvg=1002.000087 [us] |
| 212 |
|
| 213 |
Additional Monitoring Points |
| 214 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 215 |
|
| 216 |
For advanced debugging and system optimization, additional timestamp metrics are |
| 217 |
available. These metrics are derived from the timestamp capture points detailed in |
| 218 |
the Timestamp Details table above: |
| 219 |
|
| 220 |
|
| 221 |
.. list-table:: Debugging and Optimization Metrics |
| 222 |
:widths: 18 22 30 |
| 223 |
:header-rows: 1 |
| 224 |
|
| 225 |
* - Metric |
| 226 |
- Calculation |
| 227 |
- Meaning |
| 228 |
* - **Rx** |
| 229 |
- RX App TS - RX HW TS |
| 230 |
- Total RX path latency |
| 231 |
* - **RxHw2Xdp** |
| 232 |
- RX SW TS - RX HW TS |
| 233 |
- NIC HW to XDP hook latency |
| 234 |
* - **RxXdp2App** |
| 235 |
- RX App TS - RX SW TS |
| 236 |
- XDP hook to userspace latency |
| 237 |
* - **Tx** |
| 238 |
- TX HW TS - TX SW TS |
| 239 |
- TX ring to NIC HW latency |
| 240 |
* - **TxHwTimestampMissing** |
| 241 |
- Count |
| 242 |
- Missing or invalid TX HW timestamps |
| 243 |
|
| 244 |
|
| 245 |
**Rx:** |
| 246 |
Measures total receive-path latency from NIC hardware timestamp to the userspace |
| 247 |
timestamp captured when the application processes the received frame. |
| 248 |
Useful for assessing overall RX path performance. |
| 249 |
|
| 250 |
**RxHw2Xdp:** |
| 251 |
Measures latency from where the NIC records the hardware timestamp |
| 252 |
(MAC / PHY / DMA write depending on NIC implementation) to execution of the XDP program. |
| 253 |
Useful for debugging NIC to kernel boundary delays. |
| 254 |
|
| 255 |
**RxXdp2App:** |
| 256 |
Measures latency between the XDP program and the application's receive handler. |
| 257 |
Includes XSK ring polling and packet extraction. |
| 258 |
Useful for debugging kernel to userspace delays. |
| 259 |
|
| 260 |
**Tx:** |
| 261 |
Measures latency from software submission to the TX ring to when the NIC hardware |
| 262 |
transmits the frame and produces a hardware timestamp. |
| 263 |
Useful for analyzing TX ring congestion, DMA delays, or NIC scheduling. |
| 264 |
|
| 265 |
**TxHwTimestampMissing:** |
| 266 |
Counts cycles where no valid TX hardware timestamp is available. |
| 267 |
Covers cases such as: |
| 268 |
|
| 269 |
- NIC timestamp FIFO overflow |
| 270 |
- driver unable to match timestamp |
| 271 |
- timestamp not ready before app queries |
| 272 |
- invalid timestamp (e.g., TX HW TS ≤ TX SW TS) |
| 273 |
|
| 274 |
Useful for evaluating timestamp reliability and NIC/driver behavior. |
| 275 |
|
| 276 |
.. note:: |
| 277 |
These debugging metrics apply to both Mirror and Reference modes. |
| 278 |
(ProcFirst/ProcBatch remain Mirror-only.) |
| 279 |
|
| 280 |
These metrics help drill down into specific bottlenecks when processing latencies |
| 281 |
indicate performance issues. Each metric corresponds to a specific segment of the |
| 282 |
timestamp flow shown in the diagram above. |