From: ogawa.yasufumi@lab.ntt.co.jp
To: ferruh.yigit@intel.com, spp@dpdk.org, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH 1/6] spp_primary: refactor common for primary
Date: Tue, 15 Jan 2019 12:27:56 +0900 [thread overview]
Message-ID: <1547522881-10105-2-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <1547522881-10105-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp>
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Move specific variables and functions for spp_primary from
`shared/common.*` to `primary/*`.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/primary/args.c | 48 ++++++++++++++-
src/primary/args.h | 10 ++-
src/primary/init.c | 137 +++++++++++++++++++++++++++++++++++++++++-
src/primary/init.h | 16 ++++-
src/primary/main.c | 52 ++++++++--------
src/primary/primary.h | 10 +++
6 files changed, 239 insertions(+), 34 deletions(-)
create mode 100644 src/primary/primary.h
diff --git a/src/primary/args.c b/src/primary/args.c
index a601f85..f882ace 100644
--- a/src/primary/args.c
+++ b/src/primary/args.c
@@ -1,14 +1,16 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2015-2016 Intel Corporation
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
*/
#include <getopt.h>
#include <rte_memory.h>
-#include "args.h"
#include "common.h"
+#include "args.h"
#include "init.h"
+#include "primary.h"
/* global var for number of clients - extern in header */
uint16_t num_clients;
@@ -23,13 +25,52 @@ static const char *progname;
static void
usage(void)
{
- RTE_LOG(INFO, APP,
+ RTE_LOG(INFO, PRIMARY,
"%s [EAL options] -- -p PORTMASK -n NUM_CLIENTS [-s NUM_SOCKETS]\n"
" -p PORTMASK: hexadecimal bitmask of ports to use\n"
" -n NUM_CLIENTS: number of client processes to use\n"
, progname);
}
+/**
+ * The ports to be used by the application are passed in
+ * the form of a bitmask. This function parses the bitmask
+ * and places the port numbers to be used into the port[]
+ * array variable
+ */
+int
+parse_portmask(struct port_info *ports, uint16_t max_ports,
+ const char *portmask)
+{
+ char *end = NULL;
+ unsigned long pm;
+ uint16_t count = 0;
+
+ if (portmask == NULL || *portmask == '\0')
+ return -1;
+
+ /* convert parameter to a number and verify */
+ pm = strtoul(portmask, &end, 16);
+ if (end == NULL || *end != '\0' || pm == 0)
+ return -1;
+
+ /* loop through bits of the mask and mark ports */
+ while (pm != 0) {
+ if (pm & 0x01) { /* bit is set in mask, use port */
+ if (count >= max_ports)
+ RTE_LOG(WARNING, PRIMARY,
+ "port %u not present - ignoring\n",
+ count);
+ else
+ ports->id[ports->num_ports++] = count;
+ }
+ pm = (pm >> 1);
+ count++;
+ }
+
+ return 0;
+}
+
/**
* The application specific arguments follow the DPDK-specific
* arguments which are stripped by the DPDK init. This function
@@ -69,7 +110,8 @@ parse_app_args(uint16_t max_ports, int argc, char *argv[])
}
break;
default:
- RTE_LOG(ERR, APP, "ERROR: Unknown option '%c'\n", opt);
+ RTE_LOG(ERR,
+ PRIMARY, "ERROR: Unknown option '%c'\n", opt);
usage();
return -1;
}
diff --git a/src/primary/args.h b/src/primary/args.h
index 972d0ef..bbaf993 100644
--- a/src/primary/args.h
+++ b/src/primary/args.h
@@ -1,16 +1,20 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2015-2016 Intel Corporation
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
*/
-#ifndef _ARGS_H_
-#define _ARGS_H_
+#ifndef _PRIMARY_ARGS_H_
+#define _PRIMARY_ARGS_H_
#include <stdint.h>
+#include "common.h"
extern uint16_t num_clients;
extern char *server_ip;
extern int server_port;
+int parse_portmask(struct port_info *ports, uint16_t max_ports,
+ const char *portmask);
int parse_app_args(uint16_t max_ports, int argc, char *argv[]);
-#endif /* ifndef _ARGS_H_ */
+#endif /* _PRIMARY_ARGS_H_ */
diff --git a/src/primary/init.c b/src/primary/init.c
index 43941dd..2e33df9 100644
--- a/src/primary/init.c
+++ b/src/primary/init.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2015-2016 Intel Corporation
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
*/
#include <limits.h>
@@ -11,9 +12,14 @@
#include "args.h"
#include "common.h"
#include "init.h"
+#include "primary.h"
#define CLIENT_QUEUE_RINGSIZE 128
+#define MBUFS_PER_CLIENT 1536
+#define MBUFS_PER_PORT 1536
+#define MBUF_CACHE_SIZE 512
+
/* array of info/queues for clients */
struct client *clients;
@@ -37,7 +43,7 @@ init_mbuf_pools(void)
* don't pass single-producer/single-consumer flags to mbuf create as
* it seems faster to use a cache instead
*/
- RTE_LOG(DEBUG, APP, "Creating mbuf pool '%s' [%u mbufs] ...\n",
+ RTE_LOG(DEBUG, PRIMARY, "Creating mbuf pool '%s' [%u mbufs] ...\n",
PKTMBUF_POOL_NAME, num_mbufs);
if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
@@ -161,3 +167,132 @@ init(int argc, char *argv[])
return 0;
}
+
+/* Check the link status of all ports in up to 9s, and print them finally */
+void
+check_all_ports_link_status(struct port_info *ports, uint16_t port_num,
+ uint32_t port_mask)
+{
+#define CHECK_INTERVAL 100 /* 100ms */
+#define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
+ uint8_t count, all_ports_up;
+ uint16_t portid;
+ struct rte_eth_link link;
+
+ RTE_LOG(INFO, PRIMARY, "\nChecking link status");
+ fflush(stdout);
+ for (count = 0; count <= MAX_CHECK_TIME; count++) {
+ all_ports_up = 1;
+ for (portid = 0; portid < port_num; portid++) {
+ if ((port_mask & (1 << ports->id[portid])) == 0)
+ continue;
+
+ memset(&link, 0, sizeof(link));
+ rte_eth_link_get_nowait(ports->id[portid], &link);
+
+ /* clear all_ports_up flag if any link down */
+ if (link.link_status == 0) {
+ all_ports_up = 0;
+ break;
+ }
+ }
+
+ if (all_ports_up == 0) {
+ printf(".");
+ fflush(stdout);
+ rte_delay_ms(CHECK_INTERVAL);
+ } else {
+ printf("done\n");
+ break;
+ }
+ }
+
+ /* all ports up or timed out */
+ for (portid = 0; portid < port_num; portid++) {
+ if ((port_mask & (1 << ports->id[portid])) == 0)
+ continue;
+
+ memset(&link, 0, sizeof(link));
+ rte_eth_link_get_nowait(ports->id[portid], &link);
+
+ /* print link status */
+ if (link.link_status)
+ RTE_LOG(INFO, PRIMARY,
+ "Port %d Link Up - speed %u Mbps - %s\n",
+ ports->id[portid], link.link_speed,
+ (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
+ "full-duplex\n" : "half-duplex\n");
+ else
+ RTE_LOG(INFO, PRIMARY,
+ "Port %d Link Down\n", ports->id[portid]);
+ }
+}
+
+/**
+ * Initialise an individual port:
+ * - configure number of rx and tx rings
+ * - set up each rx ring, to pull from the main mbuf pool
+ * - set up each tx ring
+ * - start the port and report its status to stdout
+ */
+int
+init_port(uint16_t port_num, struct rte_mempool *pktmbuf_pool)
+{
+ /* for port configuration all features are off by default */
+ const struct rte_eth_conf port_conf = {
+ .rxmode = {
+ .mq_mode = ETH_MQ_RX_RSS,
+ },
+ };
+ const uint16_t rx_rings = 1, tx_rings = 1;
+ const uint16_t rx_ring_size = RTE_MP_RX_DESC_DEFAULT;
+ const uint16_t tx_ring_size = RTE_MP_TX_DESC_DEFAULT;
+ uint16_t q;
+ int retval;
+ struct rte_eth_dev_info dev_info;
+ struct rte_eth_conf local_port_conf = port_conf;
+ struct rte_eth_txconf txq_conf;
+
+ RTE_LOG(INFO, PRIMARY, "Port %u init ... ", port_num);
+ fflush(stdout);
+
+ rte_eth_dev_info_get(port_num, &dev_info);
+ if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
+ local_port_conf.txmode.offloads |=
+ DEV_TX_OFFLOAD_MBUF_FAST_FREE;
+ txq_conf = dev_info.default_txconf;
+ txq_conf.offloads = local_port_conf.txmode.offloads;
+
+ /*
+ * Standard DPDK port initialisation - config port, then set up
+ * rx and tx rings
+ */
+ retval = rte_eth_dev_configure(port_num, rx_rings, tx_rings,
+ &port_conf);
+ if (retval != 0)
+ return retval;
+
+ for (q = 0; q < rx_rings; q++) {
+ retval = rte_eth_rx_queue_setup(port_num, q, rx_ring_size,
+ rte_eth_dev_socket_id(port_num), NULL, pktmbuf_pool);
+ if (retval < 0)
+ return retval;
+ }
+
+ for (q = 0; q < tx_rings; q++) {
+ retval = rte_eth_tx_queue_setup(port_num, q, tx_ring_size,
+ rte_eth_dev_socket_id(port_num), &txq_conf);
+ if (retval < 0)
+ return retval;
+ }
+
+ rte_eth_promiscuous_enable(port_num);
+
+ retval = rte_eth_dev_start(port_num);
+ if (retval < 0)
+ return retval;
+
+ RTE_LOG(INFO, PRIMARY, "Port %d Init done\n", port_num);
+
+ return 0;
+}
diff --git a/src/primary/init.h b/src/primary/init.h
index 638a4e9..286bdb5 100644
--- a/src/primary/init.h
+++ b/src/primary/init.h
@@ -1,12 +1,17 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2015-2016 Intel Corporation
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
*/
-#ifndef _INIT_H_
-#define _INIT_H_
+#ifndef _PRIMARY_INIT_H_
+#define _PRIMARY_INIT_H_
#include <stdint.h>
+#define MBUF_OVERHEAD (sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
+#define RX_MBUF_DATA_SIZE 2048
+#define MBUF_SIZE (RX_MBUF_DATA_SIZE + MBUF_OVERHEAD)
+
/*
* Define a client structure with all needed info, including
* stats from the clients.
@@ -33,4 +38,9 @@ extern struct port_info *ports;
int init(int argc, char *argv[]);
-#endif /* ifndef _INIT_H_ */
+void check_all_ports_link_status(struct port_info *ports, uint16_t port_num,
+ uint32_t port_mask);
+
+int init_port(uint16_t port_num, struct rte_mempool *pktmbuf_pool);
+
+#endif /* ifndef _PRIMARY_INIT_H_ */
diff --git a/src/primary/main.c b/src/primary/main.c
index e010bc6..12b86e5 100644
--- a/src/primary/main.c
+++ b/src/primary/main.c
@@ -1,7 +1,9 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2015-2016 Intel Corporation
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
*/
+#include <signal.h>
#include <arpa/inet.h>
#include <inttypes.h>
#include <poll.h>
@@ -12,6 +14,7 @@
#include "args.h"
#include "common.h"
#include "init.h"
+#include "primary.h"
/* Buffer sizes of status message of primary. Total must be equal to MSG_SIZE */
#define PRI_BUF_SIZE_PHY 512
@@ -27,7 +30,7 @@ static void
turn_off(int sig)
{
on = 0;
- RTE_LOG(INFO, APP, "terminated %d\n", sig);
+ RTE_LOG(INFO, PRIMARY, "terminated %d\n", sig);
}
static const char *
@@ -114,7 +117,7 @@ sleep_lcore(void *dummy __rte_unused)
if (rte_atomic32_test_and_set(&display_stats)) {
const unsigned int sleeptime = 1;
- RTE_LOG(INFO, APP, "Core %u displaying statistics\n",
+ RTE_LOG(INFO, PRIMARY, "Core %u displaying statistics\n",
rte_lcore_id());
/* Longer initial pause so above log is seen */
@@ -146,12 +149,12 @@ do_send(int *connected, int *sock, char *str)
ret = send(*sock, str, MSG_SIZE, 0);
if (ret == -1) {
- RTE_LOG(ERR, APP, "send failed");
+ RTE_LOG(ERR, PRIMARY, "send failed");
*connected = 0;
return -1;
}
- RTE_LOG(INFO, APP, "To Server: %s\n", str);
+ RTE_LOG(INFO, PRIMARY, "To Server: %s\n", str);
return 0;
}
@@ -199,7 +202,7 @@ get_status_json(char *str)
char phy_port[buf_size];
for (i = 0; i < ports->num_ports; i++) {
- RTE_LOG(DEBUG, APP, "Size of phy_ports str: %d\n",
+ RTE_LOG(DEBUG, PRIMARY, "Size of phy_ports str: %d\n",
(int)strlen(phy_ports));
memset(phy_port, '\0', buf_size);
@@ -216,7 +219,7 @@ get_status_json(char *str)
int cur_buf_size = (int)strlen(phy_ports) +
(int)strlen(phy_port);
if (cur_buf_size > phyp_buf_size - 1) {
- RTE_LOG(ERR, APP,
+ RTE_LOG(ERR, PRIMARY,
"Cannot send all of phy_port stats (%d/%d)\n",
i, ports->num_ports);
sprintf(phy_ports + strlen(phy_ports) - 1, "%s", "");
@@ -232,7 +235,7 @@ get_status_json(char *str)
char ring_port[buf_size];
for (i = 0; i < num_clients; i++) {
- RTE_LOG(DEBUG, APP, "Size of ring_ports str: %d\n",
+ RTE_LOG(DEBUG, PRIMARY, "Size of ring_ports str: %d\n",
(int)strlen(ring_ports));
memset(ring_port, '\0', buf_size);
@@ -249,7 +252,7 @@ get_status_json(char *str)
int cur_buf_size = (int)strlen(ring_ports) +
(int)strlen(ring_port);
if (cur_buf_size > ringp_buf_size - 1) {
- RTE_LOG(ERR, APP,
+ RTE_LOG(ERR, PRIMARY,
"Cannot send all of ring_port stats (%d/%d)\n",
i, num_clients);
sprintf(ring_ports + strlen(ring_ports) - 1, "%s", "");
@@ -262,7 +265,7 @@ get_status_json(char *str)
sprintf(ring_ports, "%s,", ring_ports);
}
- RTE_LOG(DEBUG, APP, "{\"phy_ports\": [%s], \"ring_ports\": [%s]}",
+ RTE_LOG(DEBUG, PRIMARY, "{\"phy_ports\": [%s], \"ring_ports\": [%s]}",
phy_ports, ring_ports);
sprintf(str, "{\"phy_ports\": [%s], \"ring_ports\": [%s]}",
@@ -281,20 +284,20 @@ parse_command(char *str)
/* tokenize the user commands from controller */
token_list[i] = strtok(str, " ");
while (token_list[i] != NULL) {
- RTE_LOG(DEBUG, APP, "token %d = %s\n", i, token_list[i]);
+ RTE_LOG(DEBUG, PRIMARY, "token %d = %s\n", i, token_list[i]);
i++;
token_list[i] = strtok(NULL, " ");
}
if (!strcmp(token_list[0], "status")) {
- RTE_LOG(DEBUG, APP, "status\n");
+ RTE_LOG(DEBUG, PRIMARY, "status\n");
memset(str, '\0', MSG_SIZE);
ret = get_status_json(str);
} else if (!strcmp(token_list[0], "exit")) {
- RTE_LOG(DEBUG, APP, "exit\n");
- RTE_LOG(DEBUG, APP, "stop\n");
+ RTE_LOG(DEBUG, PRIMARY, "exit\n");
+ RTE_LOG(DEBUG, PRIMARY, "stop\n");
cmd = STOP;
ret = -1;
@@ -326,14 +329,14 @@ do_receive(int *connected, int *sock, char *str)
ret = recv(*sock, str, MSG_SIZE, 0);
if (ret <= 0) {
- RTE_LOG(DEBUG, APP, "Receive count: %d\n", ret);
+ RTE_LOG(DEBUG, PRIMARY, "Receive count: %d\n", ret);
if (ret < 0)
- RTE_LOG(ERR, APP, "Receive Fail");
+ RTE_LOG(ERR, PRIMARY, "Receive Fail");
else
- RTE_LOG(INFO, APP, "Receive 0\n");
+ RTE_LOG(INFO, PRIMARY, "Receive 0\n");
- RTE_LOG(INFO, APP, "Assume Server closed connection\n");
+ RTE_LOG(INFO, PRIMARY, "Assume Server closed connection\n");
close(*sock);
*sock = SOCK_RESET;
*connected = 0;
@@ -351,7 +354,7 @@ do_connection(int *connected, int *sock)
if (*connected == 0) {
if (*sock < 0) {
- RTE_LOG(INFO, APP, "Creating socket...\n");
+ RTE_LOG(INFO, PRIMARY, "Creating socket...\n");
*sock = socket(AF_INET, SOCK_STREAM, 0);
if (*sock < 0)
rte_exit(EXIT_FAILURE, "socket error\n");
@@ -366,15 +369,16 @@ do_connection(int *connected, int *sock)
pfd.events = POLLIN;
}
- RTE_LOG(INFO, APP, "Trying to connect ... socket %d\n", *sock);
+ RTE_LOG(INFO,
+ PRIMARY, "Trying to connect ... socket %d\n", *sock);
ret = connect(*sock, (struct sockaddr *) &servaddr,
sizeof(servaddr));
if (ret < 0) {
- RTE_LOG(ERR, APP, "Connection Error");
+ RTE_LOG(ERR, PRIMARY, "Connection Error");
return ret;
}
- RTE_LOG(INFO, APP, "Connected\n");
+ RTE_LOG(INFO, PRIMARY, "Connected\n");
*connected = 1;
}
@@ -399,7 +403,7 @@ main(int argc, char *argv[])
set_user_log_debug(1);
- RTE_LOG(INFO, APP, "Finished Process Init.\n");
+ RTE_LOG(INFO, PRIMARY, "Finished Process Init.\n");
/* clear statistics */
clear_stats();
@@ -418,7 +422,7 @@ main(int argc, char *argv[])
if (ret < 0)
continue;
- RTE_LOG(DEBUG, APP, "Received string: %s\n", str);
+ RTE_LOG(DEBUG, PRIMARY, "Received string: %s\n", str);
flg_exit = parse_command(str);
@@ -434,6 +438,6 @@ main(int argc, char *argv[])
/* exit */
close(sock);
sock = SOCK_RESET;
- RTE_LOG(INFO, APP, "spp_primary exit.\n");
+ RTE_LOG(INFO, PRIMARY, "spp_primary exit.\n");
return 0;
}
diff --git a/src/primary/primary.h b/src/primary/primary.h
new file mode 100644
index 0000000..b0d0d64
--- /dev/null
+++ b/src/primary/primary.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
+ */
+
+#ifndef _PRIMARY_PRIMARY_H_
+#define _PRIMARY_PRIMARY_H_
+
+#define RTE_LOGTYPE_PRIMARY RTE_LOGTYPE_USER1
+
+#endif
--
2.17.1
next prev parent reply other threads:[~2019-01-15 3:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-15 3:27 [spp] [PATCH 0/6] Refactor common libs ogawa.yasufumi
2019-01-15 3:27 ` ogawa.yasufumi [this message]
2019-01-15 3:27 ` [spp] [PATCH 2/6] shared: refactor common for SPP secondaries ogawa.yasufumi
2019-01-15 3:27 ` [spp] [PATCH 3/6] spp_nfv: refactor common for spp_nfv ogawa.yasufumi
2019-01-15 3:27 ` [spp] [PATCH 4/6] shared: refactor common functions ogawa.yasufumi
2019-01-15 3:28 ` [spp] [PATCH 5/6] shared: refactor libs of SPP secondary ogawa.yasufumi
2019-01-15 3:28 ` [spp] [PATCH 6/6] spp_nfv: refactor file structure ogawa.yasufumi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1547522881-10105-2-git-send-email-ogawa.yasufumi@lab.ntt.co.jp \
--to=ogawa.yasufumi@lab.ntt.co.jp \
--cc=ferruh.yigit@intel.com \
--cc=spp@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).