DPDK(一)源碼組織框架

剛拿到DPDK學習任務的時候一臉懵,這麼多內容根本不知道從哪看起,走了很多彎路,效率很低,故記錄下本文,幫助有需要的人。

本文分四部分介紹DPDK源碼的組織架構。

在本文的描述中 RTE_SDK 作爲環境變量指向DPDK源碼包解壓出來的文件根目錄。 參看 構建系統提供的有用變量 獲取更多的變量描述。

1.Makefile和Config

由DPDK庫和應用程序提供的 Makefiles 位於 $(RTE_SDK)/mk 中。

配置模板位於 $(RTE_SDK)/config。這些模板描述了爲每個目標啓用的選項。 配置文件許多可以爲DPDK庫啓用或禁用的選項,包括調試選項。用戶應該查看配置文件並熟悉這些選項。配置文件同樣也用於創建頭文件,創建的頭文件將位於新生成的目錄中。

2.庫

庫文件源碼位於目錄$(RTE_SDK)/lib中。按照慣例,庫指的是爲應用程序提供API的任何代碼。通常,它會生成一個(.a)文件,這個目錄中可能也保存一些內核模塊。

Lib目錄包含如下項目

lib
+-- librte_cmdline      # 命令行接口
+-- librte_distributor  # 報文分發器
+-- librte_eal          # 環境抽象層
+-- librte_ether        # PMD通用接口
+-- librte_hash         # 哈希庫
+-- librte_ip_frag      # IP分片庫
+-- librte_kni          # 內核NIC接口
+-- librte_kvargs       # 參數解析庫
+-- librte_lpm          # 最長前綴匹配庫
+-- librte_mbuf         # 報文及控制緩衝區操作庫
+-- librte_mempool      # 內存池管理器
+-- librte_meter        # QoS metering 庫
+-- librte_net          # IP相關的一些頭部
+-- librte_power        # 電源管理庫
+-- librte_ring         # 軟件無鎖環形緩衝區
+-- librte_sched        # QoS調度器和丟包器庫
+-- librte_timer        # 定時器庫

3.驅動

驅動程序是爲設備(硬件設備或者虛擬設備)提供輪詢模式驅動程序實現的特殊庫。 他們包含在drivers子目錄中,按照類型分類,各自編譯成一個庫,其格式爲 librte_pmd_X.a ,其中 X 是驅動程序的名稱。

驅動程序目錄下有個 net 子目錄,包括如下項目:

drivers/net
+-- af_packet          # 基於Linux af_packet的pmd
+-- bonding            # 綁定pmd驅動
+-- cxgbe              # Chelsio Terminator 10GbE/40GbE pmd
+-- e1000              # 1GbE pmd (igb and em)
+-- enic               # Cisco VIC Ethernet NIC Poll-mode Driver
+-- fm10k              # Host interface PMD driver for FM10000 Series
+-- i40e               # 40GbE poll mode driver
+-- ixgbe              # 10GbE poll mode driver
+-- mlx4               # Mellanox ConnectX-3 poll mode driver
+-- null               # NULL poll mode driver for testing
+-- pcap               # PCAP poll mode driver
+-- ring               # Ring poll mode driver
+-- szedata2           # SZEDATA2 poll mode driver
+-- virtio             # Virtio poll mode driver
+-- vmxnet3            # VMXNET3 poll mode driver
+-- xenvirt            # Xen virtio poll mode driver

部分 driver/net 目錄包含一個base子目錄,這個目錄通常包含用戶不能直接修改的代碼。 任何修訂或增強都應該X_osdep.c或X_osdep.h文件完成。請參閱base目錄中本地的自述文件以獲取更多的信息。

4.應用程序

應用程序是包含 main() 函數的源文件。 他們位於 $(RTE_SDK)/app 和 $(RTE_SDK)/examples 目錄中。

應用程序目錄包含用於測試DPPDK(如自動測試)或輪詢模式驅動程序(test-pmd)的實例應用程序:

app
+-- chkincs            # Test program to check include dependencies
+-- cmdline_test       # Test the commandline library
+-- test               # Autotests to validate DPDK features
+-- test-acl           # Test the ACL library
+-- test-pipeline      # Test the IP Pipeline framework
+-- test-pmd           # Test and benchmark poll mode drivers

Example目錄包含示例應用程序,顯示瞭如何使用庫:

examples
+-- cmdline            # Example of using the cmdline library
+-- exception_path     # Sending packets to and from Linux TAP device
+-- helloworld         # Basic Hello World example
+-- ip_reassembly      # Example showing IP reassembly
+-- ip_fragmentation   # Example showing IPv4 fragmentation
+-- ipv4_multicast     # Example showing IPv4 multicast
+-- kni                # Kernel NIC Interface (KNI) example
+-- l2fwd              # L2 forwarding with and without SR-IOV
+-- l3fwd              # L3 forwarding example
+-- l3fwd-power        # L3 forwarding example with power management
+-- l3fwd-vf           # L3 forwarding example with SR-IOV
+-- link_status_interrupt # Link status change interrupt example
+-- load_balancer      # Load balancing across multiple cores/sockets
+-- multi_process      # Example apps using multiple DPDK processes
+-- qos_meter          # QoS metering example
+-- qos_sched          # QoS scheduler and dropper example
+-- timer              # Example of using librte_timer library
+-- vmdq_dcb           # Example of VMDQ and DCB receiving
+-- vmdq               # Example of VMDQ receiving
+-- vhost              # Example of userspace vhost and switch

實際的實例目錄可能與上面顯示的有所出入。 相關詳細信息,請參考最新的DPDK代碼。

參考資料:DPDK官網說明文檔 https://dpdk-docs.readthedocs.io/en/latest/prog_guide/source_org.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章