Commit 06e178f4 authored by Leonardo Lai's avatar Leonardo Lai

added poller skeleton

parent 87269a1e
...@@ -37,7 +37,8 @@ UDPDK_C= ${CC} -c $(DPDK_CFLAGS) ${CFLAGS} ${WERROR} $< ...@@ -37,7 +37,8 @@ UDPDK_C= ${CC} -c $(DPDK_CFLAGS) ${CFLAGS} ${WERROR} $<
UDPDK_SRCS+= \ UDPDK_SRCS+= \
udpdk_syscall.c \ udpdk_syscall.c \
udpdk_init.c udpdk_init.c \
udpdk_poller.c
SRCS= ${UDPDK_SRCS} SRCS= ${UDPDK_SRCS}
......
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
// Created by leoll2 on 9/25/20. // Created by leoll2 on 9/25/20.
// Copyright (c) 2020 Leonardo Lai. All rights reserved. // Copyright (c) 2020 Leonardo Lai. All rights reserved.
// //
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <rte_common.h> #include <rte_common.h>
#include <rte_eal.h> #include <rte_eal.h>
...@@ -15,6 +21,7 @@ ...@@ -15,6 +21,7 @@
#include "udpdk_api.h" #include "udpdk_api.h"
#include "udpdk_constants.h" #include "udpdk_constants.h"
#include "udpdk_poller.h"
#define RTE_LOGTYPE_INIT RTE_LOGTYPE_USER1 #define RTE_LOGTYPE_INIT RTE_LOGTYPE_USER1
...@@ -40,6 +47,8 @@ struct exch_slot *exch_slots = NULL; ...@@ -40,6 +47,8 @@ struct exch_slot *exch_slots = NULL;
static struct rte_mempool *pktmbuf_pool; static struct rte_mempool *pktmbuf_pool;
static pid_t poller_pid;
// TODO move to a utility file // TODO move to a utility file
enum exch_ring_func {EXCH_RING_RX, EXCH_RING_TX}; enum exch_ring_func {EXCH_RING_RX, EXCH_RING_TX};
...@@ -227,67 +236,100 @@ static int init_exchange_slots(void) ...@@ -227,67 +236,100 @@ static int init_exchange_slots(void)
return 0; return 0;
} }
/* Initialize DPDK */ /* Initialize UDPDK */
int udpdk_init(int argc, char *argv[]) int udpdk_init(int argc, char *argv[])
{ {
int retval; int retval;
// Initialize EAL (returns how many arguments it consumed) // Start the secondary process
retval = rte_eal_init(argc, argv); poller_pid = fork();
if (retval < 0) { if (poller_pid != 0) {
RTE_LOG(ERR, INIT, "Cannot initialize EAL\n"); // application
return -1;
}
argc -= retval;
argv += retval;
// Initialize pool of mbuf // Initialize EAL (returns how many arguments it consumed)
retval = init_mbuf_pool(); retval = rte_eal_init(argc, argv);
if (retval < 0) { if (retval < 0) {
RTE_LOG(ERR, INIT, "Cannot initialize pool of mbufs\n"); RTE_LOG(ERR, INIT, "Cannot initialize EAL\n");
return -1; return -1;
} }
argc -= retval;
argv += retval;
// Initialize DPDK ports // Initialize pool of mbuf
retval = init_port(PORT_RX); retval = init_mbuf_pool();
if (retval < 0) { if (retval < 0) {
RTE_LOG(ERR, INIT, "Cannot initialize RX port %d\n", PORT_RX); RTE_LOG(ERR, INIT, "Cannot initialize pool of mbufs\n");
return -1; return -1;
} }
check_port_link_status(PORT_RX);
if (PORT_TX != PORT_RX) { // Initialize DPDK ports
retval = init_port(PORT_TX); retval = init_port(PORT_RX);
if (retval < 0) { if (retval < 0) {
RTE_LOG(ERR, INIT, "Cannot initialize TX port %d\n", PORT_TX); RTE_LOG(ERR, INIT, "Cannot initialize RX port %d\n", PORT_RX);
return -1; return -1;
} }
check_port_link_status(PORT_TX); check_port_link_status(PORT_RX);
} else {
RTE_LOG(INFO, INIT, "Using the same port for RX and TX\n");
}
// Initialize memzone for exchange if (PORT_TX != PORT_RX) {
retval = init_shared_memzone(); retval = init_port(PORT_TX);
if (retval < 0) { if (retval < 0) {
RTE_LOG(ERR, INIT, "Cannot initialize memzone for exchange zone descriptors\n"); RTE_LOG(ERR, INIT, "Cannot initialize TX port %d\n", PORT_TX);
return -1; return -1;
} }
check_port_link_status(PORT_TX);
} else {
RTE_LOG(INFO, INIT, "Using the same port for RX and TX\n");
}
retval = init_exchange_slots(); // Initialize memzone for exchange
if (retval < 0) { retval = init_shared_memzone();
RTE_LOG(ERR, INIT, "Cannot initialize exchange slots\n"); if (retval < 0) {
return -1; RTE_LOG(ERR, INIT, "Cannot initialize memzone for exchange zone descriptors\n");
} return -1;
// TODO initialize shared structures }
// TODO start the secondary process retval = init_exchange_slots();
if (retval < 0) {
RTE_LOG(ERR, INIT, "Cannot initialize exchange slots\n");
return -1;
}
// TODO initialize shared structures
} else {
// child -> packet poller
// TODO the arguments should come from a config rather than being hardcoded
int poller_argc = 6;
char *poller_argv[6] = {
"./testapp",
"-l",
"3-4",
"-n",
"2",
"--proc-type=secondary"
};
sleep(1); // TODO use some synchronization mechanism between primary and secondary
if (poller_init(poller_argc, poller_argv) < 0) {
return -1;
}
poller_body();
}
// The parent process (application) returns immediately from init; instead, poller doesn't till it dies (or error)
return 0; return 0;
} }
void udpdk_cleanup(void) void udpdk_cleanup(void)
{ {
uint16_t port_id; uint16_t port_id;
pid_t pid;
// Kill the poller process
RTE_LOG(INFO, INIT, "Killing the poller process (%d)...\n", poller_pid);
kill(poller_pid, SIGTERM);
pid = waitpid(poller_pid, NULL, 0);
if (pid < 0) {
RTE_LOG(WARNING, INIT, "Failed killing the poller process\n");
} else {
RTE_LOG(INFO, INIT, "...killed!\n");
}
// Stop and close DPDK ports // Stop and close DPDK ports
RTE_ETH_FOREACH_DEV(port_id) { RTE_ETH_FOREACH_DEV(port_id) {
......
//
// Created by leoll2 on 9/27/20.
// Copyright (c) 2020 Leonardo Lai. All rights reserved.
//
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <rte_common.h>
#include <rte_memory.h>
#include <rte_memzone.h>
#include <rte_eal.h>
#include <rte_log.h>
#include <rte_per_lcore.h>
#include <rte_lcore.h>
#include <rte_ring.h>
#include <rte_mempool.h>
#include <rte_mbuf.h>
static volatile int poller_alive = 1;
/* Poller signal handler */
static void poller_sighandler(int sig)
{
printf("Poller: received request to stop\n");
poller_alive = 0;
}
/* Initialize UDPDK packet poller (runs in a separate process) */
int poller_init(int argc, char *argv[])
{
int retval;
// Initialize EAL
if ((retval = rte_eal_init(argc, argv)) < 0) {
return -1;
}
// Setup signals for termination
signal(SIGINT, poller_sighandler);
signal(SIGTERM, poller_sighandler);
return 0;
}
/* Packet polling routine */
void poller_body(void)
{
while (poller_alive) {
printf("Poller: main body\n");
sleep(1);
}
// Exit directly to avoid returning in the application main (as we forked)
exit(0);
}
\ No newline at end of file
//
// Created by leoll2 on 9/27/20.
// Copyright (c) 2020 Leonardo Lai. All rights reserved.
//
#ifndef UDPDK_POLLER_H
#define UDPDK_POLLER_H
int poller_init(int argc, char *argv[]);
void poller_body(void);
#endif //UDPDK_POLLER_H
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment