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 小时前
Linux服务器磁盘应该如何合理分区?
linux·运维·服务器
贵沫末6 小时前
Ubuntu——常用软件安装
linux·运维·ubuntu
Doraemomo7 小时前
Linux内核驱动开发——中断与定时器
linux·运维·驱动开发
2301_808414387 小时前
Linux中动静态库的理解
linux·运维·服务器
M78佐菲8 小时前
ARM学习笔记(11)
linux·arm开发·笔记·嵌入式硬件·学习
M78佐菲8 小时前
ARM学习笔记(10)
linux·arm开发·笔记·嵌入式硬件·学习
半仙白桑8 小时前
内核篇第十五讲:system-V共享内存
linux·共享内存·shmget·shmat·shmdt·shmctl
一条破秋裤9 小时前
Linux 线程创建:pthread_create 与基本回收
java·linux·运维
s65166549610 小时前
IDT和GDT是什么
linux
Android系统攻城狮10 小时前
Linux Gstreamer深度解析之gst_audio_decoder_set_estimate_rate调用流程与实战(四十五)
linux·gstreamer音视频·音视频进阶