DPDK程序编译

dpdk安装、编译

1.安装编译依赖

pip3 install meson

pip3 install ninja

2.下载dpdk-22.03.tar.xz

xz -dk dpdk-22.03.tar.xz 将.xz解压为.tar

tar -xvf dpdk-22.03.tar 将.tar解压为普通文件

3.编译、安装dpdk

meson -Dbuildtype=debug build 编译debug版本

报错,需要安装更新pyelftools

pip3 install pyelftools --upgrade

cd build

ninja

虚拟机内存不足,导致编译过程中被kill掉,将虚拟机内存增加到8G

ninja install //安装

4.测试程序链接dpdk库

在/etc/ld.so.conf.d/下创建文件dpdk-ling.conf文件,内容是

/usr/local/lib64/ dpdk动态库so的位置

ldconfig 加载

用ldconfig -p |grep librte|wc -l 命令确认dpdk库是否有加载

/etc/profile中加上export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig/

dpdk编译的makefile中,会根据PKG_CONFIG_PATH查找libdpdk.pc(该文件保存了编译的类库信息)。

测试程序使用dpdk库

测试程序的编译编译命令:gcc -o test test.c -I/usr/local/include/ -lrte_node -lrte_hash -lrte_eal

cpp 复制代码
#include<rte_hash.h>
#include<rte_lcore.h>
#include <rte_eal.h>

struct rte_hash *g_hash_table;
int hash_table_init()
{
    struct rte_hash_parameters params = {0};
    char name[32];
    sprintf(name, "table_1");
    params.name = name;   //hash表的名称
    params.entries = 1000;   //hash表里元素的个数
    params.socket_id = rte_socket_id();   //在哪个numa上分大页内存
    params.key_len = 4;  //hash key的长度
    params.hash_func = NULL;   //使用什么hash算法
    g_hash_table = rte_hash_create(&params);   //创建一个hash表
    if(g_hash_table == NULL)
    {
        printf("create ipv4 hash table failed.\n");
        return 0;
    }
    uint32_t ipv4 = 16843009;
    uint32_t del_val = 33686018;
    int ret;
    ret = rte_hash_add_key_with_hash(g_hash_table, (void*)&ipv4, ipv4);
    printf("add one:%d\n",ret);
    ipv4 = 33686018;
    ret = rte_hash_add_key_with_hash(g_hash_table, (void*)&ipv4, ipv4);
    printf("add two:%d\n",ret);
    ipv4 = 50529027;
    ret = rte_hash_add_key_with_hash(g_hash_table, (void*)&ipv4, ipv4);
    printf("add three:%d\n",ret);
    rte_hash_del_key_with_hash(g_hash_table, (void*)&del_val,del_val);
    ret = rte_hash_lookup_with_hash(g_hash_table, &ipv4, ipv4);
    printf("find return value:%d\n",ret);
    return 1;
}

int main(int argc, char **argv)
{
    unsigned int lcore_id;
    int ret;
    ret = rte_eal_init(argc, argv);
    if(ret < 0)
    {
        printf("Cannot init EAL\n");
    }
    hash_table_init();
    return 0;
}

一个非常简单的dpdk hash库的创建和使用。rte_hash_add_key_with_hash的返回值可作为用户数据数组的偏移量,这个返回值相对于key来说是唯一的。也就是说这个key id可以作为另一个数组的下标。例如:通过插入key,获取id,然后在另一个数组中,通过id,更新其他存储的值。

相关推荐
阿巴~阿巴~5 小时前
JsonCpp:C++ JSON处理利器
linux·网络·c++·json·tcp·序列化和反序列化
ao_lang5 小时前
数据链路层
linux·服务器·网络
z***3355 小时前
【MySQL系列文章】Linux环境下安装部署MySQL
linux·mysql·adb
偶像你挑的噻6 小时前
13-Linux驱动开发-中断子系统
linux·驱动开发·stm32·嵌入式硬件
福尔摩斯张6 小时前
Linux进程间通信(IPC)机制深度解析与实践指南
linux·运维·服务器·数据结构·c++·算法
cookies_s_s6 小时前
项目--协程库(C++)前置知识篇
linux·服务器·c++
不过普通话一乙不改名6 小时前
Linux 网络发包的极致之路:从普通模式到 AF_XDP ZeroCopy
linux·运维·网络
jquerybootstrap7 小时前
大地2000转经纬度坐标
linux·开发语言·python
x***13397 小时前
如何在Linux中找到MySQL的安装目录
linux·运维·mysql
4***17547 小时前
linux 网卡配置
linux·网络·php