R&D/DPDK

DPDK Programming Guide and Hello World example

sunshout 2014. 3. 28. 14:11



Hello World

#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include <sys/queue.h>
 
#include <rte_memory.h>
#include <rte_memzone.h>
#include <rte_launch.h>
#include <rte_tailq.h>
#include <rte_eal.h>
#include <rte_per_lcore.h>
#include <rte_lcore.h>
#include <rte_debug.h>
 
#include "main.h"
 
static int
lcore_hello(__attribute__((unused)) void *arg)
{
        unsigned lcore_id;
        lcore_id = rte_lcore_id();
        printf("hello from core %u\n", lcore_id);
        return 0;
}
 
int
MAIN(int argc, char **argv)
{
        int ret;
        unsigned lcore_id;
 
        ret = rte_eal_init(argc, argv);
        if (ret < 0)
                rte_panic("Cannot init EAL\n");
 
        /* call lcore_hello() on every slave lcore */
        RTE_LCORE_FOREACH_SLAVE(lcore_id) {
                rte_eal_remote_launch(lcore_hello, NULL, lcore_id);
        }
 
        /* call it on master lcore too */
        lcore_hello(NULL);
 
        rte_eal_mp_wait_lcore();
        return 0;
}


Compile

root@ubuntu:~/dpdk# export RTE_SDK=/root/dpdk

root@ubuntu:~/dpdk# make RTE_TARGET=x86_64-native-linuxapp-gcc

root@ubuntu:~/dpdk# cd examples/helloword

root@ubuntu:~/dpdk# make

root@ubuntu:~/dpdk# ./build/app/helloworld -c 1 -n 1


EAL: Detected lcore 0 as core 0 on socket 0 EAL: Support maximum 64 logical core(s) by configuration. EAL: Detected 1 lcore(s) EAL: Setting up memory... EAL: Ask a virtual area of 0x1000000 bytes EAL: Virtual area found at 0x7f9c59a00000 (size = 0x1000000) EAL: Ask a virtual area of 0xf000000 bytes EAL: Virtual area found at 0x7f9c4a800000 (size = 0xf000000) EAL: Requesting 128 pages of size 2MB from socket 0 EAL: TSC frequency is ~2220257 KHz EAL: WARNING: cpu flags constant_tsc=yes nonstop_tsc=no -> using unreliable clock cycles ! EAL: Master core 0 is ready (tid=5b9a9840) hello from core 0