From 85a30b56e626f7a36cf84c3055ffc6c50a3317e7 Mon Sep 17 00:00:00 2001 From: Eric MacDonald Date: Wed, 6 Jun 2018 14:24:29 -0400 Subject: [PATCH] Mtce: Improve efficiency of mtcAgent's end-of-batch message handling The mtcAgent's message inbox batch handling was needlessly zeroing a buffer that it would never use after it reached the last received message. This update refactors the mtc_service_inbox entry code so that the message buffer zeroing operation only occurs on the unused part of fully received messages. To facilitate this change, a new utility for zeroing a bounded part of a mtce message buf was introduced to common utils. Two additional enhancements were also made to the same procedure: - variable scoping change. - hostaddr and hostname lookup scoping change. Change-Id: Ia2ef97dad611507b824927ed1652c8df8b54eee5 Signed-off-by: Eric MacDonald --- .../cgts-mtce-common-1.0/common/nodeBase.cpp | 12 ++++++++ .../cgts-mtce-common-1.0/common/nodeBase.h | 2 ++ .../maintenance/mtcCtrlMsg.cpp | 30 ++++++++++--------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/mtce-common/cgts-mtce-common-1.0/common/nodeBase.cpp b/mtce-common/cgts-mtce-common-1.0/common/nodeBase.cpp index 3f70200a..c3480638 100755 --- a/mtce-common/cgts-mtce-common-1.0/common/nodeBase.cpp +++ b/mtce-common/cgts-mtce-common-1.0/common/nodeBase.cpp @@ -705,3 +705,15 @@ bool is_host_services_cmd ( unsigned int cmd ) } return (false); } + +/* Used to fill the mtce message buffer starting after supplied 'bytes' count */ +void zero_unused_msg_buf ( mtc_message_type & msg, int bytes) +{ + if ( bytes < (int)sizeof(msg) ) + { + char * ptr = (char *)&msg ; + ptr += (bytes) ; + memset ( ptr, 0, sizeof(msg)-bytes); + } +} + diff --git a/mtce-common/cgts-mtce-common-1.0/common/nodeBase.h b/mtce-common/cgts-mtce-common-1.0/common/nodeBase.h index cf42f347..390d5ca5 100755 --- a/mtce-common/cgts-mtce-common-1.0/common/nodeBase.h +++ b/mtce-common/cgts-mtce-common-1.0/common/nodeBase.h @@ -1226,6 +1226,8 @@ int daemon_log_message ( const char * hostname, bool is_host_services_cmd ( unsigned int cmd ); +void zero_unused_msg_buf ( mtc_message_type & msg, int bytes); + /** Runtime Trace Log Utilities */ void daemon_dump_membuf ( void ); void daemon_dump_membuf_banner ( void ); diff --git a/mtce-common/cgts-mtce-common-1.0/maintenance/mtcCtrlMsg.cpp b/mtce-common/cgts-mtce-common-1.0/maintenance/mtcCtrlMsg.cpp index ff404bff..8a1f5291 100755 --- a/mtce-common/cgts-mtce-common-1.0/maintenance/mtcCtrlMsg.cpp +++ b/mtce-common/cgts-mtce-common-1.0/maintenance/mtcCtrlMsg.cpp @@ -125,17 +125,8 @@ int mtc_service_inbox ( nodeLinkClass * obj_ptr, int iface) { mtc_message_type msg ; - std::list::iterator iter ; - int bytes = 0 ; int rc = PASS ; - string ip = "0.0.0.0" ; - - MEMSET_ZERO (msg); - - string hostaddr = "" ; - string hostname = "" ; - if ( iface == INFRA_INTERFACE ) { if ( ( obj_ptr ) && @@ -143,20 +134,15 @@ int mtc_service_inbox ( nodeLinkClass * obj_ptr, ( sock_ptr->mtc_agent_infra_rx_socket )) { bytes = sock_ptr->mtc_agent_infra_rx_socket->read((char*)&msg, sizeof(msg)); - hostaddr = sock_ptr->mtc_agent_infra_rx_socket->get_src_str(); - hostname = obj_ptr->get_hostname ( hostaddr ) ; } else { - ilog ("cannot receive from unprovisioned Infra socket\n"); return ( FAIL_NO_INFRA_PROV ); } } else { bytes = sock_ptr->mtc_agent_rx_socket->read((char*)&msg, sizeof(msg)); - hostaddr = sock_ptr->mtc_agent_rx_socket->get_src_str(); - hostname = obj_ptr->get_hostname ( hostaddr ) ; } if ( bytes <= 0 ) @@ -173,8 +159,23 @@ int mtc_service_inbox ( nodeLinkClass * obj_ptr, rx_error_count = 0 ; } + zero_unused_msg_buf (msg, bytes); + + string hostaddr = "" ; + string hostname = "" ; + if ( iface == INFRA_INTERFACE ) + { + hostaddr = sock_ptr->mtc_agent_infra_rx_socket->get_src_str(); + hostname = obj_ptr->get_hostname ( hostaddr ) ; + } + else + { + hostaddr = sock_ptr->mtc_agent_rx_socket->get_src_str(); + hostname = obj_ptr->get_hostname ( hostaddr ) ; + } if ( hostname.empty() ) { + std::list::iterator iter ; iter = std::find (unknown_ip_list.begin(), unknown_ip_list.end(), hostaddr ); if ( iter == unknown_ip_list.end() ) { @@ -541,6 +542,7 @@ int mtc_service_inbox ( nodeLinkClass * obj_ptr, if ( daemon_get_cfg_ptr()->debug_msg ) { int count = 0 ; + std::list::iterator iter ; for ( iter = unknown_ip_list.begin () ; iter != unknown_ip_list.end () ; iter++ )