iokernel: Add a basic DPDK echo server and DPDK 17.08.0 as a git submodule.
To build DPDK, in dpdk dir: make config T=x86_64-native-linuxapp-gcc make
This commit is contained in:
parent
edb5fdbe4c
commit
a1a7e66119
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "dpdk"]
|
||||
path = dpdk
|
||||
url = http://dpdk.org/git/dpdk
|
23
Makefile
23
Makefile
@ -1,6 +1,8 @@
|
||||
INC = -I./inc
|
||||
CFLAGS = -g -Wall -std=gnu11 -D_GNU_SOURCE $(INC)
|
||||
DPDK = dpdk
|
||||
INC = -I./inc -I$(DPDK)/build/include
|
||||
CFLAGS = -g -Wall -std=gnu11 -D_GNU_SOURCE $(INC) -mssse3
|
||||
LDFLAGS = -T base/base.ld
|
||||
LDLIBS = -L$(DPDK)/build/lib -lnuma -ldl
|
||||
LD = gcc
|
||||
CC = gcc
|
||||
AR = ar
|
||||
@ -45,6 +47,21 @@ test_src = $(wildcard tests/*.c)
|
||||
test_obj = $(test_src:.c=.o)
|
||||
test_targets = $(basename $(test_src))
|
||||
|
||||
# dpdk libs
|
||||
DPDK_LIBS=
|
||||
DPDK_LIBS+=-Wl,-whole-archive -lrte_pmd_e1000 -Wl,-no-whole-archive
|
||||
DPDK_LIBS+=-Wl,-whole-archive -lrte_pmd_ixgbe -Wl,-no-whole-archive
|
||||
DPDK_LIBS+=-Wl,-whole-archive -lrte_mempool_ring -Wl,-no-whole-archive
|
||||
DPDK_LIBS+=-ldpdk
|
||||
DPDK_LIBS+=-lrte_eal
|
||||
DPDK_LIBS+=-lrte_ethdev
|
||||
DPDK_LIBS+=-lrte_hash
|
||||
DPDK_LIBS+=-lrte_mbuf
|
||||
DPDK_LIBS+=-lrte_mempool
|
||||
DPDK_LIBS+=-lrte_mempool
|
||||
DPDK_LIBS+=-lrte_mempool_stack
|
||||
DPDK_LIBS+=-lrte_ring
|
||||
|
||||
# must be first
|
||||
all: libbase.a libdune.a libnet.a libruntime.a iokerneld $(test_targets)
|
||||
|
||||
@ -61,7 +78,7 @@ libruntime.a: $(runtime_obj)
|
||||
$(AR) rcs $@ $^
|
||||
|
||||
iokerneld: $(iokernel_obj) libbase.a libnet.a base/base.ld
|
||||
$(LD) $(LDFLAGS) -o $@ $(iokernel_obj) libbase.a libnet.a -lpthread
|
||||
$(LD) $(LDFLAGS) -o $@ $(iokernel_obj) libbase.a libnet.a $(DPDK_LIBS) $(LDLIBS) -lpthread
|
||||
|
||||
$(test_targets): $(test_obj) libbase.a libruntime.a base/base.ld
|
||||
$(LD) $(LDFLAGS) -o $@ $@.o libbase.a libruntime.a -lpthread
|
||||
|
1
dpdk
Submodule
1
dpdk
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 02657b4adcb8af773e26ec061b01cd7abdd3f0b6
|
@ -42,3 +42,10 @@ struct proc {
|
||||
*/
|
||||
|
||||
extern int control_init(void);
|
||||
extern int dpdk_init(uint8_t port);
|
||||
|
||||
/*
|
||||
* DPDK main loop
|
||||
*/
|
||||
|
||||
extern void dpdk_run(uint8_t port) __noreturn;
|
||||
|
201
iokernel/dpdk.c
Normal file
201
iokernel/dpdk.c
Normal file
@ -0,0 +1,201 @@
|
||||
/*-
|
||||
* BSD LICENSE
|
||||
*
|
||||
* Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
#include <rte_eal.h>
|
||||
#include <rte_ethdev.h>
|
||||
#include <rte_cycles.h>
|
||||
#include <rte_lcore.h>
|
||||
#include <rte_mbuf.h>
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
#define RX_RING_SIZE 128
|
||||
#define TX_RING_SIZE 512
|
||||
|
||||
#define NUM_MBUFS 8191
|
||||
#define MBUF_CACHE_SIZE 250
|
||||
#define BURST_SIZE 32
|
||||
|
||||
static const struct rte_eth_conf port_conf_default = {
|
||||
.rxmode = { .max_rx_pkt_len = ETHER_MAX_LEN }
|
||||
};
|
||||
|
||||
/* dpdk.c: Basic DPDK echo server. */
|
||||
|
||||
/*
|
||||
* Initializes a given port using global settings and with the RX buffers
|
||||
* coming from the mbuf_pool passed as a parameter.
|
||||
*/
|
||||
static inline int
|
||||
port_init(uint8_t port, struct rte_mempool *mbuf_pool)
|
||||
{
|
||||
struct rte_eth_conf port_conf = port_conf_default;
|
||||
const uint16_t rx_rings = 1, tx_rings = 1;
|
||||
uint16_t nb_rxd = RX_RING_SIZE;
|
||||
uint16_t nb_txd = TX_RING_SIZE;
|
||||
int retval;
|
||||
uint16_t q;
|
||||
|
||||
if (port >= rte_eth_dev_count())
|
||||
return -1;
|
||||
|
||||
/* Configure the Ethernet device. */
|
||||
retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);
|
||||
if (retval != 0)
|
||||
return retval;
|
||||
|
||||
retval = rte_eth_dev_adjust_nb_rx_tx_desc(port, &nb_rxd, &nb_txd);
|
||||
if (retval != 0)
|
||||
return retval;
|
||||
|
||||
/* Allocate and set up 1 RX queue per Ethernet port. */
|
||||
for (q = 0; q < rx_rings; q++) {
|
||||
retval = rte_eth_rx_queue_setup(port, q, nb_rxd,
|
||||
rte_eth_dev_socket_id(port), NULL,
|
||||
mbuf_pool);
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Allocate and set up 1 TX queue per Ethernet port. */
|
||||
for (q = 0; q < tx_rings; q++) {
|
||||
retval = rte_eth_tx_queue_setup(port, q, nb_txd,
|
||||
rte_eth_dev_socket_id(port), NULL);
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Start the Ethernet port. */
|
||||
retval = rte_eth_dev_start(port);
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
|
||||
/* Display the port MAC address. */
|
||||
struct ether_addr addr;
|
||||
rte_eth_macaddr_get(port, &addr);
|
||||
printf("Port %u MAC: %02" PRIx8 " %02" PRIx8 " %02" PRIx8
|
||||
" %02" PRIx8 " %02" PRIx8 " %02" PRIx8 "\n",
|
||||
(unsigned)port,
|
||||
addr.addr_bytes[0], addr.addr_bytes[1],
|
||||
addr.addr_bytes[2], addr.addr_bytes[3],
|
||||
addr.addr_bytes[4], addr.addr_bytes[5]);
|
||||
|
||||
/* Enable RX in promiscuous mode for the Ethernet device. */
|
||||
rte_eth_promiscuous_enable(port);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* The main thread that does the work, reading from the port and echoing out
|
||||
* the same port.
|
||||
*/
|
||||
void dpdk_run(uint8_t port)
|
||||
{
|
||||
/*
|
||||
* Check that the port is on the same NUMA node as the polling thread
|
||||
* for best performance.
|
||||
*/
|
||||
if (rte_eth_dev_socket_id(port) > 0 &&
|
||||
rte_eth_dev_socket_id(port) != (int)rte_socket_id())
|
||||
printf("WARNING, port %u is on remote NUMA node to polling thread.\n\t"
|
||||
"Performance will not be optimal.\n", port);
|
||||
|
||||
printf("\nCore %u echoing packets. [Ctrl+C to quit]\n", rte_lcore_id());
|
||||
|
||||
/* Run until the application is quit or killed. */
|
||||
for (;;) {
|
||||
/*
|
||||
* Receive packets on the port and echo them out the same port.
|
||||
*/
|
||||
|
||||
/* Get burst of RX packets. */
|
||||
struct rte_mbuf *bufs[BURST_SIZE];
|
||||
const uint16_t nb_rx = rte_eth_rx_burst(port, 0, bufs, BURST_SIZE);
|
||||
|
||||
if (nb_rx == 0)
|
||||
continue;
|
||||
|
||||
printf("received %d packets on port %d\n", nb_rx, port);
|
||||
|
||||
/* Send burst of TX packets. */
|
||||
const uint16_t nb_tx = rte_eth_tx_burst(port, 0, bufs, nb_rx);
|
||||
|
||||
printf("sent %d packets on port %d\n", nb_tx, port);
|
||||
|
||||
/* Free any unsent packets. */
|
||||
if (unlikely(nb_tx < nb_rx)) {
|
||||
uint16_t buf;
|
||||
for (buf = nb_tx; buf < nb_rx; buf++)
|
||||
rte_pktmbuf_free(bufs[buf]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize dpdk.
|
||||
*/
|
||||
int dpdk_init(uint8_t port)
|
||||
{
|
||||
struct rte_mempool *mbuf_pool;
|
||||
unsigned nb_ports;
|
||||
char *argv[] = {"./iokerneld", "-l", "1"};
|
||||
|
||||
/* Initialize the Environment Abstraction Layer (EAL). */
|
||||
int ret = rte_eal_init(sizeof(argv) / sizeof(argv[0]), argv);
|
||||
if (ret < 0)
|
||||
rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");
|
||||
|
||||
/* Check that there is a port to send/receive on. */
|
||||
nb_ports = rte_eth_dev_count();
|
||||
if (nb_ports < 1)
|
||||
rte_exit(EXIT_FAILURE, "Error: no available ports\n");
|
||||
|
||||
/* Creates a new mempool in memory to hold the mbufs. */
|
||||
mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUFS * nb_ports,
|
||||
MBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
|
||||
|
||||
if (mbuf_pool == NULL)
|
||||
rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
|
||||
|
||||
/* Initialize port. */
|
||||
if (port_init(port, mbuf_pool) != 0)
|
||||
rte_exit(EXIT_FAILURE, "Cannot init port %"PRIu8 "\n", port);
|
||||
|
||||
if (rte_lcore_count() > 1)
|
||||
printf("\nWARNING: Too many lcores enabled. Only 1 used.\n");
|
||||
|
||||
return 0;
|
||||
}
|
@ -10,6 +10,7 @@
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int ret;
|
||||
int port = 0;
|
||||
|
||||
ret = base_init();
|
||||
if (ret) {
|
||||
@ -23,6 +24,12 @@ int main(int argc, char *argv[])
|
||||
return ret;
|
||||
}
|
||||
|
||||
while (1) {}
|
||||
ret = dpdk_init(port);
|
||||
if (ret) {
|
||||
log_err("dpdk_init() failed, ret = %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
dpdk_run(port);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user