centos7 dpdk环境搭建

  • 下载源码
dpdk官网: https://www.dpdk.org/
DPDK Core->Download->选择需要的版本进行源码下载
  • 安装依赖
# yum install make
# yum install gcc
# yum install numactl-devel*x86_64 
# yum install kernel-devel
# modprobe uio
等等。
具体参考DPDK->Documentation->LINUX USER GUIDE->Getting Started Guide for Linux->System Requirements章节
  • 编译
# tar xJf dpdk-.tar.xz
# cd dpdk-
编辑目标平台配置文件,格式为ARCH-MACHINE-EXECENV-TOOLCHAIN
# cp config/defconfig_x86_64-native-linuxapp-gcc  config/defconfig_x86_64-snb-linuxapp-gcc   
# vi config/defconfig_x86_64-snb-linuxapp-gcc  
	修改
	CONFIG_RTE_MACHINE="snb"
# make install T=x86_64-snb-linuxapp-gcc
在源码目录下生成的x86_64-snb-linuxapp-gcc文件夹就是目标平台需要的dpdk环境
  • 库开发

 1. 添加库选项
	 # vi config/defconfig_x86_64-snb-linuxapp-gcc 
	添加
	CONFIG_RTE_LIBRTE_TEST=y
 2. 在lib目录下创建test工程代码以及Makefile
 3. 添加库路径
	# vi lib/Makefile
	添加
	DIRS-$(CONFIG_RTE_LIBRTE_TEST) += librte_test
 4. 添加库链接
	# vi mk/rte.app.mk
	添加
	_LDLIBS-$(CONFIG_RTE_LIBRTE_TEST)  += -lrte_test
 5. 清空旧环境数据
	# rm x86_64-snb-linuxapp-gcc/ -rf	
 6. 编译
	# make install T=x86_64-snb-linuxapp-gcc
 7. 确认
	# ls x86_64-snb-linuxapp-gcc/lib/librte_test.a 

Makefile文件

#   BSD LICENSE
#
#   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
#   All rights reserved.
#
#   Redistribution and use in source and binary forms, with or without
#   modification, are permitted provided that the following conditions
#   are met:
#
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in
#       the documentation and/or other materials provided with the
#       distribution.
#     * Neither the name of Intel Corporation nor the names of its
#       contributors may be used to endorse or promote products derived
#       from this software without specific prior written permission.
#
#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

include $(RTE_SDK)/mk/rte.vars.mk

# library name
LIB = librte_test.a

CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3
LDLIBS += -lrte_eal 

EXPORT_MAP := rte_test_version.map

LIBABIVER := 3

# all source are stored in SRCS-y
SRCS-$(CONFIG_RTE_LIBRTE_TEST) +=  rte_test.c

# install includes
SYMLINK-$(CONFIG_RTE_LIBRTE_TEST)-include := rte_test.h

include $(RTE_SDK)/mk/rte.lib.mk

rte_test.h

#ifndef _RTE_TEST_H_
#define _RTE_TEST_H_

int dpdk_lib_test(void);

#endif /* _RTE_TEST_H_ */

rte_test.c

#include "rte_test.h"

int dpdk_lib_test(void)
{
        printf("this msg is from lib test.\n");
        return 0;
}
  • 库使用

examples/helloworld/main.c

/*-
 *   BSD LICENSE
 *
 *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following conditions
 *   are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in
 *       the documentation and/or other materials provided with the
 *       distribution.
 *     * Neither the name of Intel Corporation nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include 
#include 
#include 
#include 
#include 

#include 
#include 
#include 
#include 
#include 
#include 

#include "rte_test.h"


static int
lcore_hello(__attribute__((unused)) void *arg)
{
        unsigned lcore_id;
        lcore_id = rte_lcore_id();
        printf("hello from core %u\n", lcore_id);
        return 0;
}

int
main(int argc, char **argv)
{
        int ret;
        unsigned lcore_id;

        ret = rte_eal_init(argc, argv);
        if (ret < 0)
                rte_panic("Cannot init EAL\n");

        /* call lcore_hello() on every slave lcore */
        RTE_LCORE_FOREACH_SLAVE(lcore_id) {
                rte_eal_remote_launch(lcore_hello, NULL, lcore_id);
        }

        /* call it on master lcore too */
        lcore_hello(NULL);

        dpdk_lib_test();

        rte_eal_mp_wait_lcore();
        return 0;
}
在示例程序helloworld中对库接口调用后进行编译
# export RTE_SDK=$(pwd)  
# export RTE_TARGET=x86_64-snb-linuxapp-gcc
# make install T=x86_64-snb-linuxapp-gcc
# make -C examples/helloworld/ 
# ls examples/helloworld/build/helloworld

目标平台进行运行
/sdd/xf/test # scp [email protected]:/home/xiaofeng/C/dpdk/dpdk-stable-17.11.4/examples/helloworld/build/helloworld .
[email protected]'s password: 
helloworld                                                                                                                                                                      100% 4711KB   2.3MB/s   00:02    
/sdd/xf/test # ls
helloworld
/sdd/xf/test # ./helloworld 
EAL: Detected 16 lcore(s)
EAL: Probing VFIO support...
EAL: PCI device 0000:02:00.0 on NUMA socket 0
EAL:   probe driver: 8086:10fb net_ixgbe
EAL: PCI device 0000:02:00.1 on NUMA socket 0
EAL:   probe driver: 8086:10fb net_ixgbe
EAL: PCI device 0000:05:00.0 on NUMA socket 0
EAL:   probe driver: 8086:10fb net_ixgbe
EAL: PCI device 0000:05:00.1 on NUMA socket 0
EAL:   probe driver: 8086:10fb net_ixgbe
EAL: PCI device 0000:07:00.0 on NUMA socket 0
EAL:   probe driver: 8086:10e7 net_e1000_igb
EAL: PCI device 0000:07:00.1 on NUMA socket 0
EAL:   probe driver: 8086:10e7 net_e1000_igb
EAL: PCI device 0000:0a:00.0 on NUMA socket 0
EAL:   probe driver: 8086:1521 net_e1000_igb
EAL: PCI device 0000:0a:00.1 on NUMA socket 0
EAL:   probe driver: 8086:1521 net_e1000_igb
hello from core 0
this msg is from lib test.
/sdd/xf/test # 

你可能感兴趣的:(linux应用)