Counter Externs - 2025.1 English - UG1308

Vitis Networking P4 User Guide (UG1308)

Document ID
UG1308
Release Date
2025-05-29
Version
2025.1 English

The architecture-specific implementation of the Counter Extern closely follows the PSA/PNA specification (see References). It provides a mechanism for keeping statistics. The control plane can read the counter values. A P4 program cannot read counter values, only update them.

The Counter Extern supports three different counter types:

PACKETS
Increment values are set to 1.
BYTES
Increment values are set to the measured packet length as it appears on the AXI4-Stream I/F at the input to VNP4 (that is, before any packet editing is performed). If, for example, FCS bytes are present in the packet, they are included in the packet length increment value.
PACKETS_AND_BYTES
The lower 35 bits are incremented by the packet length, the upper 29 bits are incremented by 1.

The counters supported are 64-bit counters (combined width in the case of PACKETS_AND_BYTES type). The highest number of counters supported per instance is 65,536, and there is no limit to the number of Counter Extern instances allowed. Each counter saturates at its maximum value.

A Counter width of 1-bit is also supported, where 64 counter values are packed together in a 64-bit entry of the register map. This allows for a larger number of counters with significantly less memory usage. The counters still saturate at the maximum value, in this case 1. One example use case is with a table to monitor which table entries are hit.

The Counter Extern is only supported within the Match_Action Engine ‘control’ block of a P4 program.

The Counter Extern supports AXI4-Lite control-plane writes and reads (maximum burst size of 128 counters), with an optional clear-on-read. The Counter values are stored in LUTRAM, block RAM, or URAM, depending on the number of counters.

Note: ECC is only supported when block RAM or URAM memory type is used.

See Register Map for the Counter Extern register map.

The Counter Extern is defined in xsa.p4 as -

extern Counter<W, S> {
Counter(bit<32> n_counters, CounterType_t type);
void count(in S index);
}

An example of a Counter Extern being used in an example P4 program can be seen in the FiveTuple example design (see FiveTuple Example Design).