可能用到的函数:
1.access()函数:
功 能: 确定文件或文件夹的访问权限。即,检查某个文件的存取方式,比如说是只读方式、只写方式等。如果指定的存取方式有效,则函数返回0,否则函数返回-1。
用 法: int access(const char *filenpath, int mode);
mode参数:
R_OK 只判断是否有读权限
W_OK 只判断是否有写权限
X_OK 判断是否有执行权限
F_OK 只判断是否存在
2.strtoul()函数:
strtoul() 函数源自于“string to unsigned long”,用来将字符串转换成无符号长整型数(unsigned long)。
原型为: unsigned long strtoul (const char* str, char** endptr, int base);
参数介绍:
str :要转换的字符串;
endptr:第一个不能转换的字符的指针
base:字符串 str 所采用的进制
函数说明:strtoul() 会将参数 str 字符串根据参数 base 来转换成无符号的长整型数(unsigned long)。参数 base 范围从2 至36,或0。参数 base 代表 str 采用的进制方式,如 base 值为10 则采用10 进制,若 base 值为16 则采用16 进制数等。
函数功能:
/* 主要填充几个数据:cpu_config结构体
* 1.core_index:如果对应的lcore_id可用,该值为0,否则为-1* 2.cpuset:如果对应的lcore_id 可用,将该值填入cpuset中
* 3.detected:1 可用,0 不可用
* 4.core_id:在socket上的序号,默认从0开始。比如每个socket上两个core,该core是第二个,则为1;
* 5.socket_id:该lcore_id属于哪一个socket
*
* rte_config结构体:
* lcore_role:ROLE_OFF:没有使用,ROLE_RTE 可以使用;
* lcore_count:可以使用的core
*/
int rte_eal_cpu_init(void)
{
/* pointer to global configuration */
struct rte_config *config = rte_eal_get_configuration();//获取全局变量rte_config结构体的指针;
unsigned lcore_id;
unsigned count = 0; //用来记录可以使用的lcore的数量
/*
* Parse the maximum set of logical cores, detect the subset of running
* ones and enable them by default.
*
*/
for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
lcore_config[lcore_id].core_index = count; //初始化为0
/* init cpuset for per lcore config */
CPU_ZERO(&lcore_config[lcore_id].cpuset); //初始化
/* in 1:1 mapping, record related cpu detected state */
lcore_config[lcore_id].detected = eal_cpu_detected(lcore_id);
if (lcore_config[lcore_id].detected == 0) {
config->lcore_role[lcore_id] = ROLE_OFF;
lcore_config[lcore_id].core_index = -1;
continue;
}
/* By default, lcore 1:1 map to cpu id */
CPU_SET(lcore_id, &lcore_config[lcore_id].cpuset); //cpuset设置为lcore_id
/* By default, each detected core is enabled */
config->lcore_role[lcore_id] = ROLE_RTE;
lcore_config[lcore_id].core_id = eal_cpu_core_id(lcore_id);//该lcore_id在socket上的序号
lcore_config[lcore_id].socket_id = eal_cpu_socket_id(lcore_id); //socket_id
if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES)
#ifdef RTE_EAL_ALLOW_INV_SOCKET_ID
lcore_config[lcore_id].socket_id = 0;
#else
rte_panic("Socket ID (%u) is greater than "
"RTE_MAX_NUMA_NODES (%d)\n",
lcore_config[lcore_id].socket_id,
RTE_MAX_NUMA_NODES);
#endif
RTE_LOG(DEBUG, EAL, "Detected lcore %u as "
"core %u on socket %u\n",
lcore_id, lcore_config[lcore_id].core_id,
lcore_config[lcore_id].socket_id);
count++;
}
/* Set the count of enabled logical cores of the EAL configuration */
config->lcore_count = count; //有效的lcore数
RTE_LOG(DEBUG, EAL,
"Support maximum %u logical core(s) by configuration.\n",
RTE_MAX_LCORE);
RTE_LOG(DEBUG, EAL, "Detected %u lcore(s)\n", config->lcore_count);
return 0;
}