AF_XDP-interaction: Implement a TX batching function

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
This commit is contained in:
Jesper Dangaard Brouer
2021-12-07 18:12:11 +01:00
parent 8b02218dde
commit 56ba3a10df

View File

@ -803,6 +803,77 @@ static void tx_pkt(struct xsk_socket_info *xsk)
//complete_tx(xsk);
}
/* Generate some fake packets (in umem area). Real system will deliver TX
* packets containing the needed control information.
*/
static int invent_tx_pkts(struct xsk_umem_info *umem,
const unsigned int n, struct xdp_desc pkts[n])
{
uint32_t len = opt_pkt_size;
uint32_t offset = 256;
int i;
for (i = 0; i < n; i++) {
uint64_t pkt_addr = mem_alloc_umem_frame(&umem->mem);
struct xdp_desc desc;
uint8_t *pkt_data;
if (pkt_addr == INVALID_UMEM_FRAME)
return i;
pkt_addr += offset;
desc.addr = pkt_addr;
desc.len = len;
desc.options = 0;
/* Write into packet memory area */
pkt_data = xsk_umem__get_data(umem->buffer, pkt_addr);
gen_base_pkt(pkt_data);
pkts[i] = desc;
}
return i;
}
static int tx_batch_pkts(struct xsk_socket_info *xsk, const unsigned int n)
{
struct xsk_umem_info *umem = xsk->umem;
struct xdp_desc pkts[n];
uint32_t tx_res;
uint32_t tx_idx = 0;
int i, nr;
nr = invent_tx_pkts(umem, n, pkts);
tx_res = xsk_ring_prod__reserve(&xsk->tx, nr, &tx_idx);
if (tx_res != nr) {
/* No more transmit slots, drop all packets. Normally AF_XDP
* code would try to run TX-completion CQ step to free up slots,
* but we don't want to introduce variability due to RT
* requirements. Other code make sure CQ is processed.
*/
for (i = 0; i < nr; i++) {
mem_free_umem_frame(&umem->mem, pkts[i].addr);
}
return 0;
}
for (i = 0; i < nr ; i++) {
struct xdp_desc *tx_desc;
tx_desc = xsk_ring_prod__tx_desc(&xsk->tx, tx_idx + i);
*tx_desc = pkts[i];
//xsk_ring_prod__tx_desc(&xsk->tx, tx_idx)->addr = pkt_addr;
//xsk_ring_prod__tx_desc(&xsk->tx, tx_idx)->len = 64;
xsk->outstanding_tx++;
}
xsk_ring_prod__submit(&xsk->tx, nr);
// sendto(xsk_socket__fd(xsk->xsk), NULL, 0, MSG_DONTWAIT, NULL, 0);
complete_tx(xsk);
return nr;
}
static bool process_packet(struct xsk_socket_info *xsk,
uint64_t addr, uint32_t len)
{
@ -923,7 +994,8 @@ static void handle_receive_packets(struct xsk_socket_info *xsk)
if (!rcvd)
return;
tx_pkt(xsk);
//tx_pkt(xsk);
tx_batch_pkts(xsk, 4);
/* Process received packets */
for (i = 0; i < rcvd; i++) {