DPDK编程开发—lcore

标签:
dpdk编程开发 |
分类: DPDK |
1、知识百科
返回值 |
操作函数 |
函数功能 |
|
RTE_DECLARE_PER_LCORE |
|
|
RTE_DECLARE_PER_LCORE |
|
static unsigned |
rte_lcore_id |
返回当前运行的lcore ID |
static unsigned |
rte_get_master_lcore |
返回管理lcore的ID |
static unsigned |
rte_lcore_count |
返回系统执行lcore的数目 |
static int |
rte_lcore_index |
Return the index of the lcore starting from zero |
unsigned |
rte_socket_id |
返回正在运行的lcore所对应的物理socket |
static unsigned |
rte_lcore_to_socket_id |
获得指定lcore的物理socket ID |
static int |
rte_lcore_is_enabled |
判断lcore是否enabled,如果enable,则返回True |
static unsigned |
rte_get_next_lcore |
获得下一个enable的lcore ID |
int |
rte_thread_set_affinity |
|
void |
rte_thread_get_affinity |
|
2、头文件
#include <</font>rte_per_lcore.h>
#include <</font>rte_eal.h>
#include <</font>rte_launch.h>
struct
struct lcore_config {
};
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
http://img.ph.126.net/THPMcsEG3qFCnsN7ZL5xvA==/6630670842002371011.jpg
#lscpu
#numactl --hardware
http://img0.ph.126.net/yPoUwyb0q8QrwmK4CA5KmQ==/6630610368862842615.jpg
备注:从指令的结果可以看出本机有1个NUMA node。(available: 1 nodes (0))
http://img0.ph.126.net/FH41rNHUrmWlqSesxngO0g==/6630421252862479224.jpg
备注:从指令的结果可以看出本机有2个NUMA node。(available: 2 nodes (0-1))
# ls /sys/devices/system/node/node0
http://img1.ph.126.net/C8cQxIXtA_oMNEbV5bVfcg==/6630439944560151574.jpg
备注:node0包含0~11个processor。
socket(physical id)
http://img0.ph.126.net/ebPhRx_LjdjvvWs4iD4G5w==/6630569686932612045.jpg
一个socket对应主板上的CPU插槽,在/proc/cpuinfo中的physical id就是socket的ID。
# grep 'physical id' /proc/cpuinfo | awk -F: '{print $2 | "sort -un"}'
http://img1.ph.126.net/lGCfE6jwXb2e3FAFkdXL0A==/6630647752258185286.jpg
备注:通过以上信息,可以知道本机有2个socket,编号为0和1。
#grep 'physical id' /proc/cpuinfo | awk -F: '{print $2}' | sort | uniq -c
http://img1.ph.126.net/NjJzj63FnMntMj67_NGCCg==/6630859958002346182.jpg
备注:每个socket对应6个processer。
#cat /proc/cpuinfo |grep core|sort -u
http://img1.ph.126.net/MatqSiDQBfeVsKFg8VHm-g==/6630627961048890076.jpg
备注:一个socket有6个cores,它们的ID分别为0~5。
processer
# grep 'processor' /proc/cpuinfo | wc -l
http://img0.ph.126.net/tunvcHGUDxjJHpCk8P0rfg==/6630815977537238775.jpg
备注:本机共有12个processor。
# grep 'siblings' /proc/cpuinfo | sort -u
http://img0.ph.126.net/DLMsAW9UKvMugjDqp3A_Bg==/6630515810862470517.jpg
备注:每个socket中有几个processor也可以从siblings字段中获取。
cpu.sh
#!/bin/bash
# Simple print cpu topology
# Author: kodango
function get_nr_processor()
{
}
function get_nr_socket()
{
}
function get_nr_siblings()
{
}
function get_nr_cores_of_socket()
{
}
echo '===== CPU Topology Table ====='
echo
echo '+--------------+---------+-----------+'
echo '| Processor ID | Core ID | Socket ID |'
echo '+--------------+---------+-----------+'
while read line; do
done < /proc/cpuinfo
echo
awk -F: '{
}
END{
}' /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
on
nr_cores=`get_nr_cores_of_socket`
echo "Cores in on
let nr_cores*=nr_socket
echo "Cores in total: $nr_cores"
if [ "$nr_cores" = "$nr_processor" ]; then
else
fi
echo
echo '===== END ====='
http://img0.ph.126.net/JhijtFpst5ueM2P86WUXKA==/6630191454932271360.jpg
5、常用指令
lscpu
#lscpu
Architecture:
CPU
op-mode(s):
Byte
Order:
CPU(s):
On-line CPU(s)
list:
Thread(s) per
core:
Core(s) per
socket:
CPU
socket(s):
NUMA
node(s):
Vendor
ID:
CPU
family:
Model:
Stepping:
CPU
MHz:
BogoMIPS:
Virtualization:
L1d
cache:
L1i
cache:
L2
cache:
L3
cache:
NUMA node0
CPU(s):
NUMA node1
CPU(s):
numactl
#numactl --hardware
http://img0.ph.126.net/RtThnk-m3iXauMqEsreR6w==/6630516910374098124.jpg
/proc/cpuinfo
# cat /proc/cpuinfo |grep 'physical id'|awk -F: '{print $2}'|sort|uniq -c
http://img0.ph.126.net/UlYXzmbhUVPKm6rutgY6xA==/6630930326746540503.jpg
备注:可以知道有2个socket,1个socket上有12个processor。
#cat /proc/cpuinfo |grep core|sort -u
http://img2.ph.126.net/zLfVam7sv8A-QyfqzCzeHQ==/6630126583746235613.jpg
备注:可以知道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