DPDK offload應用筆記

查看網卡 offload 功能

  1. 使用 ethtool

使用 ethtool 可以看一般的 網卡。

ethtool -k <link_name>
  1. dpdk 的做法

在 dpdk 中可以使用以下函數來查看是否支持 offload 功能。

ixgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)

例子:

網卡 dev_info->rx_offload_capa dev_info->tx_offload_capa
I350 0xf 0x3f
82599ES 0x1f 0x3f

對照源碼上的宏開關,以上的網卡都是支持 ipv4 offload 的。

/**
 * RX offload capabilities of a device.
 */                                                         //  0xf        0x1f
#define DEV_RX_OFFLOAD_VLAN_STRIP  0x00000001               //   *          *
#define DEV_RX_OFFLOAD_IPV4_CKSUM  0x00000002               //   *          *          <--- IPV4
#define DEV_RX_OFFLOAD_UDP_CKSUM   0x00000004               //   *          *
#define DEV_RX_OFFLOAD_TCP_CKSUM   0x00000008               //   *          *
#define DEV_RX_OFFLOAD_TCP_LRO     0x00000010               //              * 
#define DEV_RX_OFFLOAD_QINQ_STRIP  0x00000020               //
#define DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM 0x00000040          //

/**
 * TX offload capabilities of a device. 
 */                                                         //  0x3f
#define DEV_TX_OFFLOAD_VLAN_INSERT 0x00000001               //   *
#define DEV_TX_OFFLOAD_IPV4_CKSUM  0x00000002               //   *                     <--- IPV4
#define DEV_TX_OFFLOAD_UDP_CKSUM   0x00000004               //   *
#define DEV_TX_OFFLOAD_TCP_CKSUM   0x00000008               //   *
#define DEV_TX_OFFLOAD_SCTP_CKSUM  0x00000010               //   *
#define DEV_TX_OFFLOAD_TCP_TSO     0x00000020               //   *
#define DEV_TX_OFFLOAD_UDP_TSO     0x00000040               //
#define DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM 0x00000080 /**< Used for tunneling packet. */
#define DEV_TX_OFFLOAD_QINQ_INSERT 0x00000100	

mbuf 的設置

一個報文想要 offload。mbuf 上還需要設置 ol_flags,l2_len,l3_len。
並且注意要清除 ipv4 報文的 checksum 字段。

以下是 programmer’s guide 的例子:

mb->l2_len = len(out_eth)
mb->l3_len = len(out_ip)
mb->ol_flags |= PKT_TX_IPV4 | PKT_TX_IP_CSUM
/* clean up the ipv4 checksum field */

詳細的宏開關需可以參考:

/**
 * Offload the IP checksum in the hardware. The flag PKT_TX_IPV4 should
 * also be set by the application, although a PMD will only check
 * PKT_TX_IP_CKSUM.
 *  - set the IP checksum field in the packet to 0
 *  - fill the mbuf offload information: l2_len, l3_len
 */
#define PKT_TX_IP_CKSUM      (1ULL << 54)

/**
 * Packet is IPv4. This flag must be set when using any offload feature
 * (TSO, L3 or L4 checksum) to tell the NIC that the packet is an IPv4
 * packet. If the packet is a tunneled packet, this flag is related to
 * the inner headers.
 */
#define PKT_TX_IPV4          (1ULL << 55)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章