From ba7b5dff853a3b11b0cc2e7b29cfc1cd99e606f7 Mon Sep 17 00:00:00 2001 From: imarom Date: Wed, 10 Aug 2016 17:45:36 +0300 Subject: core mask - first phase --- src/sim/trex_sim.h | 3 +++ src/sim/trex_sim_stateless.cpp | 45 ++++++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 13 deletions(-) (limited to 'src/sim') diff --git a/src/sim/trex_sim.h b/src/sim/trex_sim.h index 0c343261..f52ad9b4 100644 --- a/src/sim/trex_sim.h +++ b/src/sim/trex_sim.h @@ -143,6 +143,7 @@ private: void prepare_control_plane(); void prepare_dataplane(); void execute_json(const std::string &json_filename); + void find_active_dp_cores(); void run_dp(const std::string &out_filename); @@ -179,6 +180,8 @@ private: int m_dp_core_index; uint64_t m_limit; bool m_is_dry_run; + + std::vector m_active_dp_cores; }; #endif /* __TREX_SIM_H__ */ diff --git a/src/sim/trex_sim_stateless.cpp b/src/sim/trex_sim_stateless.cpp index 77bd4d70..20041c2b 100644 --- a/src/sim/trex_sim_stateless.cpp +++ b/src/sim/trex_sim_stateless.cpp @@ -123,14 +123,14 @@ public: ************************/ SimStateless::SimStateless() { - m_publisher = NULL; - m_dp_to_cp_handler = NULL; - m_verbose = false; - m_dp_core_count = -1; - m_dp_core_index = -1; - m_port_count = -1; - m_limit = 0; - m_is_dry_run = false; + m_publisher = NULL; + m_dp_to_cp_handler = NULL; + m_verbose = false; + m_dp_core_count = -1; + m_dp_core_index = -1; + m_port_count = -1; + m_limit = 0; + m_is_dry_run = false; /* override ownership checks */ TrexRpcCommand::test_set_override_ownership(true); @@ -138,6 +138,23 @@ SimStateless::SimStateless() { } +/** + * on the simulation we first construct CP and then DP + * the only way to "assume" which DP will be active during + * the run is by checking for pending CP messages on the cores + * + * @author imarom (8/10/2016) + */ +void +SimStateless::find_active_dp_cores() { + for (int core_index = 0; core_index < m_dp_core_count; core_index++) { + CFlowGenListPerThread *lpt = m_fl.m_threads_info[core_index]; + if (lpt->are_any_pending_cp_messages()) { + m_active_dp_cores.push_back(core_index); + } + } +} + int SimStateless::run(const string &json_filename, const string &out_filename, @@ -168,6 +185,8 @@ SimStateless::run(const string &json_filename, return (-1); } + find_active_dp_cores(); + run_dp(out_filename); return 0; @@ -353,14 +372,14 @@ SimStateless::run_dp(const std::string &out_filename) { show_intro(out_filename); if (is_multiple_capture()) { - for (int i = 0; i < m_dp_core_count; i++) { + for (int i : m_active_dp_cores) { std::stringstream ss; ss << out_filename << "-" << i; run_dp_core(i, ss.str(), core_stats, total); } } else { - for (int i = 0; i < m_dp_core_count; i++) { + for (int i : m_active_dp_cores) { run_dp_core(i, out_filename, core_stats, total); } } @@ -414,9 +433,9 @@ SimStateless::get_limit_per_core(int core_index) { if (m_limit == 0) { return (0); } else { - uint64_t l = std::max((uint64_t)1, m_limit / m_dp_core_count); - if (core_index == 0) { - l += (m_limit % m_dp_core_count); + uint64_t l = std::max((uint64_t)1, m_limit / m_active_dp_cores.size()); + if (core_index == m_active_dp_cores[0]) { + l += (m_limit % m_active_dp_cores.size()); } return l; } -- cgit 1.2.3-korg