intel dpdk api pci设备驱动注册和初始化过程

7 篇文章 1 订阅

声明:此文档只做学习交流使用,请勿用作其他商业用途

author:朝阳_tony
E-mail : linzhaolover@gmail.com
Create Date: 2013-8-9 10:29:36 Friday
Last Change: 2013-8-9 13:08:12 Friday

转载请注明出处:http://blog.csdn.net/linzhaolover


此文请结合intel dpdk源码去阅读,源码可以去http://dpdk.org/dev 网页中下载;更多官方文档请访问http://dpdk.org

intel DPDK交流群希望大家加入互相学习,QQ群号: 289784125


本文章基于intel dpdk  的源码1.3.1 版本进行讲解;


摘要

如何向intel dpdk添加自己的源码库,如何添加自己的实例程序,下面做一些简单的讲解;

1、添加创建自己源码库

在dpdk源码目录,以x86_64bit  gcc编译环境为例;
先设置环境变量
[cpp]  view plain  copy
 print ?
  1. export RTE_SDK=`pwd`  
  2. export RTE_TARGET=x86_64-default-linuxapp-gcc  

1)、添加选项到config配置文件;

在defconfig_x86_64-default-linuxapp-gcc配置文件的最后一行,编辑编译选项,这样在后面make时候,就会编译此库;
[cpp]  view plain  copy
 print ?
  1. echo CONFIG_RTE_LIBFOO=y >> config/defconfig_x86_64-default-linuxapp-gcc  

2)、在lib目录下创建一个源码子目录

[cpp]  view plain  copy
 print ?
  1. mkdir ${RTE_SDK}/lib/libfoo  
  2. touch ${RTE_SDK}/lib/libfoo/foo.c  
  3. touch ${RTE_SDK}/lib/libfoo/foo.h  
编辑源码;
foo.c
[cpp]  view plain  copy
 print ?
  1. #include <stdio.h>  
  2. #include <stdlib.h>  
  3. #include <string.h>  
  4. #include "foo.h"  
  5. void foo(void)  
  6. {  
  7.     printf("libfoo test appliation\n");  
  8.     fprintf(stdout,"%s %d\n",__func__,__LINE__);  
  9. }  
foo.h
[cpp]  view plain  copy
 print ?
  1. #ifndef _RTE_FOO_H_  
  2. #define _RTE_FOO_H_  
  3. extern void foo(void);  
  4. #endif  

3)、添加makefile

[cpp]  view plain  copy
 print ?
  1. cp lib/librte_mempool/Makefile  lib/libfoo/Makefile  
修改一下libfoo目录下的Makefile文件,我需要修改几个地方以适应我们自己的源码库;
[cpp]  view plain  copy
 print ?
  1. include $(RTE_SDK)/mk/rte.vars.mk  
  2.   
  3. # library name  
  4. LIB = librte_mempool.a  
  5.   
  6. CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3  
  7.   
  8. # all source are stored in SRCS-y  
  9. SRCS-$(CONFIG_RTE_LIBRTE_MEMPOOL) := rte_mempool.c  
  10.   
  11. # install includes  
  12. SYMLINK-$(CONFIG_RTE_LIBRTE_MEMPOOL)-include := rte_mempool.h  
  13.   
  14. # this lib needs eal  
  15. DEPDIRS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += lib/librte_eal lib/librte_ring  
  16.   
  17. include $(RTE_SDK)/mk/rte.lib.mk  

我们要修改库名字,将librte_mempool.a改为libfoo.a
修改源码位置和名称将所有的CONFIG_RTE_LIBRTE_MEMPOOL 修改为CONFIG_RTE_LIBFOO,将rte_mempool.c改为foo.c 我刚才编辑的那个源码文件;
在安装dpdk时会为这个库创建一个头文件连接,需要将rte_mempool.h改为foo.h
每个库不肯能独立完成所有的任务,所以要依赖其他的库,假设当前依赖 eal 和ring两个库;后期请更加自己的需要添加;
[cpp]  view plain  copy
 print ?
  1. # this lib needs eal  
  2. DEPDIRS-$(CONFIG_RTE_LIBFOO) += lib/librte_eal lib/librte_ring  
最后libfoo/Makefile是下面这样;
[cpp]  view plain  copy
 print ?
  1. include $(RTE_SDK)/mk/rte.vars.mk  
  2.   
  3. # library name  
  4. LIB = libfoo.a  
  5.   
  6. CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3  
  7.   
  8. # all source are stored in SRCS-y  
  9. SRCS-$(CONFIG_RTE_LIBFOO) := foo.c  
  10.   
  11. # install includes  
  12. SYMLINK-$(CONFIG_RTE_LIBFOO)-include := foo.h  
  13.   
  14. # this lib needs eal  
  15. DEPDIRS-$(CONFIG_RTE_LIBFOO) += lib/librte_eal lib/librte_ring  
  16.   
  17. include $(RTE_SDK)/mk/rte.lib.mk  

下面在修改lib/Makefile, 也就是要在总的库中添加编译选项,
[cpp]  view plain  copy
 print ?
  1. DIRS-$(CONFIG_RTE_LIBFOO) += libfoo  

别着急,还没完,还需要修改 mk/rte.app.mk文件,找到mempool选项所在位置添加编译选项,就像下面这样;
[cpp]  view plain  copy
 print ?
  1. ifeq ($(CONFIG_RTE_LIBRTE_MEMPOOL),y)  
  2. LDLIBS += -lrte_mempool  
  3. endif  
  4.   
  5. #add my test foo option  
  6. ifeq ($(CONFIG_RTE_LIBFOO),y)  
  7. LDLIBS += -lfoo  
  8. endif  

4)、编译安装

首先要将之前安装的删除,然后再次安装;
[cpp]  view plain  copy
 print ?
  1. rm -r x86_64-default-linuxapp-gcc/  
  2. make install T=x86_64-default-linuxapp-gcc  
如果成功了,会创建libfoo.a 和一个foo.h文件;
[cpp]  view plain  copy
 print ?
  1. ls x86_64-default-linuxapp-gcc/include/  
会发现多了一个foo.h的文件链接;
[cpp]  view plain  copy
 print ?
  1. ls x86_64-default-linuxapp-gcc/lib/  
多了一个libfoo.a静态库文件;


2、添加自己的实例程序

1、创建自己的程序源码

[cpp]  view plain  copy
 print ?
  1. mkdir mydpdk  
  2. touch mydpdk/main.c  
  3. cp examples/helloworld/Makefile  mydpdk/Makefile  
main.c源码;
[cpp]  view plain  copy
 print ?
  1. #include <stdio.h>  
  2. #include <string.h>  
  3. #include <stdint.h>  
  4. #include <errno.h>  
  5. #include <sys/queue.h>  
  6.   
  7. #include <rte_memory.h>  
  8. #include <rte_memzone.h>  
  9. #include <rte_launch.h>  
  10. #include <rte_tailq.h>  
  11. #include <rte_eal.h>  
  12. #include <rte_per_lcore.h>  
  13. #include <rte_lcore.h>  
  14. #include <rte_debug.h>  
  15.   
  16. #include <foo.h>  
  17.   
  18. int  
  19. main(int argc, char **argv)  
  20. {  
  21.   
  22.     foo();  
  23.   
  24.     return 0;  
  25. }  
foo.h 就是我在第一节创建的foo库的头文件;
编辑Makefile;
[cpp]  view plain  copy
 print ?
  1. ifeq ($(RTE_SDK),)  
  2. $(error "Please define RTE_SDK environment variable")  
  3. endif  
  4.   
  5. # Default target, can be overriden by command line or environment  
  6. RTE_TARGET ?= x86_64-default-linuxapp-gcc  
  7.   
  8. include $(RTE_SDK)/mk/rte.vars.mk  
  9.   
  10. # binary name  
  11. APP = mydpdk  
  12.   
  13. # all source are stored in SRCS-y  
  14. SRCS-y := main.c  
  15.   
  16. #CFLAGS += -O3  
  17. CFLAGS += $(WERROR_FLAGS)  
  18.   
  19. include $(RTE_SDK)/mk/rte.extapp.mk  
这要注意,将APP的输出名写成自己需要的,我这写的谁mydpdk,也就是将来了可执行程序名字;

2)、编译运行

[cpp]  view plain  copy
 print ?
  1. make -C mydpdk/  
[cpp]  view plain  copy
 print ?
  1. # ./mydpdk/build/mydpdk  
  2. libfoo test appliation  
  3. foo 10  
打印了一些信息,就是我在foo库中要输出的信息;

技术水平有待提高,如果文章有错误的地方希望读者指正,相互交流,互相学习;O(∩_∩)O~
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值