summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <[email protected]>2015-06-09 09:33:14 +0800
committerroot <[email protected]>2015-06-09 09:33:14 +0800
commit93813867177d2c5eba1d673875663b546ff50773 (patch)
tree6976a9227a5762d3326ce7560fcb22337dbb248d
parent63cf4fd76e4faaefff7bbf5da6cc8e2d702ae007 (diff)
改进统计模块,同一网卡端口计数采用原子操作进行,提高计数精确度,该特性由USE_ATOMIC_STAT控制。20150609
-rw-r--r--driver/nstat.c35
-rw-r--r--driver/nstat.h18
-rw-r--r--driver/runtime.c22
-rw-r--r--include/serial/nstat_common.h16
-rw-r--r--include/serial/sw_config.h16
-rw-r--r--logreader/dlogreader/nstat.c30
-rw-r--r--logreader/dlogreader/nstat.h18
7 files changed, 137 insertions, 18 deletions
diff --git a/driver/nstat.c b/driver/nstat.c
index 6533c21..ec0dc7d 100644
--- a/driver/nstat.c
+++ b/driver/nstat.c
@@ -152,8 +152,13 @@ void nstat_summerize_loop(struct nstat_handle * handle_now, struct nstat_handle
{
if(app.enabled_port_mask & (1 << port_id) == 0)
continue;
+#if USE_ATOMIC_STAT
+ nstat_summerize->dropped += rte_atomic64_read(&(handle_now->port[port_id].rx_drop_packets));
+ nstat_summerize->dropped += rte_atomic64_read(&(handle_now->port[port_id].tx_drop_packets));
+#else
nstat_summerize->dropped += handle_now->port[port_id].rx_drop_packets;
nstat_summerize->dropped += handle_now->port[port_id].tx_drop_packets;
+#endif
}
for(int lcore_id = 0; lcore_id < APP_MAX_LCORES; lcore_id++)
@@ -218,11 +223,31 @@ void nstat_print_loop(struct nstat_handle * handle_now, struct nstat_handle * ha
{
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;
+#if USE_ATOMIC_STAT
+ uint64_t port_rx_packets = rte_atomic64_read(&(handle_now->port[port_id].rx_packets));
+ uint64_t port_tx_packets = rte_atomic64_read(&(handle_now->port[port_id].tx_packets));
+ uint64_t port_rx_bytes = rte_atomic64_read(&(handle_now->port[port_id].rx_bytes));
+ uint64_t port_tx_bytes = rte_atomic64_read(&(handle_now->port[port_id].tx_bytes));
+
+ uint64_t past_port_rx_packets = rte_atomic64_read(&(handle_past->port[port_id].rx_packets));
+ uint64_t past_port_tx_packets = rte_atomic64_read(&(handle_past->port[port_id].tx_packets));
+ uint64_t past_port_rx_bytes = rte_atomic64_read(&(handle_past->port[port_id].rx_bytes));
+ uint64_t past_port_tx_bytes = rte_atomic64_read(&(handle_past->port[port_id].tx_bytes));
+#else
+ uint64_t port_rx_packets = handle_now->port[port_id].rx_packets;
+ uint64_t port_tx_packets = handle_now->port[port_id].tx_packets;
+ uint64_t port_rx_bytes = handle_now->port[port_id].rx_bytes;
+ uint64_t port_tx_bytes = handle_now->port[port_id].tx_bytes;
+
+ uint64_t past_port_rx_packets = handle_past->port[port_id].rx_packets;
+ uint64_t past_port_tx_packets = handle_past->port[port_id].tx_packets;
+ uint64_t past_port_rx_bytes = handle_past->port[port_id].rx_bytes;
+ uint64_t past_port_tx_bytes = handle_past->port[port_id].tx_bytes;
+#endif
+ uint64_t nic_rx_burst = (port_rx_packets - past_port_rx_packets) / calibration;
+ uint64_t nic_tx_burst = (port_tx_packets - past_port_tx_packets) / calibration;
+ uint64_t nic_rx_bytes = (port_rx_bytes - past_port_rx_bytes) / calibration;
+ uint64_t nic_tx_bytes = (port_tx_bytes - past_port_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;
diff --git a/driver/nstat.h b/driver/nstat.h
index ff544b0..8f6c810 100644
--- a/driver/nstat.h
+++ b/driver/nstat.h
@@ -4,7 +4,9 @@
#include <rte_mbuf.h>
#include <rte_version.h>
+#include <rte_atomic.h>
#include <nstat_common.h>
+#include <sw_config.h>
// Get the Pkts total length.
static inline uint64_t nstat_pktslen(struct rte_mbuf ** mbufs, unsigned nb_mbufs)
@@ -24,23 +26,39 @@ static inline uint64_t nstat_pktslen(struct rte_mbuf ** mbufs, unsigned nb_mbufs
static inline void nstat_port_count_rx(struct nstat_handle * handle, struct rte_mbuf ** mbufs, unsigned nb_mbufs, uint8_t port_id)
{
+#if USE_ATOMIC_STAT
+ rte_atomic64_add(&(handle->port[port_id].rx_packets),nb_mbufs);
+ rte_atomic64_add(&(handle->port[port_id].rx_bytes),nstat_pktslen(mbufs, nb_mbufs));
+#else
handle->port[port_id].rx_packets += nb_mbufs;
handle->port[port_id].rx_bytes += nstat_pktslen(mbufs, nb_mbufs);
+#endif
return;
}
static inline void nstat_port_count_tx(struct nstat_handle * handle, struct rte_mbuf ** mbufs, unsigned nb_mbufs, uint8_t port_id)
{
+#if USE_ATOMIC_STAT
+ rte_atomic64_add(&(handle->port[port_id].tx_packets),nb_mbufs);
+ rte_atomic64_add(&(handle->port[port_id].tx_bytes),nstat_pktslen(mbufs, nb_mbufs));
+#else
handle->port[port_id].tx_packets += nb_mbufs;
handle->port[port_id].tx_bytes += nstat_pktslen(mbufs, nb_mbufs);
+#endif
return;
}
static inline void nstat_port_count_remove_tx(struct nstat_handle * handle, struct rte_mbuf ** mbufs, unsigned nb_mbufs, uint8_t port_id)
{
+#if USE_ATOMIC_STAT
+ rte_atomic64_sub(&(handle->port[port_id].tx_packets),nb_mbufs);
+ rte_atomic64_sub(&(handle->port[port_id].tx_bytes),nstat_pktslen(mbufs,nb_mbufs));
+ rte_atomic64_add(&(handle->port[port_id].tx_drop_packets),nb_mbufs);
+#else
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;
+#endif
return;
}
diff --git a/driver/runtime.c b/driver/runtime.c
index 461e1c8..9622e61 100644
--- a/driver/runtime.c
+++ b/driver/runtime.c
@@ -86,7 +86,15 @@
#include "nstat.h"
#include "layer.h"
-static inline __attribute__((always_inline))
+#define USE_FUNCTION_INLINE 0
+
+#if USE_FUNCTION_INLINE
+#define INLINE inline __attribute__((always_inline))
+#else
+#define INLINE
+#endif
+
+static INLINE
int get_hash_result(struct rte_mbuf * mbuf, uint8_t *data, uint32_t *hash_value)
{
uint16_t protrol_type = 0;
@@ -163,7 +171,7 @@ int get_hash_result(struct rte_mbuf * mbuf, uint8_t *data, uint32_t *hash_value)
return 0;
}
-static inline __attribute__((always_inline))
+static INLINE
void app_lcore_io_rx_buffer_to_send (
struct app_lcore_params_io *lp,
uint32_t worker,
@@ -219,7 +227,7 @@ void app_lcore_io_rx_buffer_to_send (
lp->rx.mbuf_out_flush[worker] = 0;
}
-static inline __attribute__((always_inline))
+static INLINE
void app_lcore_io_rx(
struct app_lcore_params_io *lp,
uint32_t n_workers,
@@ -338,7 +346,7 @@ void app_lcore_io_rx(
}
}
-static inline __attribute__((always_inline))
+static INLINE
void app_lcore_io_rx_flush(struct app_lcore_params_io *lp, uint32_t n_workers)
{
uint32_t worker;
@@ -355,7 +363,7 @@ void app_lcore_io_rx_flush(struct app_lcore_params_io *lp, uint32_t n_workers)
#if USE_RING_BURST
- ret = rte_ring_enqueue_burst(lp->rx.rings[worker], (void **) lp->rx.mbuf_out[worker].array,
+ ret = rte_ring_sp_enqueue_burst(lp->rx.rings[worker], (void **) lp->rx.mbuf_out[worker].array,
lp->rx.mbuf_out[worker].n_mbufs);
if(unlikely(ret < lp->rx.mbuf_out[worker].n_mbufs))
@@ -393,7 +401,7 @@ void app_lcore_io_rx_flush(struct app_lcore_params_io *lp, uint32_t n_workers)
/* Lu Qiuwen<[email protected]>, at 2014-12-04 */
/* Modified from DPDK 1.7.1 examples/load_balancer/runtime.c */
-static inline __attribute__((always_inline))
+static INLINE
void app_lcore_io_tx(
struct app_lcore_params_io *lp,
uint32_t n_workers,
@@ -479,7 +487,7 @@ void app_lcore_io_tx(
}
}
-static inline __attribute__((always_inline))
+static INLINE
void app_lcore_io_tx_flush(struct app_lcore_params_io *lp)
{
uint8_t port;
diff --git a/include/serial/nstat_common.h b/include/serial/nstat_common.h
index dcaa01a..5ae2bb3 100644
--- a/include/serial/nstat_common.h
+++ b/include/serial/nstat_common.h
@@ -7,6 +7,7 @@
#include <rte_atomic.h>
#include <rte_rwlock.h>
#include <rte_ethdev.h>
+#include <sw_config.h>
#include "main.h"
#ifndef NSTAT_SHAREDMEMORY_SYMBOL
@@ -21,6 +22,19 @@
#define NSTAT_SHAREMEMORY_ETHSTAT_SYMBOL "serial_multiprocess_nstat_ethstat_20150511"
#endif
+#if USE_ATOMIC_STAT
+struct port_stat_t
+{
+ rte_atomic64_t rx_packets;
+ rte_atomic64_t rx_bytes;
+ rte_atomic64_t tx_packets;
+ rte_atomic64_t tx_bytes;
+
+ rte_atomic64_t rx_drop_packets;
+ rte_atomic64_t tx_drop_packets;
+
+} __rte_cache_aligned;
+#else
struct port_stat_t
{
uint64_t rx_packets;
@@ -32,7 +46,7 @@ struct port_stat_t
uint64_t tx_drop_packets;
} __rte_cache_aligned;
-
+#endif
struct lcore_stat_t
{
diff --git a/include/serial/sw_config.h b/include/serial/sw_config.h
new file mode 100644
index 0000000..2413ce0
--- /dev/null
+++ b/include/serial/sw_config.h
@@ -0,0 +1,16 @@
+
+#ifndef __SW_CONFIG_INCLUDE_H__
+#define __SW_CONFIG_INCLUDE_H__
+
+
+/* Use the atomic operation to manipulate the
+ * stat variable */
+
+#ifndef USE_ATOMIC_STAT
+#define USE_ATOMIC_STAT 1
+#endif
+
+
+
+
+#endif
diff --git a/logreader/dlogreader/nstat.c b/logreader/dlogreader/nstat.c
index a3e50f8..f74fccb 100644
--- a/logreader/dlogreader/nstat.c
+++ b/logreader/dlogreader/nstat.c
@@ -123,11 +123,31 @@ void nstat_print_loop(struct nstat_handle * handle_now, struct nstat_handle * ha
{
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;
+#if USE_ATOMIC_STAT
+ uint64_t port_rx_packets = rte_atomic64_read(&(handle_now->port[port_id].rx_packets));
+ uint64_t port_tx_packets = rte_atomic64_read(&(handle_now->port[port_id].tx_packets));
+ uint64_t port_rx_bytes = rte_atomic64_read(&(handle_now->port[port_id].rx_bytes));
+ uint64_t port_tx_bytes = rte_atomic64_read(&(handle_now->port[port_id].tx_bytes));
+
+ uint64_t past_port_rx_packets = rte_atomic64_read(&(handle_past->port[port_id].rx_packets));
+ uint64_t past_port_tx_packets = rte_atomic64_read(&(handle_past->port[port_id].tx_packets));
+ uint64_t past_port_rx_bytes = rte_atomic64_read(&(handle_past->port[port_id].rx_bytes));
+ uint64_t past_port_tx_bytes = rte_atomic64_read(&(handle_past->port[port_id].tx_bytes));
+#else
+ uint64_t port_rx_packets = handle_now->port[port_id].rx_packets;
+ uint64_t port_tx_packets = handle_now->port[port_id].tx_packets;
+ uint64_t port_rx_bytes = handle_now->port[port_id].rx_bytes;
+ uint64_t port_tx_bytes = handle_now->port[port_id].tx_bytes;
+
+ uint64_t past_port_rx_packets = handle_past->port[port_id].rx_packets;
+ uint64_t past_port_tx_packets = handle_past->port[port_id].tx_packets;
+ uint64_t past_port_rx_bytes = handle_past->port[port_id].rx_bytes;
+ uint64_t past_port_tx_bytes = handle_past->port[port_id].tx_bytes;
+#endif
+ uint64_t nic_rx_burst = (port_rx_packets - past_port_rx_packets) / calibration;
+ uint64_t nic_tx_burst = (port_tx_packets - past_port_tx_packets) / calibration;
+ uint64_t nic_rx_bytes = (port_rx_bytes - past_port_rx_bytes) / calibration;
+ uint64_t nic_tx_bytes = (port_tx_bytes - past_port_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;
diff --git a/logreader/dlogreader/nstat.h b/logreader/dlogreader/nstat.h
index ff544b0..8f6c810 100644
--- a/logreader/dlogreader/nstat.h
+++ b/logreader/dlogreader/nstat.h
@@ -4,7 +4,9 @@
#include <rte_mbuf.h>
#include <rte_version.h>
+#include <rte_atomic.h>
#include <nstat_common.h>
+#include <sw_config.h>
// Get the Pkts total length.
static inline uint64_t nstat_pktslen(struct rte_mbuf ** mbufs, unsigned nb_mbufs)
@@ -24,23 +26,39 @@ static inline uint64_t nstat_pktslen(struct rte_mbuf ** mbufs, unsigned nb_mbufs
static inline void nstat_port_count_rx(struct nstat_handle * handle, struct rte_mbuf ** mbufs, unsigned nb_mbufs, uint8_t port_id)
{
+#if USE_ATOMIC_STAT
+ rte_atomic64_add(&(handle->port[port_id].rx_packets),nb_mbufs);
+ rte_atomic64_add(&(handle->port[port_id].rx_bytes),nstat_pktslen(mbufs, nb_mbufs));
+#else
handle->port[port_id].rx_packets += nb_mbufs;
handle->port[port_id].rx_bytes += nstat_pktslen(mbufs, nb_mbufs);
+#endif
return;
}
static inline void nstat_port_count_tx(struct nstat_handle * handle, struct rte_mbuf ** mbufs, unsigned nb_mbufs, uint8_t port_id)
{
+#if USE_ATOMIC_STAT
+ rte_atomic64_add(&(handle->port[port_id].tx_packets),nb_mbufs);
+ rte_atomic64_add(&(handle->port[port_id].tx_bytes),nstat_pktslen(mbufs, nb_mbufs));
+#else
handle->port[port_id].tx_packets += nb_mbufs;
handle->port[port_id].tx_bytes += nstat_pktslen(mbufs, nb_mbufs);
+#endif
return;
}
static inline void nstat_port_count_remove_tx(struct nstat_handle * handle, struct rte_mbuf ** mbufs, unsigned nb_mbufs, uint8_t port_id)
{
+#if USE_ATOMIC_STAT
+ rte_atomic64_sub(&(handle->port[port_id].tx_packets),nb_mbufs);
+ rte_atomic64_sub(&(handle->port[port_id].tx_bytes),nstat_pktslen(mbufs,nb_mbufs));
+ rte_atomic64_add(&(handle->port[port_id].tx_drop_packets),nb_mbufs);
+#else
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;
+#endif
return;
}