Skip to content

Commit b186e0b

Browse files
infra: add stats for control plane
Add new fields in the existing stats structure to track the number of packets sent/received by the control plane interfaces, gr-loop included. Signed-off-by: Christophe Fontaine <[email protected]>
1 parent af3726e commit b186e0b

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

modules/infra/api/gr_infra.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ struct gr_iface_stats {
240240
uint64_t tx_packets;
241241
uint64_t tx_bytes;
242242
uint64_t tx_errors;
243+
uint64_t cp_rx_packets;
244+
uint64_t cp_rx_bytes;
245+
uint64_t cp_tx_packets;
246+
uint64_t cp_tx_bytes;
243247
};
244248

245249
struct gr_infra_iface_stats_get_resp {

modules/infra/api/stats.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ static struct api_out iface_stats_get(const void * /*request*/, struct api_ctx *
266266
s.tx_packets = 0;
267267
s.tx_bytes = 0;
268268
s.tx_errors = 0;
269+
s.cp_rx_packets = 0;
270+
s.cp_rx_bytes = 0;
271+
s.cp_tx_packets = 0;
272+
s.cp_tx_bytes = 0;
269273

270274
// Aggregate per-core stats
271275
for (int i = 0; i < RTE_MAX_LCORE; i++) {
@@ -274,6 +278,10 @@ static struct api_out iface_stats_get(const void * /*request*/, struct api_ctx *
274278
s.rx_bytes += sw_stats->rx_bytes;
275279
s.tx_packets += sw_stats->tx_packets;
276280
s.tx_bytes += sw_stats->tx_bytes;
281+
s.cp_rx_packets += sw_stats->cp_rx_packets;
282+
s.cp_rx_bytes += sw_stats->cp_rx_bytes;
283+
s.cp_tx_packets += sw_stats->cp_tx_packets;
284+
s.cp_tx_bytes += sw_stats->cp_tx_bytes;
277285
}
278286

279287
if (iface->type == GR_IFACE_TYPE_PORT) {
@@ -386,17 +394,26 @@ telemetry_ifaces_info_get(const char * /*cmd*/, const char * /*params*/, struct
386394

387395
// Software stats
388396
uint64_t rx_pkts = 0, rx_bytes = 0, tx_pkts = 0, tx_bytes = 0;
397+
uint64_t cp_rx_pkts = 0, cp_rx_bytes = 0, cp_tx_pkts = 0, cp_tx_bytes = 0;
389398
for (int i = 0; i < RTE_MAX_LCORE; i++) {
390399
struct iface_stats *sw_stats = iface_get_stats(i, iface->id);
391400
rx_pkts += sw_stats->rx_packets;
392401
rx_bytes += sw_stats->rx_bytes;
393402
tx_pkts += sw_stats->tx_packets;
394403
tx_bytes += sw_stats->tx_bytes;
404+
cp_rx_pkts += sw_stats->cp_rx_packets;
405+
cp_rx_bytes += sw_stats->cp_rx_bytes;
406+
cp_tx_pkts += sw_stats->cp_tx_packets;
407+
cp_tx_bytes += sw_stats->cp_tx_bytes;
395408
}
396409
rte_tel_data_add_dict_uint(stats_container, "rx_packets", rx_pkts);
397410
rte_tel_data_add_dict_uint(stats_container, "rx_bytes", rx_bytes);
398411
rte_tel_data_add_dict_uint(stats_container, "tx_packets", tx_pkts);
399412
rte_tel_data_add_dict_uint(stats_container, "tx_bytes", tx_bytes);
413+
rte_tel_data_add_dict_uint(stats_container, "cp_rx_packets", cp_rx_pkts);
414+
rte_tel_data_add_dict_uint(stats_container, "cp_rx_bytes", cp_rx_bytes);
415+
rte_tel_data_add_dict_uint(stats_container, "cp_tx_packets", cp_tx_pkts);
416+
rte_tel_data_add_dict_uint(stats_container, "cp_tx_bytes", cp_tx_bytes);
400417

401418
// Get hardware stats for physical ports.
402419
if (iface->type == GR_IFACE_TYPE_PORT) {

modules/infra/cli/iface.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ static cmd_status_t iface_stats(struct gr_api_client *c, const struct ec_pnode *
324324
scols_table_new_column(table, "TX_PACKETS", 0, SCOLS_FL_RIGHT);
325325
scols_table_new_column(table, "TX_BYTES", 0, SCOLS_FL_RIGHT);
326326
scols_table_new_column(table, "TX_ERRORS", 0, SCOLS_FL_RIGHT);
327+
scols_table_new_column(table, "CP_RX_PACKETS", 0, SCOLS_FL_RIGHT);
328+
scols_table_new_column(table, "CP_RX_BYTES", 0, SCOLS_FL_RIGHT);
329+
scols_table_new_column(table, "CP_TX_PACKETS", 0, SCOLS_FL_RIGHT);
330+
scols_table_new_column(table, "CP_TX_BYTES", 0, SCOLS_FL_RIGHT);
327331
scols_table_set_column_separator(table, " ");
328332

329333
for (uint16_t i = 0; i < resp->n_stats; i++) {
@@ -346,6 +350,10 @@ static cmd_status_t iface_stats(struct gr_api_client *c, const struct ec_pnode *
346350
scols_line_sprintf(line, 4, "%lu", resp->stats[i].tx_packets);
347351
scols_line_sprintf(line, 5, "%lu", resp->stats[i].tx_bytes);
348352
scols_line_sprintf(line, 6, "%lu", resp->stats[i].tx_errors);
353+
scols_line_sprintf(line, 7, "%lu", resp->stats[i].cp_rx_packets);
354+
scols_line_sprintf(line, 8, "%lu", resp->stats[i].cp_rx_bytes);
355+
scols_line_sprintf(line, 9, "%lu", resp->stats[i].cp_tx_packets);
356+
scols_line_sprintf(line, 10, "%lu", resp->stats[i].cp_tx_bytes);
349357
}
350358

351359
scols_print_table(table);

modules/infra/control/gr_iface.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ struct __rte_cache_aligned iface_stats {
9292
uint64_t rx_bytes;
9393
uint64_t tx_packets;
9494
uint64_t tx_bytes;
95+
uint64_t cp_rx_packets;
96+
uint64_t cp_rx_bytes;
97+
uint64_t cp_tx_packets;
98+
uint64_t cp_tx_bytes;
9599
};
96100

97101
#define MAX_IFACES 1024

modules/infra/control/loopback.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static void finalize_fd(struct event *ev, void * /*priv*/) {
5353
void loopback_tx(struct rte_mbuf *m) {
5454
struct mbuf_data *d = mbuf_data(m);
5555
struct iface_info_loopback *lo;
56+
struct iface_stats *stats;
5657
struct iovec iov[2];
5758
struct tun_pi pi;
5859
char *data;
@@ -97,16 +98,21 @@ void loopback_tx(struct rte_mbuf *m) {
9798
LOG(ERR, "write to tun device failed %s", strerror(errno));
9899
}
99100

101+
stats = iface_get_stats(rte_lcore_id(), d->iface->id);
102+
stats->cp_tx_packets += 1;
103+
stats->cp_tx_bytes += rte_pktmbuf_pkt_len(m);
104+
100105
end:
101106
if (!rte_pktmbuf_is_contiguous(m))
102107
rte_free(data);
103108
rte_pktmbuf_free(m);
104109
}
105110

106111
static void iface_loopback_poll(evutil_socket_t, short reason, void *ev_iface) {
107-
struct eth_input_mbuf_data *e;
108-
struct iface_info_loopback *lo;
109112
struct iface *iface = ev_iface;
113+
struct iface_info_loopback *lo;
114+
struct eth_input_mbuf_data *e;
115+
struct iface_stats *stats;
110116
struct rte_mbuf *mbuf;
111117
size_t read_len;
112118
size_t len;
@@ -155,6 +161,10 @@ static void iface_loopback_poll(evutil_socket_t, short reason, void *ev_iface) {
155161
e->iface = iface;
156162
e->domain = ETH_DOMAIN_LOOPBACK;
157163

164+
stats = iface_get_stats(rte_lcore_id(), iface->id);
165+
stats->cp_rx_packets += 1;
166+
stats->cp_rx_bytes += rte_pktmbuf_pkt_len(mbuf);
167+
158168
post_to_stack(loopback_get_control_id(), mbuf);
159169
return;
160170

0 commit comments

Comments
 (0)