summaryrefslogtreecommitdiff
path: root/logreader
diff options
context:
space:
mode:
Diffstat (limited to 'logreader')
-rw-r--r--logreader/.gitignore8
-rw-r--r--logreader/Makefile44
-rw-r--r--logreader/config.c746
-rwxr-xr-xlogreader/dlogreaderbin0 -> 477573 bytes
-rw-r--r--logreader/main.c22
-rw-r--r--logreader/nstat.c208
-rw-r--r--logreader/nstat.h72
7 files changed, 1100 insertions, 0 deletions
diff --git a/logreader/.gitignore b/logreader/.gitignore
new file mode 100644
index 0000000..75fb413
--- /dev/null
+++ b/logreader/.gitignore
@@ -0,0 +1,8 @@
+*.o
+*.ko
+*.swp
+*.tmp
+*.log
+tags
+.tags
+
diff --git a/logreader/Makefile b/logreader/Makefile
new file mode 100644
index 0000000..8c2dc09
--- /dev/null
+++ b/logreader/Makefile
@@ -0,0 +1,44 @@
+
+ifeq ($(MODULES_STATS),0)
+ MODULES_CFAGS += -DAPP_STAT=0
+endif
+
+TARGET = dlogreader
+MAJOR_VERSION = 1
+SUB_VERSION = 1
+
+DPDK_INCLUDE = $(DPDK_ROOT)/$(DPDK_TARGET)/include
+DPDK_LIB_DIR = $(DPDK_ROOT)/$(DPDK_TARGET)/lib
+DPDK_LIB = $(wildcard ${DPDK_LIB_DIR}/*.a)
+DPDK_CONFIG = $(DPDK_INCLUDE)/rte_config.h
+
+DIR_INC = -I$(DPDK_INCLUDE) -I$(APP_ROOT)/include/MESA -I$(APP_ROOT)/include/serial
+DIR_SRC = ./
+DIR_OBJ = ./
+DIR_BIN = ./
+DIR_LIB = $(APP_ROOT)/lib/
+
+MODULES = -Wl,--start-group $(DPDK_LIB) -Wl,--end-group
+MODULES += $(APP_ROOT)/lib/libMESA_prof_load.a
+
+CC = gcc
+SRC = $(wildcard ${DIR_SRC}/*.c)
+OBJ = $(patsubst %.c,${DIR_OBJ}/%.o,$(notdir ${SRC}))
+LDFLAG += -lrt -lpthread
+CFLAGS += -g -fPIC ${OPTFLAGS} ${DIR_INC} -L${DIR_LIB} -std=gnu99 -include ${DPDK_CONFIG} $(MODULES_CFAGS)
+
+${TARGET}:${OBJ}
+ ${CC} ${LDFLAG} -o $@ ${OBJ} ${MODULES}
+${DIR_OBJ}/%.o:${DIR_SRC}/%.c
+ ${CC} ${CFLAGS} -c $< -o $@
+
+.PHONY:install clean
+
+all: $(TARGET)
+
+clean:
+ rm -f *.o
+install:
+ cp -f ${TARGET} ${INSTALL}
+distclean: clean
+ rm -f ${TARGET}
diff --git a/logreader/config.c b/logreader/config.c
new file mode 100644
index 0000000..9a9ac4e
--- /dev/null
+++ b/logreader/config.c
@@ -0,0 +1,746 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright(c) 2010-2013 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 <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <string.h>
+#include <sys/queue.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <unistd.h>
+
+
+#include <rte_common.h>
+#include <rte_byteorder.h>
+#include <rte_log.h>
+#include <rte_memory.h>
+#include <rte_memcpy.h>
+#include <rte_memzone.h>
+#include <rte_tailq.h>
+#include <rte_eal.h>
+#include <rte_per_lcore.h>
+#include <rte_launch.h>
+#include <rte_atomic.h>
+#include <rte_cycles.h>
+#include <rte_prefetch.h>
+#include <rte_lcore.h>
+#include <rte_per_lcore.h>
+#include <rte_branch_prediction.h>
+#include <rte_interrupts.h>
+#include <rte_pci.h>
+#include <rte_random.h>
+#include <rte_debug.h>
+#include <rte_ether.h>
+#include <rte_ethdev.h>
+#include <rte_ring.h>
+#include <rte_mempool.h>
+#include <rte_mbuf.h>
+#include <rte_ip.h>
+#include <rte_tcp.h>
+#include <rte_lpm.h>
+#include <rte_string_fns.h>
+
+#include <assert.h>
+
+#include "main.h"
+#include "MESA_prof_load.h"
+
+struct app_params app;
+const char *conf_path[] = {
+ "conf/nl2fwd.conf",
+ ".nl2fwd.conf",
+ "~/.nl2fwd.conf",
+ "/etc/nl2fwd.conf",
+ "/usr/local/etc/nl2fwd.conf"};
+
+const int n_conf_path = 5;
+
+#ifndef APP_MAX_STRING
+#define APP_MAX_STRING 4096
+#endif
+
+void app_print_usage(void)
+{
+ printf("usages\n");
+}
+
+static int app_parse_conffile_rx(char * fcfg_path)
+{
+ int n_arg_rx = 0;
+ MESA_load_profile_int_def(fcfg_path,"rx_common","rx_count",&n_arg_rx,0);
+
+ if(n_arg_rx <= 0)
+ return -1;
+
+ for(int i = 0; i < n_arg_rx; i++)
+ {
+ struct app_lcore_params *lp;
+
+ char rx_section_name[APP_MAX_STRING];
+ sprintf(rx_section_name,"rx_%d",i);
+
+ int port,queue,lcore;
+ MESA_load_profile_int_def(fcfg_path,rx_section_name,"port",&port,0);
+ MESA_load_profile_int_def(fcfg_path,rx_section_name,"queue",&queue,0);
+ MESA_load_profile_int_def(fcfg_path,rx_section_name,"lcore",&lcore,0);
+
+ /* Enable port and queue for later initialization */
+ if ((port >= APP_MAX_NIC_PORTS) || (queue >= APP_MAX_RX_QUEUES_PER_NIC_PORT)) {
+ return -3;
+ }
+ if (app.nic_rx_queue_mask[port][queue] != 0) {
+ return -4;
+ }
+ app.enabled_port_mask |= 1 << port;
+ app.nic_rx_queue_mask[port][queue] = 1;
+
+ /* Check and assign (port, queue) to I/O lcore */
+ if (rte_lcore_is_enabled(lcore) == 0) {
+ return -5;
+ }
+
+ if (lcore >= APP_MAX_LCORES) {
+ return -6;
+ }
+ lp = &app.lcore_params[lcore];
+ if (lp->type == e_APP_LCORE_WORKER) {
+ return -7;
+ }
+ lp->type = e_APP_LCORE_IO;
+ for (int j = 0; j < lp->io.rx.n_nic_queues; j++) {
+ if ((lp->io.rx.nic_queues[j].port == port) &&
+ (lp->io.rx.nic_queues[j].queue == queue)) {
+ return -8;
+ }
+ }
+ if (lp->io.rx.n_nic_queues >= APP_MAX_NIC_RX_QUEUES_PER_IO_LCORE) {
+ return -9;
+ }
+ lp->io.rx.nic_queues[lp->io.rx.n_nic_queues].port = (uint8_t) port;
+ lp->io.rx.nic_queues[lp->io.rx.n_nic_queues].queue = (uint8_t) queue;
+ lp->io.rx.n_nic_queues ++;
+
+#if 0
+ int tx_port_existed = 0;
+ for(int j = 0; j < lp->io.tx.n_nic_ports; j++) {
+ if (lp->io.tx.nic_ports[j] == (uint8_t) port) {
+ tx_port_existed = 1;
+ break;
+ }
+ }
+
+ if(!tx_port_existed) {
+ lp->io.tx.nic_ports[lp->io.tx.n_nic_ports] = port;
+ lp->io.tx.n_nic_ports ++;
+ app.enabled_port_mask |= 1 << (uint8_t)port;
+ app.nic_tx_port_mask[(uint8_t)port] = 1;
+ }
+#endif
+ }
+
+ return 0;
+}
+
+#if 0
+static int app_parse_conffile_tx(char *fcfg_path)
+{
+
+ char tx_strbuf[APP_MAX_STRING];
+ char * parse_arg = tx_strbuf;
+ int tx_enable;
+
+ MESA_load_profile_int_def(fcfg_path,"tx","tx_enable",&tx_enable,0);
+ MESA_load_profile_string_def(fcfg_path,"tx","tx_port",parse_arg,
+ sizeof(char) * APP_MAX_STRING,"");
+ if(!tx_enable)
+ return 0;
+
+ for(parse_arg = strtok(parse_arg,",");
+ parse_arg != NULL; parse_arg = strtok(NULL,","))
+ {
+ int port = 0;
+ int ret = sscanf(parse_arg,"%d",&port);
+ if(ret <= 0)
+ return -1; //Parse Error.
+ if(port > APP_MAX_NIC_PORTS|| port < 0)
+ return -2; // Wrong Port number.
+
+ //Set TX Mask and Port Mask.
+ app.enabled_port_mask |= 1 << (uint8_t)port;
+ app.nic_tx_port_mask[(uint8_t)port] = 1;
+ }
+
+ return 0;
+}
+#endif
+
+static int app_parse_conffile_tx(char * fcfg_path)
+{
+ int n_arg_tx = 0;
+ MESA_load_profile_int_def(fcfg_path,"tx_common","tx_count",&n_arg_tx,0);
+
+ if(n_arg_tx <= 0)
+ return -1;
+
+ for(int i = 0; i < n_arg_tx; i++)
+ {
+ struct app_lcore_params *lp;
+ char tx_section_name[APP_MAX_STRING];
+ sprintf(tx_section_name,"tx_%d",i);
+
+ int port,lcore;
+ MESA_load_profile_int_def(fcfg_path,tx_section_name,"port",&port,0);
+ MESA_load_profile_int_def(fcfg_path,tx_section_name,"lcore",&lcore,0);
+
+ /* Enable port and queue for later initialization */
+ if (port >= APP_MAX_NIC_PORTS) {
+ return -3;
+ }
+ if (app.nic_tx_port_mask[port] != 0) {
+ return -4;
+ }
+ app.nic_tx_port_mask[port] = 1;
+
+ /* Check and assign (port, queue) to I/O lcore */
+ if (rte_lcore_is_enabled(lcore) == 0) {
+ return -5;
+ }
+
+ if (lcore >= APP_MAX_LCORES) {
+ return -6;
+ }
+ lp = &app.lcore_params[lcore];
+ if (lp->type == e_APP_LCORE_WORKER) {
+ return -7;
+ }
+ lp->type = e_APP_LCORE_IO;
+ for (int j = 0; j < lp->io.tx.n_nic_ports; j++) {
+ if (lp->io.tx.nic_ports[j] == port) {
+ return -8;
+ }
+ }
+ if (lp->io.tx.n_nic_ports >= APP_MAX_NIC_TX_PORTS_PER_IO_LCORE) {
+ return -9;
+ }
+ lp->io.tx.nic_ports[lp->io.tx.n_nic_ports] = (uint8_t) port;
+ lp->io.tx.n_nic_ports ++;
+
+ }
+
+ return 0;
+}
+
+static int app_parse_conffile_w(char *fcfg_path)
+{
+
+ char worker_buf[APP_MAX_STRING];
+ MESA_load_profile_string_def(fcfg_path,"worker","lcore",worker_buf,
+ sizeof(char) * APP_MAX_STRING,"");
+
+ char *p = worker_buf;
+
+ while (*p != 0) {
+ struct app_lcore_params *lp;
+ uint32_t lcore;
+
+
+ errno = 0;
+ lcore = strtoul(p, NULL, 0);
+ if ((errno != 0)) {
+ return -2;
+ }
+
+ /* Check and enable worker lcore */
+#if 0
+ if (rte_lcore_is_enabled(lcore) == 0) {
+ return -3;
+ }
+#endif
+
+ if (lcore >= APP_MAX_LCORES) {
+ return -4;
+ }
+ lp = &app.lcore_params[lcore];
+ if (lp->type == e_APP_LCORE_IO) {
+ return -5;
+ }
+ lp->type = e_APP_LCORE_WORKER;
+
+ p = strchr(p, ',');
+ if (p == NULL) {
+ break;
+ }
+ p++;
+ }
+
+ return 0;
+}
+
+
+
+static int app_parse_conffile_rxtx_paras(char * fcfg_path)
+{
+ MESA_load_profile_int_def(fcfg_path,"common","nic_rx_ring_size",
+ &app.nic_rx_ring_size,APP_DEFAULT_NIC_RX_RING_SIZE);
+ MESA_load_profile_int_def(fcfg_path,"common","nic_tx_ring_size",
+ &app.nic_tx_ring_size,APP_DEFAULT_NIC_TX_RING_SIZE);
+ MESA_load_profile_int_def(fcfg_path,"common","ring_rx_size",
+ &app.ring_rx_size, APP_DEFAULT_RING_RX_SIZE);
+ MESA_load_profile_int_def(fcfg_path,"common","ring_tx_size",
+ &app.ring_tx_size, APP_DEFAULT_RING_TX_SIZE);
+
+
+ MESA_load_profile_int_def(fcfg_path,"common","burst_size_io_rx_read",
+ &app.burst_size_io_rx_read,APP_DEFAULT_BURST_SIZE_IO_RX_READ);
+ MESA_load_profile_int_def(fcfg_path,"common","burst_size_io_rx_write",
+ &app.burst_size_io_rx_write,APP_DEFAULT_BURST_SIZE_IO_RX_WRITE);
+ MESA_load_profile_int_def(fcfg_path,"common","burst_size_io_tx_read",
+ &app.burst_size_io_tx_read,APP_DEFAULT_BURST_SIZE_IO_TX_READ);
+ MESA_load_profile_int_def(fcfg_path,"common","burst_size_io_tx_write",
+ &app.burst_size_io_tx_write,APP_DEFAULT_BURST_SIZE_IO_TX_WRITE);
+ MESA_load_profile_int_def(fcfg_path,"common","burst_size_worker_read",
+ &app.burst_size_worker_read,APP_DEFAULT_BURST_SIZE_WORKER_READ);
+ MESA_load_profile_int_def(fcfg_path,"common","burst_size_worker_write",
+ &app.burst_size_worker_write,APP_DEFAULT_BURST_SIZE_WORKER_WRITE);
+
+
+ return 0;
+}
+
+
+
+static int app_parse_conffile_map(char * fcfg_path)
+{
+ int rx_port,tx_port;
+ int n_record = 0;
+
+ MESA_load_profile_int_def(fcfg_path,"map","n_map",&n_record,0);
+
+ if(n_record <= 0)
+ return 0;
+
+ char map_strbuf[APP_MAX_STRING];
+
+ for(int i = 0; i < n_record; i++)
+ {
+ char map_key[APP_MAX_STRING];
+
+ char * map_strbuf_p = map_strbuf;
+ char * port_str = NULL;
+
+ sprintf(map_key,"map_%d",i);
+
+ int ret = MESA_load_profile_string_def(fcfg_path,"map",map_key,map_strbuf,
+ sizeof(char) * APP_MAX_STRING,"");
+ if(ret < 0)
+ return -i;
+
+ port_str = strtok(map_strbuf_p, ",");
+ ret = sscanf(port_str,"%d",&rx_port);
+
+ if(ret <= 0)
+ return -i;
+
+ // Add Map Record for RX Port.
+ app.rxtx_port_map[i].rx_port = rx_port;
+
+ int j = 1;
+ for(j = 1,port_str = strtok(NULL, ",");
+ port_str != NULL;
+ port_str = strtok(NULL, ","))
+ {
+ if(sscanf(port_str,"%d",&tx_port) < 0)
+ return -i;
+ if(tx_port > APP_MAX_NIC_PORTS || tx_port < 0)
+ return -i;
+ if(app.nic_tx_port_mask[tx_port] != 1)
+ return -i;
+
+ // Add Map Record for TX Report
+ app.rxtx_port_map[i].tx_port[j-1] = tx_port;
+
+ }
+ app.rxtx_port_map[i].n_tx_port = (uint32_t)j;
+ (app.n_rxtx_port_map)++;
+
+ app.rxtx_stream_record[(uint8_t)app.n_rxtx_stream].rx_port = rx_port;
+ app.rxtx_stream_record[(uint8_t)app.n_rxtx_stream].tx_port = tx_port;
+ (app.n_rxtx_stream)++;
+
+ app.map_type = e_APP_MAP_TYPE_PORTMAP;
+
+ }
+
+ assert(app.n_rxtx_port_map == n_record);
+
+ return n_record;
+}
+
+static int app_parse_conffile_stat(char *fcfg_path)
+{
+ MESA_load_profile_int_def(fcfg_path,"stat","enable",&(app.statistics.enable),1);
+ MESA_load_profile_int_def(fcfg_path,"stat","print", &(app.statistics.is_printmsg),1);
+ MESA_load_profile_int_def(fcfg_path,"stat","sample_time", &(app.statistics.sample_time),1);
+
+ if(app.watchdog_paras.enable)
+ app.statistics.enable = 1;
+
+ return 0;
+}
+
+
+static int app_parse_conffile_mempool(char *fcfg_path)
+{
+
+ MESA_load_profile_int_def(fcfg_path,"mempool","mempool_buffers",
+ &(app.mempool.mempool_buffers),APP_DEFAULT_MEMPOOL_BUFFERS);
+ MESA_load_profile_int_def(fcfg_path,"mempool","mempool_mbuf_size",
+ &(app.mempool.mempool_mbuf_size),APP_DEFAULT_MBUF_SIZE);
+ MESA_load_profile_int_def(fcfg_path,"mempool","mempool_cache_size",
+ &(app.mempool.mempool_cache_size),APP_DEFAULT_MEMPOOL_CACHE_SIZE);
+
+ return 0;
+}
+
+
+int app_parse_args(int argc, char **argv)
+{
+
+
+ app.enabled_port_mask = 0;
+ app.key_type = KEY_TYPE_IS_IP;
+
+ for(int i = 0; i < n_conf_path ; i++)
+ {
+ if(access(conf_path[i],R_OK) == 0) {
+
+ char * path = (char *)conf_path[i];
+
+ if(app_parse_conffile_rx(path) < 0)
+ return -1;
+ if(app_parse_conffile_tx(path) < 0)
+ return -2;
+ if(app_parse_conffile_w(path) < 0)
+ return -3;
+ if(app_parse_conffile_rxtx_paras(path) < 0)
+ return -4;
+ if(app_parse_conffile_stat(path) < 0)
+ return -5;
+ if(app_parse_conffile_map(path) < 0)
+ return -6;
+ if(app_parse_conffile_mempool(path) < 0)
+ return -7;
+ return 0;
+ }
+ }
+ return -9;
+}
+
+int
+app_get_nic_rx_queues_per_port(uint8_t port)
+{
+ uint32_t i, count;
+
+ if (port >= APP_MAX_NIC_PORTS) {
+ return -1;
+ }
+
+ count = 0;
+ for (i = 0; i < APP_MAX_RX_QUEUES_PER_NIC_PORT; i ++) {
+ if (app.nic_rx_queue_mask[port][i] == 1) {
+ count ++;
+ }
+ }
+
+ return count;
+}
+
+int
+app_get_lcore_for_nic_rx(uint8_t port, uint8_t queue, uint32_t *lcore_out)
+{
+ uint32_t lcore;
+
+ for (lcore = 0; lcore < APP_MAX_LCORES; lcore ++) {
+ struct app_lcore_params_io *lp = &app.lcore_params[lcore].io;
+ uint32_t i;
+
+ if (app.lcore_params[lcore].type != e_APP_LCORE_IO) {
+ continue;
+ }
+
+ for (i = 0; i < lp->rx.n_nic_queues; i ++) {
+ if ((lp->rx.nic_queues[i].port == port) &&
+ (lp->rx.nic_queues[i].queue == queue)) {
+ *lcore_out = lcore;
+ return 0;
+ }
+ }
+ }
+
+ return -1;
+}
+
+int
+app_get_lcore_for_nic_tx(uint8_t port, uint32_t *lcore_out)
+{
+ uint32_t lcore;
+
+ for (lcore = 0; lcore < APP_MAX_LCORES; lcore ++) {
+ struct app_lcore_params_io *lp = &app.lcore_params[lcore].io;
+ uint32_t i;
+
+ if (app.lcore_params[lcore].type != e_APP_LCORE_IO) {
+ continue;
+ }
+
+ for (i = 0; i < lp->tx.n_nic_ports; i ++) {
+ if (lp->tx.nic_ports[i] == port) {
+ *lcore_out = lcore;
+ return 0;
+ }
+ }
+ }
+
+ return -1;
+}
+
+int
+app_is_socket_used(uint32_t socket)
+{
+ uint32_t lcore;
+
+ for (lcore = 0; lcore < APP_MAX_LCORES; lcore ++) {
+ if (app.lcore_params[lcore].type == e_APP_LCORE_DISABLED) {
+ continue;
+ }
+
+ if (socket == rte_lcore_to_socket_id(lcore)) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+uint32_t
+app_get_lcores_io_rx(void)
+{
+ uint32_t lcore, count;
+
+ count = 0;
+ for (lcore = 0; lcore < APP_MAX_LCORES; lcore ++) {
+ struct app_lcore_params_io *lp_io = &app.lcore_params[lcore].io;
+
+ if ((app.lcore_params[lcore].type != e_APP_LCORE_IO) ||
+ (lp_io->rx.n_nic_queues == 0)) {
+ continue;
+ }
+ count ++;
+ }
+ return count;
+}
+
+uint32_t
+app_get_lcores_worker(void)
+{
+ uint32_t lcore, count;
+
+ count = 0;
+ for (lcore = 0; lcore < APP_MAX_LCORES; lcore ++) {
+ if (app.lcore_params[lcore].type != e_APP_LCORE_WORKER) {
+ continue;
+ }
+
+ count ++;
+ }
+
+ if (count > APP_MAX_WORKER_LCORES) {
+ rte_panic("Algorithmic error (too many worker lcores)\n");
+ return 0;
+ }
+
+ return count;
+}
+
+void
+app_print_params(void)
+{
+ unsigned port, queue, lcore, i, j;
+
+ /* Print NIC RX configuration */
+ printf("NIC RX ports: ");
+ for (port = 0; port < APP_MAX_NIC_PORTS; port ++) {
+ uint32_t n_rx_queues = app_get_nic_rx_queues_per_port((uint8_t) port);
+
+ if (n_rx_queues == 0) {
+ continue;
+ }
+
+ printf("%u (", port);
+ for (queue = 0; queue < APP_MAX_RX_QUEUES_PER_NIC_PORT; queue ++) {
+ if (app.nic_rx_queue_mask[port][queue] == 1) {
+ printf("%u ", queue);
+ }
+ }
+ printf(") ");
+ }
+ printf(";\n");
+
+ /* Print I/O lcore RX params */
+ for (lcore = 0; lcore < APP_MAX_LCORES; lcore ++) {
+ struct app_lcore_params_io *lp = &app.lcore_params[lcore].io;
+
+ if ((app.lcore_params[lcore].type != e_APP_LCORE_IO) ||
+ (lp->rx.n_nic_queues == 0)) {
+ continue;
+ }
+
+ printf("I/O lcore %u (socket %u): ", lcore, rte_lcore_to_socket_id(lcore));
+
+ printf("RX ports ");
+ for (i = 0; i < lp->rx.n_nic_queues; i ++) {
+ printf("(%u, %u) ",
+ (unsigned) lp->rx.nic_queues[i].port,
+ (unsigned) lp->rx.nic_queues[i].queue);
+ }
+ printf("; ");
+
+ printf("Output rings ");
+ for (i = 0; i < lp->rx.n_rings; i ++) {
+ printf("%p ", lp->rx.rings[i]);
+ }
+ printf(";\n");
+ }
+
+ /* Print worker lcore RX params */
+ for (lcore = 0; lcore < APP_MAX_LCORES; lcore ++) {
+ struct app_lcore_params_worker *lp = &app.lcore_params[lcore].worker;
+
+ if (app.lcore_params[lcore].type != e_APP_LCORE_WORKER) {
+ continue;
+ }
+
+ printf("Worker lcore %u (socket %u) ID %u: ",
+ lcore,
+ rte_lcore_to_socket_id(lcore),
+ (unsigned)lp->worker_id);
+
+ printf("Input rings ");
+ for (i = 0; i < lp->n_rings_in; i ++) {
+ printf("%p ", lp->rings_in[i]);
+ }
+
+ printf(";\n");
+ }
+
+ printf("\n");
+
+ /* Print NIC TX configuration */
+ printf("NIC TX ports: ");
+ for (port = 0; port < APP_MAX_NIC_PORTS; port ++) {
+ if (app.nic_tx_port_mask[port] == 1) {
+ printf("%u ", port);
+ }
+ }
+ printf(";\n");
+
+ /* Print I/O TX lcore params */
+ for (lcore = 0; lcore < APP_MAX_LCORES; lcore ++) {
+ struct app_lcore_params_io *lp = &app.lcore_params[lcore].io;
+ uint32_t n_workers = app_get_lcores_worker();
+
+ if ((app.lcore_params[lcore].type != e_APP_LCORE_IO) ||
+ (lp->tx.n_nic_ports == 0)) {
+ continue;
+ }
+
+ printf("I/O lcore %u (socket %u): ", lcore, rte_lcore_to_socket_id(lcore));
+
+ printf("Input rings per TX port ");
+ for (i = 0; i < lp->tx.n_nic_ports; i ++) {
+ port = lp->tx.nic_ports[i];
+
+ printf("%u (", port);
+ for (j = 0; j < n_workers; j ++) {
+ printf("%p ", lp->tx.rings[port][j]);
+ }
+ printf(") ");
+
+ }
+
+ printf(";\n");
+ }
+
+ /* Print worker lcore TX params */
+ for (lcore = 0; lcore < APP_MAX_LCORES; lcore ++) {
+ struct app_lcore_params_worker *lp = &app.lcore_params[lcore].worker;
+
+ if (app.lcore_params[lcore].type != e_APP_LCORE_WORKER) {
+ continue;
+ }
+
+ printf("Worker lcore %u (socket %u) ID %u: \n",
+ lcore,
+ rte_lcore_to_socket_id(lcore),
+ (unsigned)lp->worker_id);
+
+ printf("Output rings per TX port ");
+ for (port = 0; port < APP_MAX_NIC_PORTS; port ++) {
+ if (lp->rings_out[port] != NULL) {
+ printf("%u (%p) ", port, lp->rings_out[port]);
+ }
+ }
+
+ printf(";\n");
+ }
+
+ /* Rings */
+ printf("Ring sizes: NIC RX = %u; Worker in = %u; Worker out = %u; NIC TX = %u;\n",
+ (unsigned) app.nic_rx_ring_size,
+ (unsigned) app.ring_rx_size,
+ (unsigned) app.ring_tx_size,
+ (unsigned) app.nic_tx_ring_size);
+
+ /* Bursts */
+ printf("Burst sizes: I/O RX (rd = %u, wr = %u); Worker (rd = %u, wr = %u); I/O TX (rd = %u, wr = %u)\n",
+ (unsigned) app.burst_size_io_rx_read,
+ (unsigned) app.burst_size_io_rx_write,
+ (unsigned) app.burst_size_worker_read,
+ (unsigned) app.burst_size_worker_write,
+ (unsigned) app.burst_size_io_tx_read,
+ (unsigned) app.burst_size_io_tx_write);
+}
diff --git a/logreader/dlogreader b/logreader/dlogreader
new file mode 100755
index 0000000..e447e21
--- /dev/null
+++ b/logreader/dlogreader
Binary files differ
diff --git a/logreader/main.c b/logreader/main.c
new file mode 100644
index 0000000..17d99e1
--- /dev/null
+++ b/logreader/main.c
@@ -0,0 +1,22 @@
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "nstat.h"
+
+const int __SERIAL_MULTIPROCESS_LOGREADER_VERSION_20141215__ = 0;
+
+extern int app_parse_args(int argc, char **argv);
+
+int main(int argc,char * argv[])
+{
+ app_parse_args(argc,argv);
+ nstat_init();
+ nstat_thread_entry();
+
+ nstat_destroy();
+ return 0;
+}
+
diff --git a/logreader/nstat.c b/logreader/nstat.c
new file mode 100644
index 0000000..a3e50f8
--- /dev/null
+++ b/logreader/nstat.c
@@ -0,0 +1,208 @@
+
+
+/* Stat Module in Serial-Multiprocess LogReader
+ Author : Lu Qiuwen <[email protected]>
+ Date : 2014-12-07
+
+*/
+
+
+#include <sys/mman.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+
+#include "nstat.h"
+#include <main.h>
+
+#define SHM_FILEMODE 00777
+
+struct nstat_handle * nstat_common_handle = NULL;
+struct nstat_handle * nstat_handle_last = NULL;
+struct stat_summerize_t * nstat_summerize = NULL;
+
+void nstat_summerize_loop(struct nstat_handle * handle_now, struct nstat_handle * handle_past);
+void nstat_print_loop(struct nstat_handle * handle_now, struct nstat_handle * handle_past, FILE * fstream);
+
+#define TBPS (1ull * 1000 * 1000 * 1000 * 1000)
+#define GBPS (1ull * 1000 * 1000 * 1000)
+#define MBPS (1ull * 1000 * 1000)
+#define KBPS (1ull * 1000)
+
+static void unit_translate(uint64_t number, float * f_number, char * unit)
+{
+ if(number > TBPS)
+ {
+ *f_number = number * 1.0 / TBPS;
+ *unit = 'T';
+ }
+ else if(number > GBPS)
+ {
+ *f_number = number * 1.0 / GBPS;
+ *unit = 'G';
+ }
+ else if(number > MBPS)
+ {
+ *f_number = number * 1.0 / MBPS;
+ *unit = 'M';
+ }
+ else if(number > KBPS)
+ {
+ *f_number = number * 1.0 / KBPS;
+ *unit = 'K';
+ }
+ else
+ {
+ *f_number = number * 1.0;
+ *unit = ' ';
+ }
+}
+
+int nstat_init()
+{
+ int shm_fd = shm_open(NSTAT_SHAREDMEMORY_SYMBOL, O_RDWR, SHM_FILEMODE);
+ ftruncate(shm_fd, sizeof(struct nstat_handle));
+
+ void * shm_ptr = mmap(NULL, sizeof(struct nstat_handle), PROT_READ,
+ MAP_SHARED, shm_fd, 0);
+ if(shm_ptr == NULL)
+ {
+ printf("cannot create nstat shared memory");
+ exit(1);
+ }
+
+ nstat_common_handle = (struct nstat_handle *) shm_ptr;
+ nstat_handle_last = (struct nstat_handle *)malloc(sizeof(struct nstat_handle));
+
+ memset(nstat_handle_last,0,sizeof(struct nstat_handle));
+ nstat_handle_last->stat_interval = app.statistics.sample_time;
+
+ return 0;
+}
+
+int nstat_destroy()
+{
+ free(nstat_handle_last);
+ free(nstat_summerize);
+ return shm_unlink(NSTAT_SHAREDMEMORY_SYMBOL);
+}
+
+void * nstat_thread_entry()
+{
+ if(!app.statistics.enable)
+ return (void *)0;
+
+ while(1)
+ {
+ sleep(app.statistics.sample_time);
+ nstat_print_loop(nstat_common_handle,nstat_handle_last,stdout);
+ memcpy(nstat_handle_last,nstat_common_handle,sizeof(struct nstat_handle));
+ }
+
+}
+
+void nstat_print_loop(struct nstat_handle * handle_now, struct nstat_handle * handle_past, FILE * fstream)
+{
+ uint64_t calibration;
+
+ calibration = handle_now->stat_interval;
+
+ const char clr[] = {27,'[','2','J','\0'};
+ const char topleft[] = {27,'[','1',';','1','H','\0'};
+
+ fprintf(fstream,"%s%s",clr,topleft);
+
+ fprintf(fstream,"--------------------------------------------------------------------------------------------------------------------------------------\n");
+ fprintf(fstream," Network Ports Statistics(LOGREADER) \n");
+ fprintf(fstream,"--------------------------------------------------------------------------------------------------------------------------------------\n");
+
+
+ for(int port_id = 0; port_id < APP_MAX_NIC_PORTS; port_id ++)
+ {
+ if((app.enabled_port_mask & (1 << port_id)) == 0)
+ continue;
+
+ uint64_t nic_rx_burst = (handle_now->port[port_id].rx_packets - handle_past->port[port_id].rx_packets) / calibration;
+ uint64_t nic_tx_burst = (handle_now->port[port_id].tx_packets - handle_past->port[port_id].tx_packets) / calibration;
+ uint64_t nic_rx_bytes = (handle_now->port[port_id].rx_bytes - handle_past->port[port_id].rx_bytes) / calibration;
+ uint64_t nic_tx_bytes = (handle_now->port[port_id].tx_bytes - handle_past->port[port_id].tx_bytes) / calibration;
+
+ float fps_rx,bps_rx,fps_tx,bps_tx;
+ char fps_rx_unit,bps_rx_unit,fps_tx_unit,bps_tx_unit;
+
+ unit_translate(nic_rx_burst, &fps_rx, &fps_rx_unit);
+ unit_translate(nic_tx_burst, &fps_tx, &fps_tx_unit);
+ unit_translate(nic_rx_bytes * 8, &bps_rx, &bps_rx_unit);
+ unit_translate(nic_tx_bytes * 8, &bps_tx, &bps_tx_unit);
+
+ fprintf(fstream,"Port %d\n",port_id);
+ fprintf(fstream,"RX: packets%20lu | bytes:%20lu | dropped %10lu | fps:%7.2f%c | bps: %7.2f%c\n",
+ handle_now->port[port_id].rx_packets, handle_now->port[port_id].rx_bytes,
+ handle_now->port[port_id].rx_drop_packets, fps_rx,fps_rx_unit,bps_rx,bps_rx_unit);
+ fprintf(fstream,"TX: packets%20lu | bytes:%20lu | dropped %10lu | fps:%7.2f%c | bps: %7.2f%c\n",
+ handle_now->port[port_id].tx_packets, handle_now->port[port_id].tx_packets,
+ handle_now->port[port_id].tx_drop_packets, fps_tx, fps_tx_unit, bps_tx, bps_tx_unit);
+ }
+
+ fprintf(fstream,"--------------------------------------------------------------------------------------------------------------------------------------\n");
+ fprintf(fstream," Input/Output(I/O) Statistics \n");
+ fprintf(fstream,"--------------------------------------------------------------------------------------------------------------------------------------\n");
+
+ for(int lcore_id = 0; lcore_id < APP_MAX_LCORES; lcore_id++)
+ {
+ if(app.lcore_params[lcore_id].type == e_APP_LCORE_IO)
+ {
+ uint64_t io_rx_burst = (handle_now->io_rx[lcore_id].packets - handle_past->io_rx[lcore_id].packets) / calibration;
+ uint64_t io_tx_burst = (handle_now->io_tx[lcore_id].packets - handle_past->io_tx[lcore_id].packets) / calibration;
+ uint64_t io_rx_bytes = (handle_now->io_rx[lcore_id].bytes - handle_past->io_rx[lcore_id].bytes) /calibration;
+ uint64_t io_tx_bytes = (handle_now->io_tx[lcore_id].bytes - handle_past->io_tx[lcore_id].bytes) /calibration;
+
+ float fps_rx,bps_rx,fps_tx,bps_tx;
+ char fps_rx_unit,bps_rx_unit,fps_tx_unit,bps_tx_unit;
+
+ unit_translate(io_rx_burst, &fps_rx, &fps_rx_unit);
+ unit_translate(io_tx_burst, &fps_tx, &fps_tx_unit);
+ unit_translate(io_rx_bytes * 8, &bps_rx, &bps_rx_unit);
+ unit_translate(io_tx_bytes * 8, &bps_tx, &bps_tx_unit);
+
+ fprintf(fstream,"Core %d\n",lcore_id);
+ fprintf(fstream,"RX: packets%20lu | bytes:%20lu | dropped %10lu | fps:%7.2f%c | bps: %7.2f%c\n",
+ handle_now->io_rx[lcore_id].packets , handle_now->io_rx[lcore_id].bytes,
+ handle_now->io_rx[lcore_id].dropped, fps_rx,fps_rx_unit,bps_rx,bps_rx_unit);
+ fprintf(fstream,"TX: packets%20lu | bytes:%20lu | dropped %10lu | fps:%7.2f%c | bps: %7.2f%c\n",
+ handle_now->io_tx[lcore_id].packets , handle_now->io_tx[lcore_id].bytes,
+ handle_now->io_tx[lcore_id].dropped, fps_tx,fps_tx_unit,bps_tx,bps_tx_unit);
+ }
+ }
+
+ fprintf(fstream,"--------------------------------------------------------------------------------------------------------------------------------------\n");
+ fprintf(fstream," Worker(Client Process) Statistics \n");
+ fprintf(fstream,"--------------------------------------------------------------------------------------------------------------------------------------\n");
+
+ for(int lcore_id = 0; lcore_id < APP_MAX_LCORES; lcore_id++)
+ {
+ if(app.lcore_params[lcore_id].type == e_APP_LCORE_WORKER)
+ {
+ uint64_t runtime_delta = handle_now->worker_stat[lcore_id].app_runtime - handle_past->worker_stat[lcore_id].app_runtime;
+ uint64_t cycle_delta = handle_now->worker_stat[lcore_id].app_cycles - handle_past->worker_stat[lcore_id].app_cycles;
+ float runtime_per_cycle = 0;
+
+ if(likely(cycle_delta != 0))
+ runtime_per_cycle = (float)runtime_delta / cycle_delta;
+ else
+ runtime_per_cycle = 0;
+
+ fprintf(fstream,"WORKER %2d | packets %20lu | bytes: %20lu | dropped %10lu | runtime %7.2f\n",
+ lcore_id,
+ handle_now->worker_stat[lcore_id].packets,
+ handle_now->worker_stat[lcore_id].bytes,
+ handle_now->worker_stat[lcore_id].dropped,
+ runtime_per_cycle);
+ }
+ }
+
+ fprintf(fstream,"--------------------------------------------------------------------------------------------------------------------------------------\n");
+ return;
+}
diff --git a/logreader/nstat.h b/logreader/nstat.h
new file mode 100644
index 0000000..6611495
--- /dev/null
+++ b/logreader/nstat.h
@@ -0,0 +1,72 @@
+
+#ifndef __SERIAL_MULTIPROCESS_NSTAT_SERVER_INCLUDE_H__
+#define __SERIAL_MULTIPROCESS_NSTAT_SERVER_INCLUDE_H__
+
+#include <rte_mbuf.h>
+#include <nstat_common.h>
+
+// Get the Pkts total length.
+static inline uint64_t nstat_pktslen(struct rte_mbuf ** mbufs, unsigned nb_mbufs)
+{
+ uint64_t datalen = 0;
+ for(int i = 0; i < nb_mbufs; i++)
+ {
+ datalen += mbufs[i]->pkt.pkt_len + APP_PKT_OVERHEAD;
+ }
+
+ return datalen;
+}
+
+static inline void nstat_port_count_rx(struct nstat_handle * handle, struct rte_mbuf ** mbufs, unsigned nb_mbufs, uint8_t port_id)
+{
+ handle->port[port_id].rx_packets += nb_mbufs;
+ handle->port[port_id].rx_bytes += nstat_pktslen(mbufs, nb_mbufs);
+ return;
+}
+
+static inline void nstat_port_count_tx(struct nstat_handle * handle, struct rte_mbuf ** mbufs, unsigned nb_mbufs, uint8_t port_id)
+{
+ handle->port[port_id].tx_packets += nb_mbufs;
+ handle->port[port_id].tx_bytes += nstat_pktslen(mbufs, nb_mbufs);
+ return;
+}
+
+static inline void nstat_port_count_remove_tx(struct nstat_handle * handle, struct rte_mbuf ** mbufs, unsigned nb_mbufs, uint8_t port_id)
+{
+ handle->port[port_id].tx_packets -= nb_mbufs;
+ handle->port[port_id].tx_bytes -= nstat_pktslen(mbufs, nb_mbufs);
+ handle->port[port_id].tx_drop_packets += nb_mbufs;
+ return;
+}
+
+static inline void nstat_io_count_rx(struct nstat_handle * handle, struct rte_mbuf ** mbufs, unsigned nb_mbufs, uint8_t lcore_id)
+{
+ handle->io_rx[lcore_id].packets += nb_mbufs;
+ handle->io_rx[lcore_id].bytes += nstat_pktslen(mbufs,nb_mbufs);
+ return;
+}
+
+static inline void nstat_io_count_tx(struct nstat_handle * handle, struct rte_mbuf ** mbufs, unsigned nb_mbufs, uint8_t lcore_id)
+{
+ handle->io_tx[lcore_id].packets += nb_mbufs;
+ handle->io_tx[lcore_id].bytes += nstat_pktslen(mbufs,nb_mbufs);
+ return;
+}
+
+static inline void nstat_io_drop_rx(struct nstat_handle * handle, struct rte_mbuf ** mbufs, unsigned nb_mbufs, uint8_t lcore_id)
+{
+ handle->io_rx[lcore_id].dropped += nb_mbufs;
+ return;
+}
+
+static inline void nstat_io_drop_tx(struct nstat_handle * handle, struct rte_mbuf ** mbufs, unsigned nb_mbufs, uint8_t lcore_id)
+{
+ handle->io_tx[lcore_id].dropped += nb_mbufs;
+ return;
+}
+
+int nstat_init();
+int nstat_destroy();
+void * nstat_thread_entry();
+
+#endif