From ac0ae5cdc25d0ca7df05494b56d0ecc26a08ebe6 Mon Sep 17 00:00:00 2001 From: Dmytro Podgornyi Date: Thu, 23 Jul 2020 14:10:23 +0300 Subject: [PATCH] issue: 2247939 Add option VMA_VMAD_ENABLED This option allows to disable vmad functionality in VMA. Running vmad process can lead to performance degradation in case of multiple TCP socket state changes. Signed-off-by: Dmytro Podgornyi --- README.txt | 5 +++++ src/vma/dev/ring_tap.cpp | 6 ++++++ src/vma/main.cpp | 17 ++++++++++++++--- src/vma/sock/sockinfo_tcp.cpp | 14 +++++++++----- src/vma/util/sys_vars.cpp | 5 +++++ src/vma/util/sys_vars.h | 5 ++++- 6 files changed, 43 insertions(+), 9 deletions(-) diff --git a/README.txt b/README.txt index 80edf2dfe7..13e31d5a46 100644 --- a/README.txt +++ b/README.txt @@ -108,6 +108,7 @@ Example: VMA DETAILS: Stats File [VMA_STATS_FILE] VMA DETAILS: Stats shared memory directory /tmp/ [VMA_STATS_SHMEM_DIR] VMA DETAILS: VMAD output directory /tmp/vma/ [VMA_VMAD_NOTIFY_DIR] + VMA DETAILS: VMAD support Enabled [VMA_VMAD_ENABLED] VMA DETAILS: Stats FD Num (max) 100 [VMA_STATS_FD_NUM] VMA DETAILS: Conf File /etc/libvma.conf [VMA_CONFIG_FILE] VMA DETAILS: Application ID VMA_DEFAULT_APPLICATION_ID [VMA_APPLICATION_ID] @@ -324,6 +325,10 @@ Set the directory path for VMA to write files used by vmad. Default value is /tmp/vma/ Note: when used vmad must be run with --notify-dir directing the same folder. +VMA_VMAD_ENABLED +When this option is disabled VMA won't communicate with vmad. +Default vale is 1 (Enabled) + VMA_STATS_FD_NUM Max number of sockets monitored by VMA statistic mechanism. Value range is 0 to 1024. diff --git a/src/vma/dev/ring_tap.cpp b/src/vma/dev/ring_tap.cpp index 89685cbe1c..7595efab9f 100644 --- a/src/vma/dev/ring_tap.cpp +++ b/src/vma/dev/ring_tap.cpp @@ -371,6 +371,9 @@ int ring_tap::prepare_flow_message(vma_msg_flow& data, msg_flow_t flow_action, { int rc = 0; + if (unlikely(g_p_agent == NULL)) + return 0; + memset(&data, 0, sizeof(data)); data.hdr.code = VMA_MSG_FLOW; data.hdr.ver = VMA_AGENT_VER; @@ -400,6 +403,9 @@ int ring_tap::prepare_flow_message(vma_msg_flow& data, msg_flow_t flow_action) { int rc = 0; + if (unlikely(g_p_agent == NULL)) + return 0; + memset(&data, 0, sizeof(data)); data.hdr.code = VMA_MSG_FLOW; data.hdr.ver = VMA_AGENT_VER; diff --git a/src/vma/main.cpp b/src/vma/main.cpp index 69a66dd8c4..d2325171c3 100644 --- a/src/vma/main.cpp +++ b/src/vma/main.cpp @@ -390,6 +390,7 @@ void print_vma_global_settings() VLOG_STR_PARAM_STRING("Stats File", safe_mce_sys().stats_filename, MCE_DEFAULT_STATS_FILE, SYS_VAR_STATS_FILENAME, safe_mce_sys().stats_filename); VLOG_STR_PARAM_STRING("Stats shared memory directory", safe_mce_sys().stats_shmem_dirname, MCE_DEFAULT_STATS_SHMEM_DIR, SYS_VAR_STATS_SHMEM_DIRNAME, safe_mce_sys().stats_shmem_dirname); VLOG_STR_PARAM_STRING("VMAD output directory", safe_mce_sys().vmad_notify_dir, MCE_DEFAULT_VMAD_FOLDER, SYS_VAR_VMAD_DIR, safe_mce_sys().vmad_notify_dir); + VLOG_PARAM_STRING("VMAD support", safe_mce_sys().vmad_enabled, MCE_DEFAULT_VMAD_ENABLED, SYS_VAR_VMAD_ENABLED, safe_mce_sys().vmad_enabled ? "Enabled" : "Disabled"); VLOG_PARAM_NUMBER("Stats FD Num (max)", safe_mce_sys().stats_fd_num_max, MCE_DEFAULT_STATS_FD_NUM, SYS_VAR_STATS_FD_NUM); VLOG_STR_PARAM_STRING("Conf File", safe_mce_sys().conf_filename, MCE_DEFAULT_CONF_FILE, SYS_VAR_CONF_FILENAME, safe_mce_sys().conf_filename); VLOG_STR_PARAM_STRING("Application ID", safe_mce_sys().app_id, MCE_DEFAULT_APP_ID, SYS_VAR_APPLICATION_ID, safe_mce_sys().app_id); @@ -674,9 +675,19 @@ static void do_global_ctors_helper() g_is_forked_child = false; /* Open communication with daemon */ - NEW_CTOR(g_p_agent, agent()); - vlog_printf(VLOG_DEBUG,"Agent setup state: g_p_agent=%p active=%d\n", - g_p_agent, (g_p_agent ? g_p_agent->state() : -1)); + if (safe_mce_sys().vmad_enabled) { + NEW_CTOR(g_p_agent, agent()); + vlog_printf(VLOG_DEBUG, "Agent setup state: g_p_agent=%p active=%d\n", + g_p_agent, (g_p_agent ? g_p_agent->state() : -1)); + } else { + vlog_printf(VLOG_DEBUG, "Agent is disabled"); + if (mce_sys_var::HYPER_MSHV == safe_mce_sys().hypervisor) { + vlog_printf(VLOG_WARNING, "*************************************************************\n"); + vlog_printf(VLOG_WARNING, "* VMA agent is disabled on Hyper-V system, but shouldn't be.*\n"); + vlog_printf(VLOG_WARNING, "* Consider using VMA_VMAD_ENABLED=1 option. *\n"); + vlog_printf(VLOG_WARNING, "*************************************************************\n"); + } + } // Create all global managment objects NEW_CTOR(g_p_event_handler_manager, event_handler_manager()); diff --git a/src/vma/sock/sockinfo_tcp.cpp b/src/vma/sock/sockinfo_tcp.cpp index ccff41b951..da9e2d51ad 100644 --- a/src/vma/sock/sockinfo_tcp.cpp +++ b/src/vma/sock/sockinfo_tcp.cpp @@ -313,7 +313,9 @@ sockinfo_tcp::sockinfo_tcp(int fd): } si_tcp_logdbg("TCP PCB FLAGS: 0x%x", m_pcb.flags); - g_p_agent->register_cb((agent_cb_t)&sockinfo_tcp::put_agent_msg, (void *)this); + if (g_p_agent != NULL) { + g_p_agent->register_cb((agent_cb_t)&sockinfo_tcp::put_agent_msg, (void *)this); + } si_tcp_logfunc("done"); } @@ -356,8 +358,9 @@ sockinfo_tcp::~sockinfo_tcp() si_tcp_logerr("not all buffers were freed. protocol=TCP. m_n_rx_pkt_ready_list_count=%d, m_rx_ready_byte_count=%d, m_rx_pkt_ready_list.size()=%d, m_rx_ring_map.size()=%d, m_rx_reuse_buff.n_buff_num=%d, m_rx_reuse_buff.rx_reuse.size=%d, m_rx_cb_dropped_list.size=%d, m_rx_ctl_packets_list.size=%d, m_rx_peer_packets.size=%d, m_rx_ctl_reuse_list.size=%d", m_n_rx_pkt_ready_list_count, m_rx_ready_byte_count, (int)m_rx_pkt_ready_list.size() ,(int)m_rx_ring_map.size(), m_rx_reuse_buff.n_buff_num, m_rx_reuse_buff.rx_reuse.size(), m_rx_cb_dropped_list.size(), m_rx_ctl_packets_list.size(), m_rx_peer_packets.size(), m_rx_ctl_reuse_list.size()); - g_p_agent->unregister_cb((agent_cb_t)&sockinfo_tcp::put_agent_msg, (void *)this); - + if (g_p_agent != NULL) { + g_p_agent->unregister_cb((agent_cb_t)&sockinfo_tcp::put_agent_msg, (void *)this); + } si_tcp_logdbg("sock closed"); } @@ -1159,7 +1162,7 @@ err_t sockinfo_tcp::ip_output_syn_ack(struct pbuf *p, void* v_p_conn, int is_rex p_si_tcp->m_p_socket_stats->tcp_state = new_state; /* Update daemon about actual state for offloaded connection */ - if (likely(p_si_tcp->m_sock_offload == TCP_SOCK_LWIP)) { + if (g_p_agent != NULL && likely(p_si_tcp->m_sock_offload == TCP_SOCK_LWIP)) { p_si_tcp->put_agent_msg((void *)p_si_tcp); } } @@ -4733,7 +4736,8 @@ void tcp_timers_collection::handle_timer_expired(void* user_data) m_n_location = (m_n_location + 1) % m_n_intervals_size; /* Processing all messages for the daemon */ - g_p_agent->progress(); + if (g_p_agent != NULL) + g_p_agent->progress(); } void tcp_timers_collection::add_new_timer(timer_node_t* node, timer_handler* handler, void* user_data) diff --git a/src/vma/util/sys_vars.cpp b/src/vma/util/sys_vars.cpp index 49b04cb999..07f3ff4622 100644 --- a/src/vma/util/sys_vars.cpp +++ b/src/vma/util/sys_vars.cpp @@ -518,6 +518,7 @@ void mce_sys_var::get_env_params() handle_sigintr = MCE_DEFAULT_HANDLE_SIGINTR; handle_segfault = MCE_DEFAULT_HANDLE_SIGFAULT; stats_fd_num_max = MCE_DEFAULT_STATS_FD_NUM; + vmad_enabled = MCE_DEFAULT_VMAD_ENABLED; ring_allocation_logic_tx= MCE_DEFAULT_RING_ALLOCATION_LOGIC_TX; ring_allocation_logic_rx= MCE_DEFAULT_RING_ALLOCATION_LOGIC_RX; @@ -804,6 +805,10 @@ void mce_sys_var::get_env_params() read_env_variable_with_pid(vmad_notify_dir, sizeof(vmad_notify_dir), env_ptr); } + if ((env_ptr = getenv(SYS_VAR_VMAD_ENABLED)) != NULL){ + vmad_enabled = atoi(env_ptr) ? true : false; + } + if ((env_ptr = getenv(SYS_VAR_LOG_LEVEL)) != NULL) log_level = log_level::from_str(env_ptr, VLOG_DEFAULT); diff --git a/src/vma/util/sys_vars.h b/src/vma/util/sys_vars.h index 90ab66e42f..5706fa140d 100644 --- a/src/vma/util/sys_vars.h +++ b/src/vma/util/sys_vars.h @@ -313,6 +313,7 @@ struct mce_sys_var { char stats_shmem_dirname[PATH_MAX]; char conf_filename[PATH_MAX]; char vmad_notify_dir[PATH_MAX]; + bool vmad_enabled; bool log_colors; bool handle_sigintr; bool handle_segfault; @@ -457,6 +458,7 @@ extern mce_sys_var & safe_mce_sys(); #define SYS_VAR_LOG_FILENAME "VMA_LOG_FILE" #define SYS_VAR_STATS_FILENAME "VMA_STATS_FILE" #define SYS_VAR_VMAD_DIR "VMA_VMAD_NOTIFY_DIR" +#define SYS_VAR_VMAD_ENABLED "VMA_VMAD_ENABLED" #define SYS_VAR_STATS_SHMEM_DIRNAME "VMA_STATS_SHMEM_DIR" #define SYS_VAR_CONF_FILENAME "VMA_CONFIG_FILE" #define SYS_VAR_LOG_COLORS "VMA_LOG_COLORS" @@ -575,7 +577,8 @@ extern mce_sys_var & safe_mce_sys(); #define MCE_DEFAULT_LOG_FILE ("") #define MCE_DEFAULT_CONF_FILE ("/etc/libvma.conf") #define MCE_DEFAULT_STATS_FILE ("") -#define MCE_DEFAULT_VMAD_FOLDER (VMA_AGENT_PATH) +#define MCE_DEFAULT_VMAD_FOLDER (VMA_AGENT_PATH) +#define MCE_DEFAULT_VMAD_ENABLED (true) #define MCE_DEFAULT_STATS_SHMEM_DIR ("/tmp/") #define MCE_DEFAULT_LOG_DETAILS (0) #define MCE_DEFAULT_LOG_COLORS (true)