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

相关推荐
apocelipes1 小时前
Linux c 运行时获取动态库所在路径
linux·c语言·linux编程
努力学习的小廉2 小时前
深入了解linux系统—— 进程池
linux·运维·服务器
秃头菜狗2 小时前
各个主要目录的功能 / Linux 常见指令
linux·运维·服务器
2301_793102492 小时前
Linux——MySql数据库
linux·数据库
jiunian_cn4 小时前
【Linux】centos软件安装
linux·运维·centos
程序员JerrySUN4 小时前
[特殊字符] 深入理解 Linux 内核进程管理:架构、核心函数与调度机制
java·linux·架构
孤寂大仙v4 小时前
【计算机网络】非阻塞IO——select实现多路转接
linux·计算机网络
派阿喵搞电子4 小时前
Ubuntu下有关UDP网络通信的指令
linux·服务器·网络
Evan_ZGYF丶4 小时前
【PCIe总线】 -- PCI、PCIe相关实现
linux·嵌入式·pcie·pci
舰长1154 小时前
Ubuntu挂载本地镜像源(像CentOS 一样挂载本地镜像源)
linux·ubuntu·centos