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,更新其他存储的值。

相关推荐
chlk12317 小时前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑18 小时前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件18 小时前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
深紫色的三北六号1 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash1 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI2 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行2 天前
Linux和window共享文件夹
linux
木心月转码ing3 天前
WSL+Cpp开发环境配置
linux
崔小汤呀4 天前
最全的docker安装笔记,包含CentOS和Ubuntu
linux·后端
何中应4 天前
vi编辑器使用
linux·后端·操作系统