Thanks, Stephen,
Because in container scenario, we need to assign xdp attach mode manually.
Currently I have a workaround solution, in xsk_configure() function, to get the mode from environment variable and assign to xsk_socket_config.xdp_flags. But it's not easy to maintain for DPDK version upgrades.
So here is the request for DPDK AF_XDP PMD to add new option for xdp attach mode in future new release.
=========================================================================
static int
xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
int ring_size)
{
struct xsk_socket_config cfg;
struct pkt_tx_queue *txq = rxq->pair;
int ret = 0;
int reserve_size = ETH_AF_XDP_DFLT_NUM_DESCS;
struct rte_mbuf *fq_bufs[reserve_size];
bool reserve_before;
rxq->umem = xdp_umem_configure(internals, rxq);
if (rxq->umem == NULL)
return -ENOMEM;
txq->umem = rxq->umem;
reserve_before = __atomic_load_n(&rxq->umem->refcnt, __ATOMIC_ACQUIRE) <= 1;
#if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
ret = rte_pktmbuf_alloc_bulk(rxq->umem->mb_pool, fq_bufs, reserve_size);
if (ret) {
AF_XDP_LOG(DEBUG, "Failed to get enough buffers for fq.\n");
goto out_umem;
} else {
AF_XDP_LOG(DEBUG, "XDP_UMEM_UNALIGNED_CHUNK_FLAG Got enough buffers for fq.\n");
}
#endif
/* reserve fill queue of queues not (yet) sharing UMEM */
if (reserve_before) {
ret = reserve_fill_queue(rxq->umem, reserve_size, fq_bufs, &rxq->fq);
if (ret) {
AF_XDP_LOG(ERR, "Failed to reserve fill queue.\n");
goto out_umem;
} else {
AF_XDP_LOG(DEBUG, "Reserved fill queue.\n");
}
} else {
AF_XDP_LOG(DEBUG, "No need to reserve fill queue.\n");
}
cfg.rx_size = ring_size;
cfg.tx_size = ring_size;
cfg.libbpf_flags = 0;
cfg.xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST;
cfg.bind_flags = 0;
/* Force AF_XDP socket into copy mode when users want it */
if (internals->force_copy)
cfg.bind_flags |= XDP_COPY;
/* #define XDP_FLAGS_UPDATE_IF_NOEXIST (1U << 0)
* #define XDP_FLAGS_SKB_MODE (1U << 1)
* #define XDP_FLAGS_DRV_MODE (1U << 2)
* #define XDP_FLAGS_HW_MODE (1U << 3)
*/
const char *env_xdp_attach_mode;
env_xdp_attach_mode = getenv(XDP_ATTACH_MODE);
if (env_xdp_attach_mode) {
AF_XDP_LOG(INFO,"XDP attach mode enviroment variable is %s.\n", env_xdp_attach_mode);
if (env_xdp_attach_mode[0] == '1' && env_xdp_attach_mode[1] == '\0')
cfg.xdp_flags |= XDP_FLAGS_SKB_MODE;
else if (env_xdp_attach_mode[0] == '2' && env_xdp_attach_mode[1] == '\0')
cfg.xdp_flags |= XDP_FLAGS_DRV_MODE;
else if (env_xdp_attach_mode[0] == '3' && env_xdp_attach_mode[1] == '\0')
cfg.xdp_flags |= XDP_FLAGS_HW_MODE;
else
AF_XDP_LOG(INFO,"XDP attach mode enviroment variable shall be 1 or 2 or 3.\n");
} else {
AF_XDP_LOG(INFO,"No XDP attach mode enviroment variable.\n");
}
==============================================================================================
From: Stephen Hemminger <stephen@networkplumber.org>
Sent: Thursday, October 24, 2024 12:09 AM
To: Xiaohua Wang <xiaohua.wang@ericsson.com>
Cc: dev@dpdk.org <dev@dpdk.org>
Subject: Re: Can DPDK AF_XDP PMD support macvlan driver in container?