diff options
-rw-r--r-- | src/debug.cpp | 12 | ||||
-rw-r--r-- | src/flow_stat.cpp | 18 | ||||
-rw-r--r-- | src/flow_stat.h | 11 | ||||
-rw-r--r-- | src/internal_api/trex_platform_api.h | 6 | ||||
-rw-r--r-- | src/main_dpdk.cpp | 21 | ||||
-rw-r--r-- | src/main_dpdk.h | 5 |
6 files changed, 44 insertions, 29 deletions
diff --git a/src/debug.cpp b/src/debug.cpp index 902766a1..656549dc 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -415,11 +415,17 @@ int CTrexDebug::test_send(uint pkt_type) { lp->dump_stats_extended(stdout); } for (port_id = 0; port_id < m_max_ports; port_id++) { - uint64_t fdir_stat[MAX_FLOW_STATS]; + rx_per_flow_t fdir_stat[MAX_FLOW_STATS]; + uint64_t fdir_stat_64[MAX_FLOW_STATS]; CPhyEthIF *lp = &m_ports[port_id]; - if (lp->get_flow_stats(fdir_stat, NULL, 0, MAX_FLOW_STATS, false) == 0) - rte_stat_dump_array(fdir_stat, "FDIR stat", MAX_FLOW_STATS); + if (lp->get_flow_stats(fdir_stat, NULL, 0, MAX_FLOW_STATS, false) == 0) { + for (int i = 0; i < MAX_FLOW_STATS; i++) { + fdir_stat_64[i] = fdir_stat[i].get_pkts(); + } + rte_stat_dump_array(fdir_stat_64, "FDIR stat", MAX_FLOW_STATS); + } } + return (0); } diff --git a/src/flow_stat.cpp b/src/flow_stat.cpp index f03065d2..01038292 100644 --- a/src/flow_stat.cpp +++ b/src/flow_stat.cpp @@ -121,7 +121,7 @@ void CFlowStatUserIdInfo::reset_hw_id() { // Next session will start counting from 0. for (int i = 0; i < TREX_MAX_PORTS; i++) { m_rx_counter_base[i] += m_rx_counter[i]; - m_rx_counter[i] = 0; + memset(&m_rx_counter[i], 0, sizeof(m_rx_counter[0])); m_tx_counter_base[i] += m_tx_counter[i]; memset(&m_tx_counter[i], 0, sizeof(m_tx_counter[0])); } @@ -590,7 +590,7 @@ int CFlowStatRuleMgr::stop_stream(const TrexStream * stream) { // update counters, and reset before unmapping CFlowStatUserIdInfo *p_user_id = m_user_id_map.find_user_id(m_hw_id_map.get_user_id(hw_id)); assert(p_user_id != NULL); - uint64_t rx_counter; + rx_per_flow_t rx_counter; tx_per_flow_t tx_counter; for (uint8_t port = 0; port < m_num_ports; port++) { m_api->del_rx_flow_stat_rule(port, FLOW_STAT_RULE_TYPE_IPV4_ID, proto, hw_id); @@ -620,7 +620,7 @@ int CFlowStatRuleMgr::get_active_pgids(flow_stat_active_t &result) { // return false if no counters changed since last run. true otherwise bool CFlowStatRuleMgr::dump_json(std::string & json, bool baseline) { - uint64_t rx_stats[MAX_FLOW_STATS]; + rx_per_flow_t rx_stats[MAX_FLOW_STATS]; tx_per_flow_t tx_stats[MAX_FLOW_STATS]; Json::FastWriter writer; Json::Value root; @@ -645,15 +645,16 @@ bool CFlowStatRuleMgr::dump_json(std::string & json, bool baseline) { for (uint8_t port = 0; port < m_num_ports; port++) { m_api->get_flow_stats(port, rx_stats, (void *)tx_stats, 0, m_max_hw_id, false); for (int i = 0; i <= m_max_hw_id; i++) { - if (rx_stats[i] != 0) { + if (rx_stats[i].get_pkts() != 0) { + rx_per_flow_t rx_pkts = rx_stats[i]; CFlowStatUserIdInfo *p_user_id = m_user_id_map.find_user_id(m_hw_id_map.get_user_id(i)); if (likely(p_user_id != NULL)) { - if (p_user_id->get_rx_counter(port) != rx_stats[i]) { - p_user_id->set_rx_counter(port, rx_stats[i]); + if (p_user_id->get_rx_counter(port) != rx_pkts) { + p_user_id->set_rx_counter(port, rx_pkts); p_user_id->set_need_to_send_rx(port); } } else { - std::cerr << __METHOD_NAME__ << i << ":Could not count " << rx_stats[i] << " rx packets, on port " + std::cerr << __METHOD_NAME__ << i << ":Could not count " << rx_pkts << " rx packets, on port " << (uint16_t)port << ", because no mapping was found." << std::endl; } } @@ -690,7 +691,8 @@ bool CFlowStatRuleMgr::dump_json(std::string & json, bool baseline) { std::string str_port = static_cast<std::ostringstream*>( &(std::ostringstream() << int(port) ) )->str(); if (user_id_info->need_to_send_rx(port) || baseline) { user_id_info->set_no_need_to_send_rx(port); - data_section[str_user_id]["rx_pkts"][str_port] = Json::Value::UInt64(user_id_info->get_rx_counter(port)); + data_section[str_user_id]["rx_pkts"][str_port] = Json::Value::UInt64(user_id_info->get_rx_counter(port).get_pkts()); + data_section[str_user_id]["rx_bytes"][str_port] = Json::Value::UInt64(user_id_info->get_rx_counter(port).get_bytes()); send_empty = false; } if (user_id_info->need_to_send_tx(port) || baseline) { diff --git a/src/flow_stat.h b/src/flow_stat.h index 3e00a180..0fb4fede 100644 --- a/src/flow_stat.h +++ b/src/flow_stat.h @@ -50,7 +50,7 @@ class tx_per_flow_t_ { inline void set_bytes(uint64_t bytes) { m_bytes = bytes;; } - inline void get_pkts(uint64_t pkts) { + inline void set_pkts(uint64_t pkts) { m_pkts = pkts; } inline void add_bytes(uint64_t bytes) { @@ -100,6 +100,7 @@ class tx_per_flow_t_ { }; typedef class tx_per_flow_t_ tx_per_flow_t; +typedef class tx_per_flow_t_ rx_per_flow_t; class CPhyEthIF; class Cxl710Parser; @@ -108,8 +109,8 @@ class CFlowStatUserIdInfo { public: CFlowStatUserIdInfo(uint8_t proto); friend std::ostream& operator<<(std::ostream& os, const CFlowStatUserIdInfo& cf); - void set_rx_counter(uint8_t port, uint64_t val) {m_rx_counter[port] = val;} - uint64_t get_rx_counter(uint8_t port) {return m_rx_counter[port] + m_rx_counter_base[port];} + void set_rx_counter(uint8_t port, rx_per_flow_t val) {m_rx_counter[port] = val;} + rx_per_flow_t get_rx_counter(uint8_t port) {return m_rx_counter[port] + m_rx_counter_base[port];} void set_tx_counter(uint8_t port, tx_per_flow_t val) {m_tx_counter[port] = val;} tx_per_flow_t get_tx_counter(uint8_t port) {return m_tx_counter[port] + m_tx_counter_base[port];} void set_hw_id(uint16_t hw_id) {m_hw_id = hw_id;} @@ -135,9 +136,9 @@ class CFlowStatUserIdInfo { private: bool m_rx_changed[TREX_MAX_PORTS]; // Which RX counters changed since we last published bool m_tx_changed[TREX_MAX_PORTS]; // Which TX counters changed since we last published - uint64_t m_rx_counter[TREX_MAX_PORTS]; // How many packets received with this user id since stream start + rx_per_flow_t m_rx_counter[TREX_MAX_PORTS]; // How many packets received with this user id since stream start // How many packets received with this user id, since stream creation, before stream start. - uint64_t m_rx_counter_base[TREX_MAX_PORTS]; + rx_per_flow_t m_rx_counter_base[TREX_MAX_PORTS]; tx_per_flow_t m_tx_counter[TREX_MAX_PORTS]; // How many packets transmitted with this user id since stream start // How many packets transmitted with this user id, since stream creation, before stream start. tx_per_flow_t m_tx_counter_base[TREX_MAX_PORTS]; diff --git a/src/internal_api/trex_platform_api.h b/src/internal_api/trex_platform_api.h index f8f76584..fc5da491 100644 --- a/src/internal_api/trex_platform_api.h +++ b/src/internal_api/trex_platform_api.h @@ -142,7 +142,7 @@ public: virtual void publish_async_data_now(uint32_t key, bool baseline) const = 0; virtual uint8_t get_dp_core_count() const = 0; virtual void get_interface_stat_info(uint8_t interface_id, uint16_t &num_counters, uint16_t &capabilities) const =0; - virtual int get_flow_stats(uint8_t port_id, uint64_t *stats, void *tx_stats, int min, int max, bool reset) const = 0; + virtual int get_flow_stats(uint8_t port_id, void *stats, void *tx_stats, int min, int max, bool reset) const = 0; virtual int reset_hw_flow_stats(uint8_t port_id) const = 0; virtual void get_port_num(uint8_t &port_num) const = 0; virtual int add_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const = 0; @@ -171,7 +171,7 @@ public: void publish_async_data_now(uint32_t key, bool baseline) const; uint8_t get_dp_core_count() const; void get_interface_stat_info(uint8_t interface_id, uint16_t &num_counters, uint16_t &capabilities) const; - int get_flow_stats(uint8_t port_id, uint64_t *stats, void *tx_stats, int min, int max, bool reset) const; + int get_flow_stats(uint8_t port_id, void *stats, void *tx_stats, int min, int max, bool reset) const; int reset_hw_flow_stats(uint8_t port_id) const; void get_port_num(uint8_t &port_num) const; int add_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const; @@ -225,7 +225,7 @@ public: virtual void publish_async_data_now(uint32_t key, bool baseline) const { } - virtual int get_flow_stats(uint8_t port_id, uint64_t *stats, void *tx_stats, int min, int max, bool reset) const {return 0;}; + virtual int get_flow_stats(uint8_t port_id, void *stats, void *tx_stats, int min, int max, bool reset) const {return 0;}; virtual int reset_hw_flow_stats(uint8_t port_id) const {return 0;}; virtual void get_port_num(uint8_t &port_num) const {port_num = 2;}; virtual int add_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const {return 0;} diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp index 111426c3..4fc048ff 100644 --- a/src/main_dpdk.cpp +++ b/src/main_dpdk.cpp @@ -1190,7 +1190,8 @@ void CPhyEthIFStats::Clear(){ oerrors = 0; imcasts = 0; rx_nombuf = 0; - memset(m_rx_per_flow, 0, sizeof(m_rx_per_flow)); + memset(m_rx_per_flow_pkts, 0, sizeof(m_rx_per_flow_pkts)); + memset(m_rx_per_flow_bytes, 0, sizeof(m_rx_per_flow_bytes)); } @@ -3990,7 +3991,7 @@ int CPhyEthIF::reset_hw_flow_stats() { // rx_stats, tx_stats - arrays of len max - min + 1. Returning rx, tx updated absolute values. // min, max - minimum, maximum counters range to get // reset - If true, need to reset counter value after reading -int CPhyEthIF::get_flow_stats(uint64_t *rx_stats, tx_per_flow_t *tx_stats, int min, int max, bool reset) { +int CPhyEthIF::get_flow_stats(rx_per_flow_t *rx_stats, tx_per_flow_t *tx_stats, int min, int max, bool reset) { uint32_t diff_pkts[MAX_FLOW_STATS]; uint32_t diff_bytes[MAX_FLOW_STATS]; @@ -4003,16 +4004,20 @@ int CPhyEthIF::get_flow_stats(uint64_t *rx_stats, tx_per_flow_t *tx_stats, int m if ( reset ) { // return value so far, and reset if (rx_stats != NULL) { - rx_stats[i - min] = m_stats.m_rx_per_flow[i] + diff_pkts[i]; + rx_stats[i - min].set_pkts(m_stats.m_rx_per_flow_pkts[i] + diff_pkts[i]); + rx_stats[i - min].set_bytes(m_stats.m_rx_per_flow_bytes[i] + diff_bytes[i]); } if (tx_stats != NULL) { tx_stats[i - min] = g_trex.clear_flow_tx_stats(m_port_id, i); } - m_stats.m_rx_per_flow[i] = 0; + m_stats.m_rx_per_flow_pkts[i] = 0; + m_stats.m_rx_per_flow_bytes[i] = 0; } else { - m_stats.m_rx_per_flow[i] += diff_pkts[i]; + m_stats.m_rx_per_flow_pkts[i] += diff_pkts[i]; + m_stats.m_rx_per_flow_bytes[i] += diff_bytes[i]; if (rx_stats != NULL) { - rx_stats[i - min] = m_stats.m_rx_per_flow[i]; + rx_stats[i - min].set_pkts(m_stats.m_rx_per_flow_pkts[i]); + rx_stats[i - min].set_bytes(m_stats.m_rx_per_flow_bytes[i]); } if (tx_stats != NULL) { tx_stats[i - min] = g_trex.get_flow_tx_stats(m_port_id, i); @@ -5288,8 +5293,8 @@ TrexDpdkPlatformApi::get_interface_stat_info(uint8_t interface_id, uint16_t &num capabilities = CTRexExtendedDriverDb::Ins()->get_drv()->get_rx_stat_capabilities(); } -int TrexDpdkPlatformApi::get_flow_stats(uint8 port_id, uint64_t *rx_stats, void *tx_stats, int min, int max, bool reset) const { - return g_trex.m_ports[port_id].get_flow_stats(rx_stats, (tx_per_flow_t *)tx_stats, min, max, reset); +int TrexDpdkPlatformApi::get_flow_stats(uint8 port_id, void *rx_stats, void *tx_stats, int min, int max, bool reset) const { + return g_trex.m_ports[port_id].get_flow_stats((rx_per_flow_t *)rx_stats, (tx_per_flow_t *)tx_stats, min, max, reset); } int TrexDpdkPlatformApi::reset_hw_flow_stats(uint8_t port_id) const { diff --git a/src/main_dpdk.h b/src/main_dpdk.h index c5d2d4d7..ff1ea784 100644 --- a/src/main_dpdk.h +++ b/src/main_dpdk.h @@ -38,7 +38,8 @@ class CPhyEthIFStats { uint64_t oerrors; /**< Total number of failed transmitted packets. */ uint64_t imcasts; /**< Total number of multicast received packets. */ uint64_t rx_nombuf; /**< Total number of RX mbuf allocation failures. */ - uint64_t m_rx_per_flow [MAX_FLOW_STATS]; // Per flow RX statistics + uint64_t m_rx_per_flow_pkts [MAX_FLOW_STATS]; // Per flow RX pkts + uint64_t m_rx_per_flow_bytes[MAX_FLOW_STATS]; // Per flow RX bytes // Previous fdir stats values read from driver. Since on xl710 this is 32 bit, we save old value, to handle wrap around. uint32_t m_fdir_prev_pkts [MAX_FLOW_STATS]; uint32_t m_fdir_prev_bytes [MAX_FLOW_STATS]; @@ -74,7 +75,7 @@ class CPhyEthIF { void get_stats(CPhyEthIFStats *stats); int dump_fdir_global_stats(FILE *fd); int reset_hw_flow_stats(); - int get_flow_stats(uint64_t *rx_stats, tx_per_flow_t *tx_stats, int min, int max, bool reset); + int get_flow_stats(rx_per_flow_t *rx_stats, tx_per_flow_t *tx_stats, int min, int max, bool reset); void get_stats_1g(CPhyEthIFStats *stats); void rx_queue_setup(uint16_t rx_queue_id, uint16_t nb_rx_desc, |