[DPDK][转]DPDK编程开发(4)—lcore
1、知识百科
|
返回值 |
操作函数 |
函数功能 |
|
RTE_DECLARE_PER_LCORE (unsigned, _lcore_id) |
||
|
RTE_DECLARE_PER_LCORE (rte_cpuset_t, _cpuset) |
||
|
static unsigned |
rte_lcore_id (void) |
返回当前运行的lcore ID |
|
static unsigned |
rte_get_master_lcore (void) |
返回管理lcore的ID |
|
static unsigned |
rte_lcore_count (void) |
返回系统执行lcore的数目 |
|
static int |
rte_lcore_index (int lcore_id) |
Return the index of the lcore starting from zero |
|
unsigned |
rte_socket_id (void) |
返回正在运行的lcore所对应的物理socket |
|
static unsigned |
rte_lcore_to_socket_id (unsigned lcore_id) |
获得指定lcore的物理socket ID |
|
static int |
rte_lcore_is_enabled (unsigned lcore_id) |
判断lcore是否enabled,如果enable,则返回True |
|
static unsigned |
rte_get_next_lcore (unsigned i, int skip_master, int wrap) |
获得下一个enable的lcore ID |
|
int |
rte_thread_set_affinity (rte_cpuset_t *cpusetp) |
|
|
void |
rte_thread_get_affinity (rte_cpuset_t *cpusetp) |
2、头文件
#include <rte_per_lcore.h>
#include <rte_eal.h>
#include <rte_launch.h>
struct lcore_config lcore_config[RTE_MAX_LCORE]
struct lcore_config {
unsigned detected; /**< true if lcore was detected */
pthread_t thread_id; /**< pthread identifier */
int pipe_master2slave[2]; /**< communication pipe with master */
int pipe_slave2master[2]; /**< communication pipe with master */
lcore_function_t * volatile f; /**< function to call */
void * volatile arg; /**< argument of function */
volatile int ret; /**< return value of function */
volatile enum rte_lcore_state_t state; /**< lcore state */
unsigned socket_id; /**< physical socket id for this lcore */
unsigned core_id; /**< core number on socket for this lcore */
};
3、操作函数
rte_lcore_count(void)
函数功能:返回系统执行lcore的数目(和RTE_MAX_LCORE(宏64)不是一样的概念)。
rte_lcore_id(void)
函数功能:返回当前运行的lcore ID。
rte_get_master_lcore(void)
函数功能:返回管理lcore的ID。
rte_get_next_lcore(unsigned i, int skip_master, int wrap)
函数功能:获得下一个enable的lcore ID。
rte_lcore_index(int lcore_id)
函数功能:Return the index of the lcore starting from zero。
rte_lcore_is_enabled(unsigned lcore_id)
函数功能:判断lcore是否enabled,如果enable,则返回True。
rte_lcore_to_socket_id(unsigned lcore_id)
函数功能:获得指定lcore的物理socket ID。
rte_socket_id(void)
函数功能:返回正在运行的lcore所对应的物理socket。
rte_thread_get_affinity(rte_cpuset_t * cpusetp)
函数功能:获得当前线程的core affinity。
rte_thread_set_affinity(rte_cpuset_t * cpusetp)
函数功能:对当前线程设置core affinity,成功返回0,失败返回-1。
4、知识扩展
NUMA
NUMA(Non-Uniform Memory Access,非一致性内存访问)和SMP(Symmetric Multi-Processor,对称多处理器系统)是两种不同的CPU硬件体系架构。
SMP的主要特征是共享,所有的CPU共享使用全部资源,例如内存、总线和I/O,多个CPU对称工作,彼此之间没有主次之分,平等地访问共享的资源,这样势必引入资源的竞争问题,从而导致它的扩展内力非常有限;NUMA架构在中大型系统上一直非常盛行,也是高性能的解决方案,在系统延迟方面表现也都很优秀。
在NUMA架构下,CPU的概念从大到小依次是:Socket、Core、Processor。随着多核技术的发展,我们将多个CPU封装在一起,这个封装一般被称为Socket(插槽),而Socket中的每个核心被称为Core,为了进一步提升CPU的处理能力,Intel又引入了HT(Hyper-Threading,超线程)的技术,一个Core打开HT之后,在OS看来就是两个核,当然这个核是逻辑上的概念,所以也被称为Logical Processor,本文简称为Processor。
node
NUMA体系结构中多了node的概念,主要用于解决core分组问题,在目前常见的分组中,一个socket里有一个node,每个node有自己的内部CPU、总线和内存,同时还可以访问其他node内的内存,NUMA最大的优势是可以方便增加CPU数量。
#lscpu
#numactl --hardware
备注:从指令的结果可以看出本机有1个NUMA node。(available: 1 nodes (0))
备注:从指令的结果可以看出本机有2个NUMA node。(available: 2 nodes (0-1))
# ls /sys/devices/system/node/node0
备注:node0包含0~11个processor。
socket(physical id)
一个socket对应主板上的CPU插槽,在/proc/cpuinfo中的physical id就是socket的ID。
# grep 'physical id' /proc/cpuinfo | awk -F: '{print $2 | "sort -un"}'
备注:通过以上信息,可以知道本机有2个socket,编号为0和1。
#grep 'physical id' /proc/cpuinfo | awk -F: '{print $2}' | sort | uniq -c
备注:每个socket对应6个processer。
#cat /proc/cpuinfo |grep core|sort -u
备注:一个socket有6个cores,它们的ID分别为0~5。
processer
# grep 'processor' /proc/cpuinfo | wc -l
备注:本机共有12个processor。
# grep 'siblings' /proc/cpuinfo | sort -u
备注:每个socket中有几个processor也可以从siblings字段中获取。
cpu.sh
#!/bin/bash
# Simple print cpu topology
# Author: kodango
function get_nr_processor()
{
grep '^processor' /proc/cpuinfo | wc -l
}
function get_nr_socket()
{
grep 'physical id' /proc/cpuinfo | awk -F: '{
print $2 | "sort -un"}' | wc -l
}
function get_nr_siblings()
{
grep 'siblings' /proc/cpuinfo | awk -F: '{
print $2 | "sort -un"}'
}
function get_nr_cores_of_socket()
{
grep 'cpu cores' /proc/cpuinfo | awk -F: '{
print $2 | "sort -un"}'
}
echo '===== CPU Topology Table ====='
echo
echo '+--------------+---------+-----------+'
echo '| Processor ID | Core ID | Socket ID |'
echo '+--------------+---------+-----------+'
while read line; do
if [ -z "$line" ]; then
printf '| %-12s | %-7s | %-9s |\n' $p_id $c_id $s_id
echo '+--------------+---------+-----------+'
continue
fi
if echo "$line" | grep -q "^processor"; then
p_id=`echo "$line" | awk -F: '{print $2}' | tr -d ' '`
fi
if echo "$line" | grep -q "^core id"; then
c_id=`echo "$line" | awk -F: '{print $2}' | tr -d ' '`
fi
if echo "$line" | grep -q "^physical id"; then
s_id=`echo "$line" | awk -F: '{print $2}' | tr -d ' '`
fi
done < /proc/cpuinfo
echo
awk -F: '{
if ($1 ~ /processor/) {
gsub(/ /,"",$2);
p_id=$2;
} else if ($1 ~ /physical id/){
gsub(/ /,"",$2);
s_id=$2;
arr[s_id]=arr[s_id] " " p_id
}
}
END{
for (i in arr)
printf "Socket %s:%s\n", i, arr[i];
}' /proc/cpuinfo
echo
echo '===== CPU Info Summary ====='
echo
nr_processor=`get_nr_processor`
echo "Logical processors: $nr_processor"
nr_socket=`get_nr_socket`
echo "Physical socket: $nr_socket"
nr_siblings=`get_nr_siblings`
echo "Siblings in one socket: $nr_siblings"
nr_cores=`get_nr_cores_of_socket`
echo "Cores in one socket: $nr_cores"
let nr_cores*=nr_socket
echo "Cores in total: $nr_cores"
if [ "$nr_cores" = "$nr_processor" ]; then
echo "Hyper-Threading: off"
else
echo "Hyper-Threading: on"
fi
echo
echo '===== END ====='
5、常用指令
lscpu
#lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 12 //共有12个逻辑CPU
On-line CPU(s) list: 0-11
Thread(s) per core: 1 //每个core有1个threads
Core(s) per socket: 6 //每个socket有6个cores
CPU socket(s): 2 //共有2个sockets
NUMA node(s): 2 //共有2个NUMA nodes
Vendor ID: GenuineIntel
CPU family: 6
Model: 45
Stepping: 7
CPU MHz: 2294.387 //主频
BogoMIPS: 4588.30
Virtualization: VT-x
L1d cache: 32K //L1 data cache
L1i cache: 32K //L1 instruction cache
L2 cache: 256K
L3 cache: 15360K
NUMA node0 CPU(s): 0-5
NUMA node1 CPU(s): 6-11
numactl
#numactl --hardware
/proc/cpuinfo
# cat /proc/cpuinfo |grep 'physical id'|awk -F: '{print $2}'|sort|uniq -c
备注:可以知道有2个socket,1个socket上有12个processor。
#cat /proc/cpuinfo |grep core|sort -u
备注:可以知道1个socket上有6个cores,结合上个信息,可以知道开启了超线程。
6、参考资料
lcore:
http://www.dpdk.org/doc/api/rte__lcore_8h.html
CPU Topology:
http://kodango.com/cpu-topology
SMP VS NUMA VS MPP:
http://xasun.com/article/4d/2076.html
http://www.ibm.com/developerworks/cn/linux/l-numa/index.html
http://blog.csdn.net/ustc_dylan/article/details/45667227
[DPDK][转]DPDK编程开发(4)—lcore的更多相关文章
- [dev][dpdk][crypto] dpdk加解密设备与IPSEC
概述 分三部分,加解密框架(crypto framework),加解密设备(crypto dev),安全协议(Security Framework) × API,设计思路等,都在加解密框架里:见文档 ...
- C++编程开发学习的50条建议(转)
每个从事C++开发的朋友相信都能给后来者一些建议,但是真正为此进行大致总结的很少.本文就给出了网上流传的对C++编程开发学习的50条建议,总结的还是相当不错的,编程学习者(不仅限于C++学习者)如果真 ...
- C#脱离Halcon编程开发环境使用方法
在没有安装Halcon开发程序(HDevelop (SSE2))的电脑上面编程,使C#脱离Halcon编程开发环境使用方法,除了按照Halcon与编程环境必须要做的设置步骤外,还需要做如下两个工作: ...
- WCF分布式开发步步为赢(4):WCF服务可靠性传输配置与编程开发
今天继续WCF分布式开发步步为赢系列的第4节:WCF服务可靠性传输配置与编程开发.这个章节,我们要介绍什么是WCF服务的可靠性传输,随便介绍网络协议的概念,Web Service为什么不支持可靠性传出 ...
- WCF分布式开发步步为赢(3)WCF服务元数据交换、配置及编程开发
今天我们继续WCF分布式开发步步为赢(3)WCF服务元数据交换.配置及编程开发的学习.经过前面两节的学习,我们了解WCF分布式开发的相关的基本的概念和自定义宿主托管服务的完整的开发和配置过程.今天我们 ...
- 如何搭建Visual Studio的内核编程开发环境
最近正在看<寒江独钓——Windows内核安全编程>这本书,感觉这本书非常好,有兴趣的朋友可以买来看看,有关这本书的信息请参考:http://www.china-pub.com/19559 ...
- 【转】50条大牛C++编程开发学习建议
每个从事C++开发的朋友相信都能给后来者一些建议,但是真正为此进行大致总结的很少.本文就给出了网上流传的对C++编程开发学习的50条建议,总结的还是相当不错的,编程学习者(不仅限于C++学习者)如果真 ...
- Manual | BSD手册| Linux手册 | 数据库手册 | 编程开发手册 | WEB开发手册 | 软件应用手册 | 网络技术手册 | GNU手册
豆豆手册 □ BSD手册 □ Linux手册 □ 数据库手册 □ 编程开发手册 □ WEB开发手册 □ 软件应用手册 □ 网络技术手册 □ GNU手册 在线手册 首 页 BSD手册 ·FreeBS ...
- [dev][ipsec][dpdk] strongswan/dpdk源码分析之ipsec算法配置过程
1 简述 storngswan的配置里用一种固定格式的字符串设置了用于协商的预定义算法.在包协商过程中strongswan将字符串转换为固定的枚举值封在数据包里用于传输. 协商成功之后,这组被协商选中 ...
- Mac iOS Mac Watch 应用和游戏编程开发工具推荐
今日分享「iOS / Mac / Watch 应用和游戏开发工具」推荐,这期专题主要为iOS开发者推荐一些优秀的设计和开发工具,这些工具包含移动原型的设计.程序的开发等,可以大大提高开发的效率!专题会 ...
随机推荐
- volatile关键字并不能作为线程计数器
在java线程并发处理中,有一个关键字volatile的使用目前存在很大的混淆,以为使用这个关键字,在进行多线程并发处理的时候就可以万事大吉. Java语言是支持多线程的,为了解决线程并发的问题,在语 ...
- MAC usb启动盘制作
1.从App Store 下载OS 2.磁盘工具格式化磁盘默认即可 3. 为啥截图,因为有些是不一样的,建议使用 Tab建, 未命名则是你移动U盘命名的名称. 4.完成:所有的命令完成的话, 终 ...
- secureCRT远程登录工具的颜色配置(转载)
另外,字体和编码设置(如果需要显示中文):Options->Session Options->Appearance->font(字体:幼圆,字形:常规,大小:小三号,字符集:中文GB ...
- Java开发常用的在线工具
原文出处: hollischuang(@Hollis_Chuang) 作为一个Java开发人员,经常要和各种各样的工具打交道,除了我们常用的IDE工具以外,其实还有很多工具是我们在日常开发及学习过程中 ...
- dos命名重启或关闭远程服务器
1.建议远程连接.(把远程机器IP换成实际IP地址,把密码改为administrator的真实密码) net use \\远程机器IP\ipc$ "密码"/user:adminis ...
- Java中sql语句的引号问题
1..sql语句 在数据库中,当我们查询语句时,会使用类似的语句: Select * from userinfo where userid='1' or 1; Select * from userin ...
- UI UIBUTTON
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- 数据类型和Json格式(转载)
作者: 阮一峰 日期: 2009年5月30日 1. 前几天,我才知道有一种简化的数据交换格式,叫做yaml. 我翻了一遍它的文档,看懂的地方不多,但是有一句话令我茅塞顿开. 它说,从结构上看,所有的数 ...
- 2014 年最热门的国人开发开源软件TOP 100
不知道从什么时候开始,很多一说起国产好像就非常愤慨,其实大可不必.做开源中国六年有余,这六年时间国内的开源蓬勃发展,从一开始的使用到贡献,到推出自己很多的开源软件,而且还有很多软件被国外认可.中国是开 ...
- using border-radius to make a worker
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="U ...