英特尔DPDK开发者指南 – 开发环境

来源:互联网 发布:软件研发工程师 英文 编辑:程序博客网 时间:2024/06/05 19:30

http://laplace.in/?p=1



25.0 源码组织结构

本段描述Intel® DPDK框架的源码组织结构。

25.1 Make文件和配置文件

注意: 在后续的描述中,环境变量RTE_SDK指向解压压缩包时产生的基础目录。可以跳到构建系统提供的有用的变量 查看其他变量的描述。

DPDK提供的Makefile在$(RTE_SDK)/mk目录中。

配置文件模板在$(RTE_SDK)/config目录。这些模板描述了对应的生成目标的选项。配置文件中同时还包含了一些关于DPDK 的开关项,包括DEBUG选项。用户应该查看配置文件并熟悉其中的选项。配置文件同时用来生成头文件,这些头文件会被生成在 新的build文件夹内。

25.2 库文件

库文件放在$(RTE_SDK)/lib目录中。习惯上,我们调用库的代码来提供API给应用程序。 通常,这里会产生一个静态库(.a),不过内核模块也在这个文件夹下。lib文件夹包括:

25.3 应用程序

应用程序是指代码中含有main()函数的程序。它们在$(RTE_SDK)/app$(RTE_SDK)/examples目录中。

app目录中是一些用来自动测试DPDK的简单程序。

examples目录中则是一些显示如何使用库文件的样例程序。

注意: 实际的examples目录也许会有额外的应用程序,请查看最新的DPDK源码包。

26.0 开发套件构建系统

DPDK需要一个构建系统来支持编译等活动。本节描述的是使用DPDK框架时的限制与机制。 其中有有两个用例:

  • 编译DPDK库文件和示例程序。框架会产生指定的二进制库,其中包括了包含文件和示例程序
  • 使用已安装的DPDK库来编译一个外部的程序或库

26.1 构建开发套件的二进制文件

下文提供了如何构建DPDK二进制文件的细节

26.1.1 构建目录的概念

安装完毕后,会有一个构建目录被创建出来(译注:如下文中的i686-default-linuxapp-gcc)。每一个构建 目录都包括包含文件、库文件、应用程序:

一个构建目录对应一个包含了架构、执行环境、工具链的配置文件。相同的源码通过不同的配置文件 It is possible to have several build directories sharing the same sources with different configurations. 例如,想用默认的配置文件模板config/defconfig_x86_64-linuxapp创建一个构建目录my_sdk_build_dir,我们可以:

这会创建一个新目录my_sdk_build_dir。然后我们就可以编译它了:

这等同于执行:

my_sdk_build_dir中的内容如下:

参阅根make文件帮助获得能从DPDK根目录下执行的make命令的一些细节。

26.2 构建外部程序

本质上DPDK是一个开发套件,因此其第一要务是使用户能使用SDK创建应用程序。要想编译一个程序,用户必须 设置RTE_SDKRTE_TARGET环境变量。

对于一个新的程序,用户必须创建自己的Makefile,这个Makefile可能包含一些.mk文件, 比如:${RTE_SDK}/mk/DPDK.vars.mk${RTE_SDK}/mk/DPDK.app.mk。根据您选择的目标(包括架构、 机器、执行环境、工具链等,这些目标定义在Makefile中或作为一个环境变量),在编译应用程序和库文件时, 框架会选择合适的.h头文件和.a库文件。目标文件在${RTE_SDK}/arch-machine-execenv-toolchain (译注:其中arch、machine、execenv、toolchain应该依据编译环境而改变,如arch可以为i686、x86_64, toolchain可以为gcc、icc等),它会被环境变量${RTE_BIN_SDK}内在地引用。使用make命令即可编译应 用程序。编译结果会保存在/path/to/my_app/build目录。

examples目录提供了一些示例程序

26.3 Makefile说明

26.3.1 DPDK Makefile的通用规则

DPDK的Makefile永远依照如下的格式:

  1. 在开始处包含$(RTE_SDK)/mk/DPDK.vars.mk
  2. 为RTE构建系统定义指定的变量
  3. 包含指定的.mk文件$(RTE_SDK)/mk/DPDK.XYZ.mk,其中XYZ可以是app、lib、extapp、extlib、 obj、gnuconfigure等,具体应该用哪一个,完全取决于你想创建的项目的类型。请参阅Makefile类型
  4. 包含用户定义的规则和变量

下面是一个非常简单的外部应用的Makefile示例:

26.3.2 Makefile类型

用户创建的Makefile中最后包含的.mk文件决定了这个Makefile的角色。注意用同一个Makefile是不可 能既创建库文件又创建应用程序的。因此用户必须在不同的目录中创建两个独立的Makefile。任何情况下 用户都应该把rte.vars.mk包含进来。

26.3.2.1 应用程序

这些Makefile产生二进制应用。

  • rte.app.mk: 内部程序
  • rte.extapp.mk: 外部程序
  • rte.hostapp.mk: 宿主程序

26.3.2.2 静态库

创建.a静态库

  • rte.lib.mk: 内部库
  • rte.extlib.mk: 外部库
  • rte.hostlib.mk: 宿主库

26.3.2.3 安装

  • rte.install.mk: 不创建任何东西,仅仅是用于向安装目录创建链接文件。对于从开发框架包含文件很有用。

26.3.2.4 内核模块

  • rte.module.mk: 用框架创建一个内核模块

26.3.2.5 目标文件

  • rte.obj.mk: 将许多目标文件合并为一个,在框架内使用
  • rte.extobj.mk: 将许多目标文件合并为一个,在框架外使用

26.3.2.6 杂项

  • rte.doc.mk: 开发框架的文档
  • rte.gnuconfigure.mk: 创建基于configure的程序
  • rte.subdir.mk: 在框架内创建许多目录

26.3.3 构建系统提供的有用的变量

  • RTE_SDK: DPDK源码包的绝对路径。编译开发套件时框架会自动设置。当编译外部应用时,用户必须定义这个环境变量。
  • RTE_SRCDIR: 源码的路径。当编译开发套件时RTE_SRCDIR等于RTE_SDK。编译外部应用时则指向外部应用的源码目录。
  • RTE_OUTPUT: 输出文件的路径。通常情况下是$(RTE_SRCDIR)/build,通过make命令的O=选项可以重写该变量。
  • RTE_TARGET: 一个标识了编译目标的字符串。格式为arch-machine-execenv-toolchain。编译SDK时是由构建系 统通过配置文件(.config)推理出来的。编译外部应用时则必须由用户在Makefile或环境变量中指定。
  • RTE_SDK_BIN: $(RTE_SDK)/$(RTE_TARGET)的引用。
  • RTE_ARCH: 定义架构(i686, x86_64)。和CONFIG_RTE_ARCH值相同,只是不需要双引号括起来。
  • RTE_MACHINE : 定义目标机器。和CONFIG_RTE_MACHINE值相同,只是不需要双引号括起来。
  • RTE_TOOLCHAIN : 定义工具链(gcc、icc)。和CONFIG_RTE_TOOLCHAIN值相同,只是不需要双引号括起来。
  • RTE_EXEC_ENV: 定义执行环境(如linuxapp)。和CONFIG_RTE_EXEC_ENV值相同,只是不需要双引号括起来。
  • RTE_KERNELDIR: 这个变量包含了用来编译内核模块的内核源码的绝对路径。内核头文件必须和执行应用程序的目 标机器相匹配。默认情况下,这个变量设置为/lib/modules/$(shell uname -r)/build。当编译机和目标机相同时, 这是正确的。 26.3.4 Variables that Can be Set/Overridden in a Makefile Only
  • VPATH: The path list that the build system will search for sources. By default, RTE_SRCDIR will be included in VPATH.
  • CFLAGS: Flags to use for C compilation. The user should use += to append data in this variable.
  • LDFLAGS: Flags to use for linking. The user should use += to append data in this variable.
  • ASFLAGS: Flags to use for assembly. The user should use += to append data in this variable.
  • CPPFLAGS: Flags to use to give flags to C preprocessor (only useful when assembling .S files). The user should use += to append data in this variable.
  • LDLIBS: In an application, the list of libraries to link with (for example, -L / path/to/libfoo -lfoo). The user should use += to append data in this variable.
  • SRC-y: A list of source files (.c, .S, or .o if the source is a binary) in case of application, library or object Makefiles. The sources must be available from VPATH.
  • INSTALL-y-$(INSTPATH): A list of files to be installed in $(INSTPATH) . The files must be available from VPATH and will be copied in $(RTE_OUTPUT)/ $(INSTPATH) . Can be used in almost any RTE Makefile.
  • SYMLINK-y-$(INSTPATH): A list of files to be installed in $(INSTPATH) . The files must be available from VPATH and will be linked (symbolically) in $(RTE_OUTPUT)/$(INSTPATH). This variable can be used in almost any Intel ®DPDK Makefile.
  • PREBUILD: A list of prerequisite actions to be taken before building. The user should use += to append data in this variable.
  • POSTBUILD: A list of actions to be taken after the main build. The user should use += to append data in this variable.
  • PREINSTALL: A list of prerequisite actions to be taken before installing. The user should use += to append data in this variable.
  • POSTINSTALL: A list of actions to be taken after installing. The user should use += to append data in this variable.
  • PRECLEAN: A list of prerequisite actions to be taken before cleaning. The user should use += to append data in this variable.
  • POSTCLEAN: A list of actions to be taken after cleaning. The user should use += to append data in this variable.
  • DEPDIR-y: Only used in the development kit framework to specify if the build of the current directory depends on build of another one. This is needed to support parallel builds correctly. 26.3.5 Variables that can be Set/Overridden by the User on the Command Line Only Some variables can be used to configure the build system behavior. They are documented in Development Kit Root Makefile Help and External Application/Library Makefile help.
  • WERROR_CFLAGS: By default, this is set to a specific value that depends on the compiler. Users are encouraged to use this variable as follows: CFLAGS += $(WERROR_CFLAGS) This avoids the use of different cases depending on the compiler (icc or gcc ). Also, this variable can be overridden from the command line, which allows bypassing of the flags for testing purposes. 26.3.6 Variables that Can be Set/Ove rridden by the User in a Makefile or Command Line
  • CFLAGS_my_file.o: Specific flags to add for C compilation of my_file.c.
  • LDFLAGS_my_app: Specific flags to add when linking my_app.
  • NO_AUTOLIBS: If set, the libraries provided by the framework will not be included in the LDLIBS variable automatically.
  • EXTRA_CFLAGS: The content of this variable is appended after CFLAGS when compiling.
  • EXTRA_LDFLAGS: The content of this variable is appended after LDFLAGS when linking.
  • EXTRA_ASFLAGS: The content of this variable is appended after ASFLAGS when assembling.
  • EXTRA_CPPFLAGS: The content of this variable is appended after CPPFLAGS when using a C preprocessor on assembly files.

27.0 开发套件的根Makefile帮助

DPDK为目标提供根级的Makefile DPDK provides a root level Makefile with targets for configuration, building, cleaning, testing, installation and others. These targets are explained in the following sections. 27.1 配置目标 The configuration target requires the name of the target, which is specified using T=mytarget and it is mandatory. The list of available targets are in $(RTESDK)/ config (remove the defconfig prefix). Configuration targets also support the specific ation of the name of the output directory, using O=mybuilddir. This is an optional parameter, the default output directory is build. • config This will create a build directory, and generates a configuration from a template. A Makefile is also created in the new build directory. Example: make config O=mybuild T=x86_64-default-linuxapp-gcc

27.2 构建目标 Build targets support the optional specificat ion of the name of the output directory, using O=mybuilddir. The default output directory is build. • all , build or just make Build the Intel ® DPDK in the output directory previously created by a make config. Example: make O=mybuild • clean Clean all objects created using make build. Example: make clean O=mybuild • %_sub Build a subdirectory only, without managing dependencies on other directories. Example: make lib/librte_eal_sub O=mybuild • %_clean Clean a subdirectory only. Example: make lib/librte_eal_clean O=mybuild

27.3 安装目标 • install Build the Intel ® DPDK binary. Actually, this builds each supported target in a separate directory. The name of each directory is the name of the target. The name of the targets to install can be optionally specified using T=mytarget. The target name can contain wildcard characters. The list of available targets are in $(RTESDK)/config (remove the defconfig prefix). Example: make install T=x86_64- • uninstall Remove installed target directories.

27.4 测试目标 • test Launch automatic tests for a build directory specified using O=mybuilddir. It is optional, the default output directory is build. Example: make test O=mybuild • testall Launch automatic tests for all installed target directories (after a make install). The name of the targets to test can be optionally specified using T=mytarget. The target name can contain wildcard ( ) characters. The list of available targets are in $(RTESDK)/config (remove the defconfig prefix). Examples: make testall, make testall T=x86_64-

27.5 目标的文档 • doxydoc Generate the Doxygen documentation (pdf only).

27.6 目标的依赖

这个目标 This target is implicitly called by make config . Typically, there is no need for a user to call it, except if DEPDIRS-y variables have been updated in Makefiles. It will generate the file $(RTE_OUTPUT)/.depdirs. Example: make depdirs O=mybuild

This command generates a dot graph of dependencies. It can be displayed to debug circular dependency issues, or just to understand the dependencies. Example: make depgraph O=mybuild > /tmp/graph.dot && dotty /tmp/ graph.dot

27.7 目标杂项

显示帮助

27.8 其他有用的命令行变量

The following variables can be specified on the command line: • V= Enable verbose build (show full compilation command line, and some intermediate commands). • D= Enable dependency debugging. This provides some useful information about why a target is built or not. • EXTRA_CFLAGS= , EXTRA_LDFLAGS=, EXTRA_ASFLAGS=, EXTRA_CPPFLAGS= Append specific compilation, link or asm flags. • CROSS= Specify a cross toolchain header that will prefix all gcc/binutils applications. This only works when using gcc.

27.9 在构建目录make 以上描述的所有目标均在SDK的根$(RTE_SDK)被调用。在构建目录执行相同的Makefile目标也是可行的。 举例来说:

这和下面的等价:

27.10 编译用于调试

编译包含调试信息并且优化级别为0的DPDK框架及其示例程序,需要在编译前将EXTRA_CFLAGS变量设置为:

之后就可以像平常那样编译DPDK框架、示例程序甚至用户程序了:


28.0 扩展DPDK

本节将会记述一个开发者如何扩展DPDK,例如提供一个新库、一个新目标或者支持一个新目标。

28.1 示例:为DPDK增加一个新库libfoo

给DPDK增加新库,过程如下:

  • 增加一个新的配置选项:
  • 创建一个项目文件夹并创建源文件:
  • 给libfoo添加一个foo()函数。

在foo.c中定义:

在foo.h中声明:

  • 更新lib/Makefile:

在其中添加:

  • 为库创建一个新的Makefile,例如,可以从mempool库的Makefile文件派生一个:

将其中的librte_mempool替换为libfoorte_mempool替换为foo

  • 更新mk/DPDK.app.mk,添加-lfooLDLIBS变量(确保其可用)。之后,当链接DPDK应用时就能自动使用这个编译选项了。
  • 构建拥有新库的DPDK框架(这里只用一个目标作展示):
  • 检查库是否被安装:

28.1.1 示例: 在测试程序中使用libfoo

测试程序用来验证所有的DPDK功能是否有效。一旦你添加了新的库,就必须在测试程序用添加新的用例。

  • 首先应该添加一个test_foo.c文件。它包含foo.h并且从test_foo()调用foo(),当测试通过时test_foo()应该返回0。
  • Makefile、test.h和commands.c也都应该更新,以便执行测试用例。
  • 测试报告的产生: autotest.py是一个用来产生测试报告的脚本,它在${RTE_SDK}/doc/rst/test_report/autotests 目录下。这个脚本也应该更新。如果libfoo是一个新的测试族,${RTE_SDK}/doc/rst/test_report/test_report.rst中 的链接也应该更新。
  • 构建拥有新测试程序的DPDK框架(这里只用一个目标作展示):

29.0 构建你自己的应用

29.1 在开发套件的目录中编译示例程序

当编译示例程序(比如hello_world)时,RTE_SDKRTE_TARGET韩晶变量必须被export。

默认情况下,二进制文件会在build文件夹下生成。

29.2 在开发套件之外构建你自己的应用

示例程序Hello World可以被复制到一个新的文件夹,以作为你开发的起始点:

29.3 自定义Makefile

29.3.1 应用的Makefile

示例程序hello world的默认Makefile是一个不错的起始点,它包括:

用户必须定义一些变量

29.3.2 库的Makefile

用同样的方法也能编译成库文件

和编译应用唯一的不同是,用LIB变量替代APP变量,LIB变量的内容是库的名字,比如,libfoo.a。

29.3.3 自定义Makefile的行为

一些变量可以用来自定义Makefile的行为。下面列出最常用的一些。请参阅构建系统提供的有用的变量 查看相关细节。


30.0 外部应用、外部库Makefile帮助

外部应用或库应该从RTE_SDK导入指定的Makefile,这些文件位于mk文件夹:

30.1 预备知识

下列变量必须定义:

  • ${RTE_SDK}: 指向DPDK的根目录
  • ${RTE_TARGET}: 编译目标的引用(比如,x86_64-default-linuxapp-gcc

30.2 构建目标

构建目标支持通过O=mybuilddir选项指定输出文件夹,这是可选的。默认的输出目录是build。

  • all, “nothing” (meaning just make) 在指定目录创建应用或库。 举例: make O=mybuild
  • clean 清除所有使用make构建的对象 举例: make clean O=mybuild

30.3 帮助目标

  • help 显示帮助。

30.4 其他有用的命令行变量

以下变量可以在命令行中指定:

30.5 从其他文件夹make

从其他文件夹执行Makefile也是可以的。通过指定源文件目录和输出文件目录即可实现:

1
2
3
exportRTE_SDK=/path/to/DPDK
exportRTE_TARGET=x86_64-default-linuxapp-icc
make-f/path/to/my_app/MakefileS=/path/to/my_appO=/path/to/build_dir

0 0
原创粉丝点击