summaryrefslogtreecommitdiffstats
path: root/src/stateless/cp
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-10-11 14:42:24 +0200
committerimarom <imarom@cisco.com>2015-10-11 14:42:24 +0200
commit6c7880b9881ed6690954f0c29259dd0b584b3970 (patch)
treef8d23267dc0e086f1c622418e8bf68a04d38e64d /src/stateless/cp
parent3b827c9584c28d3f1f573e372f646edfe9f5f007 (diff)
DP cores now inject a single packet as a dummy to see stats
Diffstat (limited to 'src/stateless/cp')
-rw-r--r--src/stateless/cp/trex_stateless.cpp14
-rw-r--r--src/stateless/cp/trex_stateless.h4
-rw-r--r--src/stateless/cp/trex_stateless_port.cpp77
-rw-r--r--src/stateless/cp/trex_stateless_port.h34
4 files changed, 105 insertions, 24 deletions
diff --git a/src/stateless/cp/trex_stateless.cpp b/src/stateless/cp/trex_stateless.cpp
index 20e001c9..72762e26 100644
--- a/src/stateless/cp/trex_stateless.cpp
+++ b/src/stateless/cp/trex_stateless.cpp
@@ -50,7 +50,9 @@ void TrexStateless::configure(const TrexStatelessCfg &cfg) {
}
/* create RPC servers */
- instance.m_rpc_server = new TrexRpcServer(cfg.m_rpc_req_resp_cfg, cfg.m_rpc_async_cfg);
+
+ /* set both servers to mutex each other */
+ instance.m_rpc_server = new TrexRpcServer(cfg.m_rpc_req_resp_cfg, cfg.m_rpc_async_cfg, &instance.m_global_cp_lock);
instance.m_rpc_server->set_verbose(cfg.m_rpc_server_verbose);
/* configure ports */
@@ -152,12 +154,10 @@ TrexStateless::get_dp_core_count() {
void
TrexStateless::update_stats() {
- /* update CPU util. */
- #ifdef TREX_RPC_MOCK_SERVER
- m_stats.m_stats.m_cpu_util = 0;
- #else
- m_stats.m_stats.m_cpu_util = 0;
- #endif
+ /* update CPU util.
+ TODO
+ */
+ m_stats.m_stats.m_cpu_util = 0;
/* for every port update and accumulate */
for (uint8_t i = 0; i < m_port_count; i++) {
diff --git a/src/stateless/cp/trex_stateless.h b/src/stateless/cp/trex_stateless.h
index ef612e84..649b25dd 100644
--- a/src/stateless/cp/trex_stateless.h
+++ b/src/stateless/cp/trex_stateless.h
@@ -25,6 +25,8 @@ limitations under the License.
#include <string>
#include <stdexcept>
+#include <mutex>
+
#include <trex_stream.h>
#include <trex_stateless_port.h>
#include <trex_stateless_dp_core.h>
@@ -192,6 +194,8 @@ protected:
/* stats */
TrexStatelessStats m_stats;
+
+ std::mutex m_global_cp_lock;
};
#endif /* __TREX_STATELESS_H__ */
diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp
index 240b7582..f745bee9 100644
--- a/src/stateless/cp/trex_stateless_port.cpp
+++ b/src/stateless/cp/trex_stateless_port.cpp
@@ -28,6 +28,7 @@ limitations under the License.
// DPDK c++ issue
#include <rte_ethdev.h>
+#include <os_time.h>
using namespace std;
@@ -133,28 +134,23 @@ TrexStatelessPort::generate_handler() {
*/
void
TrexStatelessPort::update_stats() {
- #ifdef TREX_RPC_MOCK_SERVER
- /* do lies - its a mock */
- m_stats.m_stats.m_tx_bps = rand() % 10000;
- m_stats.m_stats.m_rx_bps = rand() % 10000;
+ struct rte_eth_stats stats;
+ rte_eth_stats_get(m_port_id, &stats);
- m_stats.m_stats.m_tx_pps = m_stats.m_stats.m_tx_bps / (64 + rand() % 1000);
- m_stats.m_stats.m_rx_pps = m_stats.m_stats.m_rx_bps / (64 + rand() % 1000);
+ /* copy straight values */
+ m_stats.m_stats.m_total_tx_bytes = stats.obytes;
+ m_stats.m_stats.m_total_rx_bytes = stats.ibytes;
+ m_stats.m_stats.m_total_tx_pkts = stats.opackets;
+ m_stats.m_stats.m_total_rx_pkts = stats.ipackets;
- m_stats.m_stats.m_total_tx_bytes += m_stats.m_stats.m_tx_bps;
- m_stats.m_stats.m_total_rx_bytes += m_stats.m_stats.m_rx_bps;
+ /* calculate stats */
+ m_stats.m_stats.m_tx_bps = m_stats.m_bw_tx_bps.add(stats.obytes);
+ m_stats.m_stats.m_rx_bps = m_stats.m_bw_rx_bps.add(stats.ibytes);
- m_stats.m_stats.m_total_tx_pkts += m_stats.m_stats.m_tx_pps;
- m_stats.m_stats.m_total_rx_pkts += m_stats.m_stats.m_rx_pps;
+ m_stats.m_stats.m_tx_pps = m_stats.m_bw_tx_pps.add(stats.opackets);
+ m_stats.m_stats.m_rx_pps = m_stats.m_bw_rx_pps.add(stats.ipackets);
- #else
- /* real update work */
- struct rte_eth_stats stats;
- rte_eth_stats_get(m_port_id, &stats);
- printf("ipackets is %u\n", stats.ipackets);
- printf("opackets is %u\n", stats.opackets);
- #endif
}
const TrexPortStats &
@@ -181,3 +177,50 @@ TrexStatelessPort::encode_stats(Json::Value &port) {
}
+
+/***************************
+ * BW measurement
+ *
+ **************************/
+/* TODO: move this to a common place */
+BWMeasure::BWMeasure() {
+ reset();
+}
+
+void BWMeasure::reset(void) {
+ m_start=false;
+ m_last_time_msec=0;
+ m_last_bytes=0;
+ m_last_result=0.0;
+};
+
+double BWMeasure::calc_MBsec(uint32_t dtime_msec,
+ uint64_t dbytes){
+ double rate=0.000008*( ( (double)dbytes*(double)os_get_time_freq())/((double)dtime_msec) );
+ return(rate);
+}
+
+double BWMeasure::add(uint64_t size) {
+ if ( false == m_start ) {
+ m_start=true;
+ m_last_time_msec = os_get_time_msec() ;
+ m_last_bytes=size;
+ return(0.0);
+ }
+
+ uint32_t ctime=os_get_time_msec();
+ if ((ctime - m_last_time_msec) <os_get_time_freq() ) {
+ return(m_last_result);
+ }
+
+ uint32_t dtime_msec = ctime-m_last_time_msec;
+ uint64_t dbytes = size - m_last_bytes;
+
+ m_last_time_msec = ctime;
+ m_last_bytes = size;
+
+ m_last_result= 0.5*calc_MBsec(dtime_msec,dbytes) +0.5*(m_last_result);
+ return( m_last_result );
+}
+
+
diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h
index a19fd981..428d5aee 100644
--- a/src/stateless/cp/trex_stateless_port.h
+++ b/src/stateless/cp/trex_stateless_port.h
@@ -24,6 +24,27 @@ limitations under the License.
#include <trex_stream.h>
/**
+ * bandwidth measurement class
+ *
+ */
+class BWMeasure {
+public:
+ BWMeasure();
+ void reset(void);
+ double add(uint64_t size);
+
+private:
+ double calc_MBsec(uint32_t dtime_msec,
+ uint64_t dbytes);
+
+public:
+ bool m_start;
+ uint32_t m_last_time_msec;
+ uint64_t m_last_bytes;
+ double m_last_result;
+};
+
+/**
* TRex stateless port stats
*
* @author imarom (24-Sep-15)
@@ -33,9 +54,22 @@ class TrexPortStats {
public:
TrexPortStats() {
m_stats = {0};
+
+ m_bw_tx_bps.reset();
+ m_bw_rx_bps.reset();
+
+ m_bw_tx_pps.reset();
+ m_bw_rx_pps.reset();
}
public:
+
+ BWMeasure m_bw_tx_bps;
+ BWMeasure m_bw_rx_bps;
+
+ BWMeasure m_bw_tx_pps;
+ BWMeasure m_bw_rx_pps;
+
struct {
double m_tx_bps;