Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
U
udpdk
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ywj
udpdk
Commits
06e178f4
Commit
06e178f4
authored
Sep 27, 2020
by
Leonardo Lai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added poller skeleton
parent
87269a1e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
157 additions
and
43 deletions
+157
-43
udpdk/Makefile
udpdk/Makefile
+2
-1
udpdk/udpdk_init.c
udpdk/udpdk_init.c
+84
-42
udpdk/udpdk_poller.c
udpdk/udpdk_poller.c
+58
-0
udpdk/udpdk_poller.h
udpdk/udpdk_poller.h
+13
-0
No files found.
udpdk/Makefile
View file @
06e178f4
...
...
@@ -37,7 +37,8 @@ UDPDK_C= ${CC} -c $(DPDK_CFLAGS) ${CFLAGS} ${WERROR} $<
UDPDK_SRCS
+=
\
udpdk_syscall.c
\
udpdk_init.c
udpdk_init.c
\
udpdk_poller.c
SRCS
=
${UDPDK_SRCS}
...
...
udpdk/udpdk_init.c
View file @
06e178f4
...
...
@@ -2,6 +2,12 @@
// Created by leoll2 on 9/25/20.
// 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_eal.h>
...
...
@@ -15,6 +21,7 @@
#include "udpdk_api.h"
#include "udpdk_constants.h"
#include "udpdk_poller.h"
#define RTE_LOGTYPE_INIT RTE_LOGTYPE_USER1
...
...
@@ -40,6 +47,8 @@ struct exch_slot *exch_slots = NULL;
static
struct
rte_mempool
*
pktmbuf_pool
;
static
pid_t
poller_pid
;
// TODO move to a utility file
enum
exch_ring_func
{
EXCH_RING_RX
,
EXCH_RING_TX
};
...
...
@@ -227,67 +236,100 @@ static int init_exchange_slots(void)
return
0
;
}
/* Initialize DPDK */
/* Initialize
U
DPDK */
int
udpdk_init
(
int
argc
,
char
*
argv
[])
{
int
retval
;
// Initialize EAL (returns how many arguments it consumed)
retval
=
rte_eal_init
(
argc
,
argv
);
if
(
retval
<
0
)
{
RTE_LOG
(
ERR
,
INIT
,
"Cannot initialize EAL
\n
"
);
return
-
1
;
}
argc
-=
retval
;
argv
+=
retval
;
// Start the secondary process
poller_pid
=
fork
();
if
(
poller_pid
!=
0
)
{
// application
// Initialize pool of mbuf
retval
=
init_mbuf_pool
();
if
(
retval
<
0
)
{
RTE_LOG
(
ERR
,
INIT
,
"Cannot initialize pool of mbufs
\n
"
);
return
-
1
;
}
// Initialize EAL (returns how many arguments it consumed)
retval
=
rte_eal_init
(
argc
,
argv
);
if
(
retval
<
0
)
{
RTE_LOG
(
ERR
,
INIT
,
"Cannot initialize EAL
\n
"
);
return
-
1
;
}
argc
-=
retval
;
argv
+=
retval
;
// Initialize DPDK ports
retval
=
init_port
(
PORT_RX
);
if
(
retval
<
0
)
{
RTE_LOG
(
ERR
,
INIT
,
"Cannot initialize RX port %d
\n
"
,
PORT_RX
);
return
-
1
;
}
check_port_link_status
(
PORT_RX
);
// Initialize pool of mbuf
retval
=
init_mbuf_pool
();
if
(
retval
<
0
)
{
RTE_LOG
(
ERR
,
INIT
,
"Cannot initialize pool of mbufs
\n
"
);
return
-
1
;
}
if
(
PORT_TX
!=
PORT_RX
)
{
retval
=
init_port
(
PORT_
T
X
);
// Initialize DPDK ports
retval
=
init_port
(
PORT_
R
X
);
if
(
retval
<
0
)
{
RTE_LOG
(
ERR
,
INIT
,
"Cannot initialize
TX port %d
\n
"
,
PORT_T
X
);
RTE_LOG
(
ERR
,
INIT
,
"Cannot initialize
RX port %d
\n
"
,
PORT_R
X
);
return
-
1
;
}
check_port_link_status
(
PORT_TX
);
}
else
{
RTE_LOG
(
INFO
,
INIT
,
"Using the same port for RX and TX
\n
"
);
}
check_port_link_status
(
PORT_RX
);
// Initialize memzone for exchange
retval
=
init_shared_memzone
();
if
(
retval
<
0
)
{
RTE_LOG
(
ERR
,
INIT
,
"Cannot initialize memzone for exchange zone descriptors
\n
"
);
return
-
1
;
}
if
(
PORT_TX
!=
PORT_RX
)
{
retval
=
init_port
(
PORT_TX
);
if
(
retval
<
0
)
{
RTE_LOG
(
ERR
,
INIT
,
"Cannot initialize TX port %d
\n
"
,
PORT_TX
);
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
();
if
(
retval
<
0
)
{
RTE_LOG
(
ERR
,
INIT
,
"Cannot initialize exchange slots
\n
"
);
return
-
1
;
}
// TODO initialize shared structures
// Initialize memzone for exchange
retval
=
init_shared_memzone
();
if
(
retval
<
0
)
{
RTE_LOG
(
ERR
,
INIT
,
"Cannot initialize memzone for exchange zone descriptors
\n
"
)
;
return
-
1
;
}
// 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
;
}
void
udpdk_cleanup
(
void
)
{
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
RTE_ETH_FOREACH_DEV
(
port_id
)
{
...
...
udpdk/udpdk_poller.c
0 → 100644
View file @
06e178f4
//
// 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
udpdk/udpdk_poller.h
0 → 100644
View file @
06e178f4
//
// 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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment