Skip to content

Commit c429d72

Browse files
magnus-karlssonkernel-patches-bot
authored andcommitted
samples/bpf: increment Tx stats at sending
Increment the statistics over how many Tx packets have been sent at the time of sending instead of at the time of completion. This as a completion event means that the buffer has been sent AND returned to user space. The packet always gets sent shortly after sendto() is called. The kernel might, for performance reasons, decide to not return every single buffer to user space immediately after sending, for example, only after a batch of packets have been transmitted. Incrementing the number of packets sent at completion, will in that case be confusing as if you send a single packet, the counter might show zero for a while even though the packet has been transmitted. Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com> Acked-by: John Fastabend <john.fastabend@gmail.com>
1 parent 12422f9 commit c429d72

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

samples/bpf/xdpsock_user.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,6 @@ static inline void complete_tx_l2fwd(struct xsk_socket_info *xsk,
11461146
xsk_ring_prod__submit(&xsk->umem->fq, rcvd);
11471147
xsk_ring_cons__release(&xsk->umem->cq, rcvd);
11481148
xsk->outstanding_tx -= rcvd;
1149-
xsk->ring_stats.tx_npkts += rcvd;
11501149
}
11511150
}
11521151

@@ -1168,7 +1167,6 @@ static inline void complete_tx_only(struct xsk_socket_info *xsk,
11681167
if (rcvd > 0) {
11691168
xsk_ring_cons__release(&xsk->umem->cq, rcvd);
11701169
xsk->outstanding_tx -= rcvd;
1171-
xsk->ring_stats.tx_npkts += rcvd;
11721170
}
11731171
}
11741172

@@ -1260,6 +1258,7 @@ static void tx_only(struct xsk_socket_info *xsk, u32 *frame_nb, int batch_size)
12601258
}
12611259

12621260
xsk_ring_prod__submit(&xsk->tx, batch_size);
1261+
xsk->ring_stats.tx_npkts += batch_size;
12631262
xsk->outstanding_tx += batch_size;
12641263
*frame_nb += batch_size;
12651264
*frame_nb %= NUM_FRAMES;
@@ -1348,6 +1347,7 @@ static void l2fwd(struct xsk_socket_info *xsk, struct pollfd *fds)
13481347
}
13491348
return;
13501349
}
1350+
xsk->ring_stats.rx_npkts += rcvd;
13511351

13521352
ret = xsk_ring_prod__reserve(&xsk->tx, rcvd, &idx_tx);
13531353
while (ret != rcvd) {
@@ -1379,7 +1379,7 @@ static void l2fwd(struct xsk_socket_info *xsk, struct pollfd *fds)
13791379
xsk_ring_prod__submit(&xsk->tx, rcvd);
13801380
xsk_ring_cons__release(&xsk->rx, rcvd);
13811381

1382-
xsk->ring_stats.rx_npkts += rcvd;
1382+
xsk->ring_stats.tx_npkts += rcvd;
13831383
xsk->outstanding_tx += rcvd;
13841384
}
13851385

0 commit comments

Comments
 (0)