[PATCH v6 04/11] net/rtap: add statistics and device info

Stephen Hemminger
2026-02-14T23:48:07Z

Implement basic and per-queue statistics collection.
Usual statistics per queue: packets, bytes, errors.

The imissed counter reports kernel rx_dropped (packets dropped
before reaching the interface) retrieved via netlink IFLA_STATS64.
The rx_drop_base field captures the baseline value at stats_reset.

Device info reports ifindex, max queue counts, and default
burst/ring sizes.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
doc/guides/nics/features/rtap.ini | 2 +
drivers/net/rtap/rtap.h | 2 +
drivers/net/rtap/rtap_ethdev.c | 120 ++++++++++++++++++++++++++++++
3 files changed, 124 insertions(+)

diff --git a/doc/guides/nics/features/rtap.ini b/doc/guides/nics/features/rtap.ini
index c064e1e0b9..9bef9e341d 100644
--- a/doc/guides/nics/features/rtap.ini
+++ b/doc/guides/nics/features/rtap.ini
@@ -5,6 +5,8 @@
;
[Features]
Scattered Rx = P
+Basic stats = Y
+Stats per queue = Y
Linux = Y
ARMv7 = Y
ARMv8 = Y
diff --git a/drivers/net/rtap/rtap.h b/drivers/net/rtap/rtap.h
index 823b8c59f7..abfde20e60 100644
--- a/drivers/net/rtap/rtap.h
+++ b/drivers/net/rtap/rtap.h
@@ -62,6 +62,8 @@ struct rtap_pmd {
int if_index; /* interface index */
int nlsk_fd; /* netlink control socket */
struct rte_ether_addr eth_addr; /* address assigned by kernel */
+
+ uint64_t rx_drop_base; /* value of rx_dropped when reset */
};

/* rtap_ethdev.c */
diff --git a/drivers/net/rtap/rtap_ethdev.c b/drivers/net/rtap/rtap_ethdev.c
index 463e24a6e1..888f8e7f39 100644
--- a/drivers/net/rtap/rtap_ethdev.c
+++ b/drivers/net/rtap/rtap_ethdev.c
@@ -2,6 +2,7 @@
* Copyright (c) 2026 Stephen Hemminger
*/

+#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
@@ -11,6 +12,7 @@
#include <sys/ioctl.h>
#include <net/if.h>
#include <linux/if_tun.h>
+#include <linux/if_link.h>
#include <linux/virtio_net.h>

#include <rte_config.h>
@@ -29,6 +31,14 @@

#define RTAP_DEFAULT_IFNAME "rtap%d"

+#define RTAP_DEFAULT_BURST 64
+#define RTAP_NUM_BUFFERS 1024
+#define RTAP_MAX_QUEUES 128
+#define RTAP_MIN_RX_BUFSIZE RTE_ETHER_MIN_LEN
+#define RTAP_MAX_RX_PKTLEN RTE_ETHER_MAX_JUMBO_FRAME_LEN
+
+static_assert(RTAP_MAX_QUEUES <= RTE_MP_MAX_FD_NUM, "Max queues exceeds MP fd limit");
+
#define RTAP_IFACE_ARG "iface"
#define RTAP_PERSIST_ARG "persist"

@@ -157,6 +167,112 @@ rtap_dev_configure(struct rte_eth_dev *dev)
return 0;
}

+static int
+rtap_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
+{
+ struct rtap_pmd *pmd = dev->data->dev_private;
+
+ dev_info->if_index = pmd->if_index;
+ dev_info->max_mac_addrs = 1;
+ dev_info->max_rx_pktlen = RTAP_MAX_RX_PKTLEN;
+ dev_info->min_rx_bufsize = RTAP_MIN_RX_BUFSIZE;
+ dev_info->max_rx_queues = RTAP_MAX_QUEUES;
+ dev_info->max_tx_queues = RTAP_MAX_QUEUES;
+
+ dev_info->default_rxportconf = (struct rte_eth_dev_portconf) {
+ .burst_size = RTAP_DEFAULT_BURST,
+ .ring_size = RTAP_NUM_BUFFERS,
+ .nb_queues = 1,
+ };
+ dev_info->default_txportconf = (struct rte_eth_dev_portconf) {
+ .burst_size = RTAP_DEFAULT_BURST,
+ .ring_size = RTAP_NUM_BUFFERS,
+ .nb_queues = 1,
+ };
+ return 0;
+}
+
+static int
+rtap_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
+ struct eth_queue_stats *qstats)
+{
+ struct rtap_pmd *pmd = dev->data->dev_private;
+ struct rtnl_link_stats64 kstats;
+ uint16_t i;
+
+ for (i = 0; i < dev->data->nb_rx_queues; i++) {
+ struct rtap_rx_queue *rxq = dev->data->rx_queues[i];
+ if (rxq == NULL)
+ continue;
+
+ stats->ipackets += rxq->rx_packets;
+ stats->ibytes += rxq->rx_bytes;
+ stats->ierrors += rxq->rx_errors;
+
+ if (qstats != NULL && i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
+ qstats->q_ipackets[i] = rxq->rx_packets;
+ qstats->q_ibytes[i] = rxq->rx_bytes;
+ qstats->q_errors[i] = rxq->rx_errors;
+ }
+ }
+
+ for (i = 0; i < dev->data->nb_tx_queues; i++) {
+ struct rtap_tx_queue *txq = dev->data->tx_queues[i];
+ if (txq == NULL)
+ continue;
+
+ stats->opackets += txq->tx_packets;
+ stats->obytes += txq->tx_bytes;
+ stats->oerrors += txq->tx_errors;
+
+ if (qstats != NULL && i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
+ qstats->q_opackets[i] = txq->tx_packets;
+ qstats->q_obytes[i] = txq->tx_bytes;
+ }
+ }
+
+ /* Get kernel rx_dropped counter via netlink */
+ if (rtap_nl_get_stats(pmd->if_index, &kstats) == 0 &&
+ kstats.rx_dropped > pmd->rx_drop_base)
+ stats->imissed = kstats.rx_dropped - pmd->rx_drop_base;
+
+ return 0;
+}
+
+static int
+rtap_stats_reset(struct rte_eth_dev *dev)
+{
+ struct rtap_pmd *pmd = dev->data->dev_private;
+ struct rtnl_link_stats64 kstats;
+ uint16_t i;
+
+ for (i = 0; i < dev->data->nb_rx_queues; i++) {
+ struct rtap_rx_queue *rxq = dev->data->rx_queues[i];
+ if (rxq == NULL)
+ continue;
+
+ rxq->rx_packets = 0;
+ rxq->rx_bytes = 0;
+ rxq->rx_errors = 0;
+ }
+
+ for (i = 0; i < dev->data->nb_tx_queues; i++) {
+ struct rtap_tx_queue *txq = dev->data->tx_queues[i];
+ if (txq == NULL)
+ continue;
+
+ txq->tx_packets = 0;
+ txq->tx_bytes = 0;
+ txq->tx_errors = 0;
+ }
+
+ /* Capture current rx_dropped as baseline via netlink */
+ if (rtap_nl_get_stats(pmd->if_index, &kstats) == 0)
+ pmd->rx_drop_base = kstats.rx_dropped;
+
+ return 0;
+}
+
static int
rtap_dev_close(struct rte_eth_dev *dev)
{
@@ -247,7 +363,10 @@ static const struct eth_dev_ops rtap_ops = {
.dev_start = rtap_dev_start,
.dev_stop = rtap_dev_stop,
.dev_configure = rtap_dev_configure,
+ .dev_infos_get = rtap_dev_info,
.dev_close = rtap_dev_close,
+ .stats_get = rtap_stats_get,
+ .stats_reset = rtap_stats_reset,
.rx_queue_setup = rtap_rx_queue_setup,
.rx_queue_release = rtap_rx_queue_release,
.tx_queue_setup = rtap_tx_queue_setup,
@@ -262,6 +381,7 @@ rtap_create(struct rte_eth_dev *dev, const char *tap_name, uint8_t persist)

pmd->keep_fd = -1;
pmd->nlsk_fd = -1;
+ pmd->rx_drop_base = 0;

dev->dev_ops = &rtap_ops;

--
2.51.0