【转载】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)

返回管理lcoreID

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)

获得下一个enablelcore 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)

函数功能:返回管理lcoreID

rte_get_next_lcore(unsigned i, int skip_master, int wrap)

函数功能:获得下一个enablelcore 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

NUMANon-Uniform Memory Access,非一致性内存访问)和SMPSymmetric Multi-Processor,对称多处理器系统)是两种不同的CPU硬件体系架构。

SMP的主要特征是共享,所有的CPU共享使用全部资源,例如内存、总线和I/O,多个CPU对称工作,彼此之间没有主次之分,平等地访问共享的资源,这样势必引入资源的竞争问题,从而导致它的扩展内力非常有限;NUMA架构在中大型系统上一直非常盛行,也是高性能的解决方案,在系统延迟方面表现也都很优秀。

NUMA架构下,CPU的概念从大到小依次是:SocketCoreProcessor。随着多核技术的发展,我们将多个CPU封装在一起,这个封装一般被称为Socket(插槽),而Socket中的每个核心被称为Core,为了进一步提升CPU的处理能力,Intel又引入了HTHyper-Threading,超线程)的技术,一个Core打开HT之后,在OS看来就是两个核,当然这个核是逻辑上的概念,所以也被称为Logical Processor,本文简称为Processor

node

        NUMA体系结构中多了node的概念,主要用于解决core分组问题,在目前常见的分组中,一个socket里有一个node,每个node有自己的内部CPU、总线和内存,同时还可以访问其他node内的内存,NUMA最大的优势是可以方便增加CPU数量。

image

#lscpu

#numactl --hardware

image

备注:从指令的结果可以看出本机有1NUMA node。(available: 1 nodes (0)

 

image

备注:从指令的结果可以看出本机有2NUMA node。(available: 2 nodes (0-1)

 

# ls /sys/devices/system/node/node0

image

备注:node0包含0~11processor

socketphysical id

image

一个socket对应主板上的CPU插槽,在/proc/cpuinfo中的physical id就是socketID

# grep 'physical id' /proc/cpuinfo | awk -F: '{print $2 | "sort -un"}'

image

备注:通过以上信息,可以知道本机有2socket,编号为01

 

#grep 'physical id' /proc/cpuinfo | awk -F: '{print $2}' | sort | uniq -c

image

备注:每个socket对应6processer

 

#cat /proc/cpuinfo |grep core|sort -u

image

备注:一个socket6cores,它们的ID分别为0~5

processer

# grep 'processor' /proc/cpuinfo | wc -l

image

备注:本机共有12processor

 

# grep 'siblings' /proc/cpuinfo | sort -u

image

备注:每个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 ====='

image

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                  //每个core1threads

Core(s) per socket:       6                  //每个socket6cores

CPU socket(s):               2                  //共有2sockets

NUMA node(s):             2                  //共有2NUMA 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

image

/proc/cpuinfo

# cat /proc/cpuinfo |grep 'physical id'|awk -F: '{print $2}'|sort|uniq -c

image

备注:可以知道有2socket1socket上有12processor

 

#cat /proc/cpuinfo |grep core|sort -u

image

备注:可以知道1socket上有6cores,结合上个信息,可以知道开启了超线程。

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

 

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: DPDK(Data Plane Development Kit)是一个开源的软件开发工具集合,用于构建高性能的数据平面应用程序。DPDK提供了一系列的库函数和驱动,帮助开发人员更好地利用硬件资源,并将网络应用程序性能最大化。 DPDK中文开发指南是一本为中国开发人员编写的文档,旨在帮助他们了解和掌握DPDK的使用方法和技巧。 该开发指南内容丰富,包括了对DPDK框架的详细介绍、环境搭建、编译安装等基础知识。同时,还介绍了如何使用DPDK进行包处理、网络流的管理和数据包转发等高级功能。它提供了丰富的示例代码和代码解析,帮助开发人员更好地理解和应用DPDK的各种功能。 在该开发指南中,还介绍了DPDK在不同平台下的使用方法,如在Linux、FreeBSD等操作系统中的配置和使用。并且,该指南还特别关注了在中国特定网络环境下的应用示例和最佳实践,以帮助开发人员更好地应用DPDK进行网络应用程序的开发。 总之,DPDK中文开发指南是一本针对中国开发人员的宝贵资料,通过它,开发人员可以更加深入地了解和使用DPDK开发出高性能、高可扩展性的数据面应用程序。同时,该指南还为中国特定网络环境下的应用提供了示例和最佳实践,帮助开发人员更好地应对挑战,提升网络应用程序的性能和稳定性。 ### 回答2: DPDK全称为Data Plane Development Kit,是一种用于加速数据平面处理的开源软件库。该库提供了一系列高性能的API,供开发者利用其进行高速数据包处理。DPDK能够通过绕过操作系统内核的方式,直接将网络流量发送和接收到用户空间,从而大大提升了网络应用的性能。 DPDK提供了一份中文开发指南,方便中国开发者学习和使用DPDK。这份指南详细介绍了DPDK的概念、原理和架构,以及其在高性能数据包处理方面的优势。指南还提供了一些使用DPDK的实例和案例,方便开发者理解和应用DPDK。 该指南首先介绍了DPDK的基本概念和使用环境,包括CPU的绑定与适配、内存管理和物理设备绑定等。然后,指南介绍了如何使用DPDK的API来实现网络应用,包括创建和管理网络接口、发送和接收数据包等。此外,还介绍了DPDK的报文处理框架、多队列和多核绑定等高级特性。 在指南的后面,还提供了一些常见问题和解决方案,方便开发者在使用DPDK过程中遇到问题时进行参考。此外,指南还提供了一些进阶话题,如数据包包头解析、流量管理和软件交换机等,供开发者在深入理解DPDK后进行进一步探索和应用。 总之,DPDK中文开发指南提供了一个全面而易懂的学习和使用DPDK的参考文档,对于想要利用DPDK开发高性能数据平面应用的中国开发者来说,非常有帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值