声明:此文档只做学习交流使用,请勿用作其他商业用途
author:朝阳_tonyLast Change: 2013年7月6日16:41:44 星期六
此文中源码可以去http://dpdk.org/dev 网页中下载;更多官方文档请访问http://dpdk.org
rte_config_init() 是为了初始化struct rte_config rte_config这个结构体,这个结构体是整个dpdk运行程序所包含的配置信息;函数还创建run时共享内存文件 /var/run/.rte_config,方便其他的子程序共享这个结构体中的数据;
函数在下面这个文件中
dpdk/lib/librte_eal/linuxapp/eal/eal.c
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 文件,并设置相应的共享内存;
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 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
};
枚举变量就定义了我上面提到的集中程序运行所属关系;
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;
}
我们在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,希望大家多指正错误,互相交流学习;