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;
+ }
+#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;
+ }
+ }
cfg.rx_size = ring_size;
cfg.tx_size = ring_size;
cfg.bind_flags |= XDP_USE_NEED_WAKEUP;
#endif
- if (strnlen(internals->prog_path, PATH_MAX) &&
- !internals->custom_prog_configured) {
- ret = load_custom_xdp_prog(internals->prog_path,
- internals->if_index,
- &internals->map);
- if (ret) {
- AF_XDP_LOG(ERR, "Failed to load custom XDP program %s\n",
- internals->prog_path);
- goto err;
+ if (strnlen(internals->prog_path, PATH_MAX)) {
+ if (!internals->custom_prog_configured) {
+ ret = load_custom_xdp_prog(internals->prog_path,
+ internals->if_index,
+ &internals->map);
+ if (ret) {
+ AF_XDP_LOG(ERR, "Failed to load custom XDP program %s\n",
+ internals->prog_path);
+ goto out_umem;
+ }
+ internals->custom_prog_configured = 1;
}
- internals->custom_prog_configured = 1;
- cfg.libbpf_flags = XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD;
+ cfg.libbpf_flags |= XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD;
}
if (internals->shared_umem)
if (ret) {
AF_XDP_LOG(ERR, "Failed to create xsk socket.\n");
- goto err;
+ goto out_umem;
+ }
+
+ if (!reserve_before) {
+ /* reserve fill queue of queues sharing UMEM */
+ 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_xsk;
+ }
}
/* insert the xsk into the xsks_map */
&rxq->xsk_queue_idx, &fd, 0);
if (err) {
AF_XDP_LOG(ERR, "Failed to insert xsk in map.\n");
- goto err;
+ goto out_xsk;
}
}
-#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 err;
- }
-#endif
-
if (rxq->busy_budget) {
ret = configure_preferred_busy_poll(rxq);
if (ret) {
AF_XDP_LOG(ERR, "Failed configure busy polling.\n");
- goto err;
+ goto out_xsk;
}
}
- ret = reserve_fill_queue(rxq->umem, reserve_size, fq_bufs, &rxq->fq);
- if (ret) {
- xsk_socket__delete(rxq->xsk);
- AF_XDP_LOG(ERR, "Failed to reserve fill queue.\n");
- goto err;
- }
-
return 0;
-err:
+out_xsk:
+ xsk_socket__delete(rxq->xsk);
+out_umem:
if (__atomic_sub_fetch(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) == 0)
xdp_umem_destroy(rxq->umem);