intel dpdk rte_config_init() 函数
2013-07-06 17:16
441 查看
声明:此文档只做学习交流使用,请勿用作其他商业用途
author:朝阳_tony
E-mail : linzhaolover@gmail.com
Create Date:2013年7月6日16:20:34 星期六
转载请注明出处:http://blog.csdn.net/linzhaolove
Last Change: 2013年7月6日16:41:44 星期六
此文中源码可以去http://dpdk.org/dev 网页中下载;更多官方文档请访问http://dpdk.org
函数在下面这个文件中
dpdk/lib/librte_eal/linuxapp/eal/eal.c
process_type 这个参数,主要根据你运行程序时传递给 --proc-type参数决定 ;
--proc-type primary|secondary|auto ,分别是 指定为 主程序,次程序,自动裁决;
如果是primary,则调用rte_eal_config_create(); 函数去创建/var/run/.config 文件;并设置共享内存;
如果是secondary,则调用rte_eal_config_attach();去打开/var/run/.config 文件,并设置相应的共享内存;
uint32_t master_lcore;主线程的id;
uint32_t lcore_count ; 目前有效逻辑core的个数;
枚举变量就定义了我上面提到的集中程序运行所属关系;
编译并运行测试;
得到结果
# ./build/app/helloworld -c 1f -n 4 --proc-type=auto
EAL: coremask set to 1f
pathname = /var/run/.rte_config
EAL: Auto-detected process type: PRIMARY
EAL: Using native RDTSC
EAL: Detected lcore 0 on socket 0
EAL: Detected lcore 1 on socket 0
EAL: Detected lcore 2 on socket 0
EAL: Detected lcore 3 on socket 0
EAL: Detected lcore 4 on socket 0
EAL: Detected lcore 5 on socket 0
EAL: Detected lcore 6 on socket 0
EAL: Detected lcore 7 on socket 0
EAL: Detected lcore 8 on socket 0
EAL: Detected lcore 9 on socket 0
EAL: Detected lcore 10 on socket 0
EAL: Detected lcore 11 on socket 0
EAL: Requesting 1024 pages of size 2097152
EAL: Ask a virtual area of 0x80000000 bytes
EAL: Virtual area found at 0x7fbd33000000 (size = 0x80000000)
EAL: Master core 0 is ready (tid=b3f03800)
EAL: Core 4 is ready (tid=307fa700)
EAL: Core 3 is ready (tid=30ffb700)
EAL: Core 1 is ready (tid=31ffd700)
hello from core 1
EAL: Core 2 is ready (tid=317fc700)
hello from core 2
hello from core 3
hello from core 4
hello from core 0
rte_config->lcore_count = 5
1f=(00011111) 8421bcd码后5个bit位;选择5个core,进行运行
继续学习dpdk,希望大家多指正错误,互相交流学习;
author:朝阳_tony
E-mail : linzhaolover@gmail.com
Create Date:2013年7月6日16:20:34 星期六
转载请注明出处:http://blog.csdn.net/linzhaolove
Last Change: 2013年7月6日16:41:44 星期六
此文中源码可以去http://dpdk.org/dev 网页中下载;更多官方文档请访问http://dpdk.org
1、函数作用
rte_config_init() 是为了初始化struct rte_config rte_config这个结构体,这个结构体是整个dpdk运行程序所包含的配置信息;函数还创建run时共享内存文件 /var/run/.rte_config,方便其他的子程序共享这个结构体中的数据;函数在下面这个文件中
dpdk/lib/librte_eal/linuxapp/eal/eal.c
2、函数学习
rte_config_init() 中的部分源码switch (rte_config.process_type){ case RTE_PROC_PRIMARY: rte_eal_config_create(); break; case RTE_PROC_SECONDARY: rte_eal_config_attach(); break; case RTE_PROC_AUTO: case RTE_PROC_INVALID: rte_panic("Invalid process type\n"); }
process_type 这个参数,主要根据你运行程序时传递给 --proc-type参数决定 ;
--proc-type primary|secondary|auto ,分别是 指定为 主程序,次程序,自动裁决;
如果是primary,则调用rte_eal_config_create(); 函数去创建/var/run/.config 文件;并设置共享内存;
如果是secondary,则调用rte_eal_config_attach();去打开/var/run/.config 文件,并设置相应的共享内存;
3、rte_config 结构体介绍
code 在dpdk/lib/librte_eal/common/include/rte_eal.h中/** * The global RTE configuration structure. */ struct rte_config { uint32_t version; /**< Configuration [structure] version. */ uint32_t magic; /**< Magic number - Sanity check. */ uint32_t master_lcore; /**< Id of the master lcore */ uint32_t lcore_count; /**< Number of available logical cores. */ enum rte_lcore_role_t lcore_role[RTE_MAX_LCORE]; /**< State of cores. */ /** Primary or secondary configuration */ enum rte_proc_type_t process_type; /** * Pointer to memory configuration, which may be shared across multiple * Intel DPDK instances */ struct rte_mem_config *mem_config; } __attribute__((__packed__));
uint32_t master_lcore;主线程的id;
uint32_t lcore_count ; 目前有效逻辑core的个数;
enum rte_proc_type_t { RTE_PROC_AUTO = -1, /* allow auto-detection of primary/secondary */ RTE_PROC_PRIMARY = 0, /* set to zero, so primary is the default */ RTE_PROC_SECONDARY, RTE_PROC_INVALID };
枚举变量就定义了我上面提到的集中程序运行所属关系;
4、rte_config 在dpdk库中引用;
dpdk提供了一个rte_eal_get_configuration() 函数,去获取全局的结构体rte_config;/* Return a pointer to the configuration structure */ struct rte_config * rte_eal_get_configuration(void) { return &rte_config; }
5、测试rte_config结构体
我们在dpdk/example/helloworld/main.c的main()函数中添加下面3行代码代码/* call it on master lcore too */ lcore_hello(NULL); struct rte_config *tmp_config; tmp_config=rte_eal_get_configuration(); printf("rte_config->lcore_count = %d \n",tmp_config->lcore_count);
编译并运行测试;
make ./build/app/helloworld -c 1f -n 4 --proc-type=auto
得到结果
# ./build/app/helloworld -c 1f -n 4 --proc-type=auto
EAL: coremask set to 1f
pathname = /var/run/.rte_config
EAL: Auto-detected process type: PRIMARY
EAL: Using native RDTSC
EAL: Detected lcore 0 on socket 0
EAL: Detected lcore 1 on socket 0
EAL: Detected lcore 2 on socket 0
EAL: Detected lcore 3 on socket 0
EAL: Detected lcore 4 on socket 0
EAL: Detected lcore 5 on socket 0
EAL: Detected lcore 6 on socket 0
EAL: Detected lcore 7 on socket 0
EAL: Detected lcore 8 on socket 0
EAL: Detected lcore 9 on socket 0
EAL: Detected lcore 10 on socket 0
EAL: Detected lcore 11 on socket 0
EAL: Requesting 1024 pages of size 2097152
EAL: Ask a virtual area of 0x80000000 bytes
EAL: Virtual area found at 0x7fbd33000000 (size = 0x80000000)
EAL: Master core 0 is ready (tid=b3f03800)
EAL: Core 4 is ready (tid=307fa700)
EAL: Core 3 is ready (tid=30ffb700)
EAL: Core 1 is ready (tid=31ffd700)
hello from core 1
EAL: Core 2 is ready (tid=317fc700)
hello from core 2
hello from core 3
hello from core 4
hello from core 0
rte_config->lcore_count = 5
EAL: Auto-detected process type: PRIMARY这行显示是我传递的--proc-type=auto 自己裁决选择的主程序;
rte_config->lcore_count = 5显示有效的逻辑lcore个数是5,是因为我在运行程序是传递参数 -c 1f
1f=(00011111) 8421bcd码后5个bit位;选择5个core,进行运行
继续学习dpdk,希望大家多指正错误,互相交流学习;
相关文章推荐
- uboot下init_sequence_f函数之setup_dram_config
- VxWorks5.5之usrInit函数分析(usrConfig.c)
- uboot下init_sequence_f函数之show_dram_config
- 9.STM32中对SysTick_Init()函数(sysTick_Config()、TimingDelay_Decrement()自定义)和Delay_us()的理解
- Android读取init.rc配置文件parse_config函数解析
- 关于init_IRQ的函数分析
- mips linux trap_init函数分析(转)
- init.d functions的daemon函数
- Linux下简单Shell实现(二)基本功能---主函数及init()函数
- JDE系统函数详解---JDB_InitBhvr
- Windows下程序入口函数与_security_init_cookie
- 创建一个数组,实现函数init()初始化数组,实现empty()清空数组,reverse()函数完成数组的逆置
- (转载)php curl_init函数用法
- php curl_init函数用法
- php curl_init函数用法(http://blog.sina.com.cn/s/blog_640738130100tsig.html)
- [初始化函数]SystemInit()
- com.alibaba.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:178) com.alibaba.dubbo.config.Re
- PHP - Smarty模板引擎 - Manual手册 - Chapter 7. Built-in Functions第7章 内建函数 - {config_load}用于从一个配置文件加载配置变量到模板中
- 自定义函数名数据类型typedef int (init_fnc_t) (void);
- python中的特殊函数__call__()以及init,setattr,getattr,delattr