为什么bnx2x_recv_pkts将dbuk中的mbuf data_off设置为cqe_fp-> placement_offset?

时间:2017-05-03 02:17:17

标签: dpdk

我设置了256字节的标题空间,我想用它来保存私有数据,但是bnx2x_recv_pkts方法在dpdk中将mbuf data_off设置为cqe_fp->placement_offset?为什么呢?

len = cqe_fp->pkt_len_or_gro_seg_len;
**pad = cqe_fp->placement_offset;**

new_mb = rte_mbuf_raw_alloc(rxq->mb_pool);
if (unlikely(!new_mb)) {
    PMD_RX_LOG(ERR, "mbuf alloc fail fp[%02d]", fp->index);
    rte_eth_devices[rxq->port_id].data->
            rx_mbuf_alloc_failed++;
    goto next_rx;
}

rx_mb = rxq->sw_ring[bd_cons];
rxq->sw_ring[bd_cons] = new_mb;
rxq->rx_ring[bd_prod] = new_mb->buf_physaddr;

rx_pref = NEXT_RX_BD(bd_cons) & MAX_RX_BD(rxq);
rte_prefetch0(rxq->sw_ring[rx_pref]);
if ((rx_pref & 0x3) == 0) {
    rte_prefetch0(&rxq->rx_ring[rx_pref]);
    rte_prefetch0(&rxq->sw_ring[rx_pref]);
}

**rx_mb->data_off = pad;**
rx_mb->nb_segs = 1;
rx_mb->next = NULL;
rx_mb->pkt_len = rx_mb->data_len = len;
rx_mb->port = rxq->port_id;
rte_prefetch1(rte_pktmbuf_mtod(rx_mb, void *));

2 个答案:

答案 0 :(得分:0)

虽然它无法解决您的问题,但您可能需要考虑使用mbuf私有区域,该区域位于mbuf头和数据缓冲区之间。

它可以是任何尺寸,对PMD完全透明。有关更多详细信息,请参阅rte_pktmbuf_pool_create():

http://dpdk.org/doc/api/rte__mbuf_8h.html#a593921f13307803b94bbb4e0932db962

答案 1 :(得分:0)

我认为这是一个错误。我修改代码就好了。

    new_mb = rte_mbuf_raw_alloc(rxq->mb_pool);
    if (unlikely(!new_mb)) {
        PMD_RX_LOG(ERR, "mbuf alloc fail fp[%02d]", fp->index);
        rte_eth_devices[rxq->port_id].data->
                rx_mbuf_alloc_failed++;
        goto next_rx;
    }   
    new_mb->data_off = RTE_PKTMBUF_HEADROOM;

    rx_mb = rxq->sw_ring[bd_cons];
    rxq->sw_ring[bd_cons] = new_mb;
    //rxq->rx_ring[bd_prod] = new_mb->buf_physaddr;
    rxq->rx_ring[bd_prod] = rte_cpu_to_le_64(rte_mbuf_data_dma_addr_default(new_mb));

将new_mb-> buf_physaddr编辑为rte_cpu_to_le_64(rte_mbuf_data_dma_addr_default(new_mb)),这将跳过余量。

when setup queue of nic. bnx2x_dev_rx_queue_setup will call.
    for (idx = 0; idx < rxq->nb_rx_desc; idx = NEXT_RX_BD(idx)) {
    mbuf = rte_mbuf_raw_alloc(mp);
    if (NULL == mbuf) {
        PMD_RX_LOG(ERR, "RX mbuf alloc failed queue_id=%u, idx=%d",
               (unsigned)rxq->queue_id, idx);
        bnx2x_rx_queue_release(rxq);
        return -ENOMEM;
    }
    rxq->sw_ring[idx] = mbuf;
    //rxq->rx_ring[idx] = mbuf->buf_physaddr;
    rxq->rx_ring[idx] = rte_cpu_to_le_64(rte_mbuf_data_dma_addr_default(mbuf));  
}