From 483dfb7c5021d7dc9e2c7f10c9b76101441c7203 Mon Sep 17 00:00:00 2001 From: imarom Date: Sun, 3 Jul 2016 15:38:59 +0300 Subject: slowpath features bit to avoid multiple IFs --- src/bp_sim.h | 6 ++++++ src/main_dpdk.cpp | 42 ++++++++++++++++++++++++++++++------------ src/trex_client_config.cpp | 18 ++---------------- src/utl_yaml.cpp | 27 +++++++++++++++++++++++++-- src/utl_yaml.h | 11 ++++++++--- 5 files changed, 71 insertions(+), 33 deletions(-) diff --git a/src/bp_sim.h b/src/bp_sim.h index 4e301b2d..bfccc817 100755 --- a/src/bp_sim.h +++ b/src/bp_sim.h @@ -629,6 +629,9 @@ public: void set_mac_ip_overide_enable(bool enable){ btSetMaskBit32(m_flags,30,30,enable?1:0); + if (enable) { + set_slowpath_features_on(enable); + } } bool get_is_rx_check_enable(){ @@ -653,6 +656,9 @@ public: void set_client_cfg_enable(bool enable){ btSetMaskBit32(m_flags1, 1, 1, enable ? 1 : 0); + if (enable) { + set_slowpath_features_on(enable); + } } diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp index 4b086597..c4ba7fa5 100644 --- a/src/main_dpdk.cpp +++ b/src/main_dpdk.cpp @@ -1732,7 +1732,9 @@ public: virtual void flush_dp_rx_queue(void); virtual int flush_tx_queue(void); __attribute__ ((noinline)) void flush_rx_queue(); - __attribute__ ((noinline)) void apply_client_cfg(const ClientCfg *cfg, rte_mbuf_t *m, pkt_dir_t dir, uint8_t *p); + __attribute__ ((noinline)) void handle_slowpath_features(CGenNode *node, rte_mbuf_t *m, uint8_t *p, pkt_dir_t dir); + + void apply_client_cfg(const ClientCfg *cfg, rte_mbuf_t *m, pkt_dir_t dir, uint8_t *p); bool process_rx_pkt(pkt_dir_t dir,rte_mbuf_t * m); @@ -2146,8 +2148,29 @@ void CCoreEthIF::add_vlan(rte_mbuf_t *m, uint16_t vlan_id) { m->vlan_tci = vlan_id; } +/** + * slow path features goes here (avoid multiple IFs) + * + */ +void CCoreEthIF::handle_slowpath_features(CGenNode *node, rte_mbuf_t *m, uint8_t *p, pkt_dir_t dir) { + + + /* MAC ovverride */ + if ( unlikely( CGlobalInfo::m_options.preview.get_mac_ip_overide_enable() ) ) { + /* client side */ + if ( node->is_initiator_pkt() ) { + *((uint32_t*)(p+6)) = PKT_NTOHL(node->m_src_ip); + } + } + + /* flag is faster than checking the node pointer (another cacheline) */ + if ( unlikely(CGlobalInfo::m_options.preview.get_is_client_cfg_enable() ) ) { + apply_client_cfg(node->m_client_cfg, m, dir, p); + } + +} + int CCoreEthIF::send_node(CGenNode * node) { - if ( unlikely( node->get_cache_mbuf() !=NULL ) ) { pkt_dir_t dir; @@ -2170,6 +2193,7 @@ int CCoreEthIF::send_node(CGenNode * node) { dir = node->cur_interface_dir(); single_port = node->get_is_all_flow_from_same_dir() ; + if ( unlikely( CGlobalInfo::m_options.preview.get_vlan_mode_enable() ) ){ /* which vlan to choose 0 or 1*/ uint8_t vlan_port = (node->m_src_ip &1); @@ -2200,18 +2224,12 @@ int CCoreEthIF::send_node(CGenNode * node) { memcpy(p,CGlobalInfo::m_options.get_dst_src_mac_addr(p_id),12); - if ( unlikely( CGlobalInfo::m_options.preview.get_mac_ip_overide_enable() ) ) { - /* client side */ - if ( node->is_initiator_pkt() ) { - *((uint32_t*)(p+6)) = PKT_NTOHL(node->m_src_ip); - } - } - - /* flag is faster than checking the node pointer (another cacheline) */ - if ( unlikely(CGlobalInfo::m_options.preview.get_is_client_cfg_enable() ) ) { - apply_client_cfg(node->m_client_cfg, m, dir, p); + /* when slowpath features are on */ + if ( unlikely( CGlobalInfo::m_options.preview.get_is_slowpath_features_on() ) ) { + handle_slowpath_features(node, m, p, dir); } + if ( unlikely( node->is_rx_check_enabled() ) ) { lp_stats->m_tx_rx_check_pkt++; lp->do_generate_new_mbuf_rxcheck(m, node, single_port); diff --git a/src/trex_client_config.cpp b/src/trex_client_config.cpp index 8569cbf0..b56037ea 100644 --- a/src/trex_client_config.cpp +++ b/src/trex_client_config.cpp @@ -70,24 +70,10 @@ ClientCfgDB::load_yaml_file(const std::string &filename) { m_groups.clear(); m_cache_group = NULL; - if (!utl_is_file_exists(filename)){ - ss << "file '" << filename << "' does not exists"; - throw std::runtime_error(ss.str()); - } - - std::ifstream fin(filename); - YAML::Parser base_parser(fin); - YAML::Node root; - - /* parse the YAML */ - try { - base_parser.GetNextDocument(root); - } catch (const std::runtime_error &ex) { - throw std::runtime_error("failed to parse client config file '" + filename + "'\n " + std::string(ex.what())); - } - /* wrapper parser */ + YAML::Node root; YAMLParserWrapper parser(filename); + parser.load(root); /* parse globals */ m_under_vlan = parser.parse_bool(root, "vlan"); diff --git a/src/utl_yaml.cpp b/src/utl_yaml.cpp index 66c83ac8..8352e887 100755 --- a/src/utl_yaml.cpp +++ b/src/utl_yaml.cpp @@ -22,6 +22,8 @@ limitations under the License. */ #include +#include +#include "common/basic_utils.h" #define INADDRSZ 4 @@ -157,6 +159,27 @@ static bool mac2uint64(const std::string &mac_str, uint64_t &mac_num) { * YAML Parser Wrapper * ***********************/ +void +YAMLParserWrapper::load(YAML::Node &root) { + std::stringstream ss; + + /* first check file exists */ + if (!utl_is_file_exists(m_filename)){ + ss << "file '" << m_filename << "' does not exists"; + throw std::runtime_error(ss.str()); + } + + std::ifstream fin(m_filename); + + try { + YAML::Parser base_parser(fin); + base_parser.GetNextDocument(root); + + } catch (const YAML::Exception &e) { + parse_err(e.what()); + } +} + bool YAMLParserWrapper::parse_bool(const YAML::Node &node, const std::string &name, bool def) { if (!node.FindValue(name)) { @@ -322,7 +345,7 @@ void YAMLParserWrapper::parse_err(const std::string &err, const YAML::Node &node) const { std::stringstream ss; - ss << "'" << m_header << "' - YAML parsing error at line " << node.GetMark().line << ": "; + ss << "'" << m_filename << "' - YAML parsing error at line " << node.GetMark().line << ": "; ss << err; throw std::runtime_error(ss.str()); @@ -332,7 +355,7 @@ void YAMLParserWrapper::parse_err(const std::string &err) const { std::stringstream ss; - ss << "'" << m_header << "' - YAML parsing error: " << err; + ss << "'" << m_filename << "' - YAML parsing error: " << err; throw std::runtime_error(ss.str()); } diff --git a/src/utl_yaml.h b/src/utl_yaml.h index 2547b666..59104b21 100755 --- a/src/utl_yaml.h +++ b/src/utl_yaml.h @@ -39,14 +39,19 @@ bool utl_yaml_read_uint16(const YAML::Node& node, const std::string &name, uint16_t & val); - /* a thin wrapper to customize errors */ class YAMLParserWrapper { public: /* a header that will start every error message */ - YAMLParserWrapper(const std::string &header) : m_header(header) { + YAMLParserWrapper(const std::string &filename) : m_filename(filename) { } + /** + * loads the file (while parsing it) + * + */ + void load(YAML::Node &root); + /* bool */ bool parse_bool(const YAML::Node &node, const std::string &name); bool parse_bool(const YAML::Node &node, const std::string &name, bool def); @@ -69,6 +74,6 @@ public: private: - std::string m_header; + std::string m_filename; }; #endif -- cgit 1.2.3-korg