From: Mike Stepanek (mstepane) Date: Mon, 9 Dec 2019 13:22:29 +0000 (+0000) Subject: Merge pull request #1858 in SNORT/snort3 from ~DAVMCPHE/snort3:reload_idle_tuning... X-Git-Tag: 3.0.0-267~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e103de5812559eb52eccc26557582f40fcd47743;p=thirdparty%2Fsnort3.git Merge pull request #1858 in SNORT/snort3 from ~DAVMCPHE/snort3:reload_idle_tuning to master Squashed commit of the following: commit bac1de7f1bdc9aa14db71457e39932c27768c43e Author: davis mcpherson Date: Fri Nov 22 09:07:13 2019 -0500 reload: fix issue where resource tuning was not being called when in idle context --- diff --git a/src/flow/prune_stats.h b/src/flow/prune_stats.h index 1015f4695..ab4cacd2f 100644 --- a/src/flow/prune_stats.h +++ b/src/flow/prune_stats.h @@ -82,7 +82,7 @@ struct FlowDeleteStats PegCount get_total() const { PegCount total = 0; - for ( state_t i = 0; i < static_cast(PruneReason::MAX); ++i ) + for ( state_t i = 0; i < static_cast(FlowDeleteState::MAX); ++i ) total += deletes[i]; return total; diff --git a/src/main/analyzer.cc b/src/main/analyzer.cc index 5d5eb2be4..c06d2714e 100644 --- a/src/main/analyzer.cc +++ b/src/main/analyzer.cc @@ -535,6 +535,8 @@ const char* Analyzer::get_state_string() void Analyzer::idle() { + idling = true; + // FIXIT-L this whole thing could be pub-sub daq_stats.idle++; @@ -555,6 +557,10 @@ void Analyzer::idle() Stream::timeout_flows(packet_time()); HighAvailabilityManager::process_receive(); + + handle_uncompleted_commands(); + + idling = false; } /* diff --git a/src/main/analyzer.h b/src/main/analyzer.h index b15f4ade7..77c1fad88 100644 --- a/src/main/analyzer.h +++ b/src/main/analyzer.h @@ -108,6 +108,9 @@ public: void rotate(); snort::SFDAQInstance* get_daq_instance() { return daq_instance; } + bool is_idling() const + { return idling; } + private: void analyze(); bool handle_command(); @@ -136,6 +139,7 @@ private: std::atomic state; unsigned id; bool exit_requested = false; + bool idling = false; uint64_t exit_after_cnt; uint64_t pause_after_cnt = 0; uint64_t skip_cnt = 0; diff --git a/src/main/analyzer_command.cc b/src/main/analyzer_command.cc index ee9170afd..8bad70d9b 100644 --- a/src/main/analyzer_command.cc +++ b/src/main/analyzer_command.cc @@ -129,8 +129,16 @@ bool ACSwap::execute(Analyzer& analyzer, void** ac_state) if ( !reload_tuners->empty() ) { auto rrt = reload_tuners->front(); - if ( rrt->tune_packet_context() ) - reload_tuners->pop_front(); + if ( analyzer.is_idling() ) + { + if ( rrt->tune_idle_context() ) + reload_tuners->pop_front(); + } + else + { + if ( rrt->tune_packet_context() ) + reload_tuners->pop_front(); + } } // check for empty again and free list instance if we are done diff --git a/src/stream/base/stream_base.cc b/src/stream/base/stream_base.cc index 2b1c08f50..7bc89e193 100644 --- a/src/stream/base/stream_base.cc +++ b/src/stream/base/stream_base.cc @@ -65,6 +65,8 @@ const PegInfo base_pegs[] = { CountType::SUM, "expected_realized", "number of expected flows realized" }, { CountType::SUM, "expected_pruned", "number of expected flows pruned" }, { CountType::SUM, "expected_overflows", "number of expected cache overflows" }, + { CountType::SUM, "reload_tuning_idle", "number of times stream resource tuner called while idle" }, + { CountType::SUM, "reload_tuning_packets", "number of times stream resource tuner called while processing packets" }, { CountType::SUM, "reload_total_adds", "number of flows added by config reloads" }, { CountType::SUM, "reload_total_deletes", "number of flows deleted by config reloads" }, { CountType::SUM, "reload_freelist_deletes", "number of flows deleted from the free list by config reloads" }, @@ -103,13 +105,13 @@ void base_sum() } sum_stats((PegCount*)&g_stats, (PegCount*)&stream_base_stats, - array_size(base_pegs)-1); + array_size(base_pegs) - 1); base_reset(); } void base_stats() { - show_stats((PegCount*)&g_stats, base_pegs, array_size(base_pegs)-1, MOD_NAME); + show_stats((PegCount*)&g_stats, base_pegs, array_size(base_pegs) - 1, MOD_NAME); } void base_reset() diff --git a/src/stream/base/stream_module.cc b/src/stream/base/stream_module.cc index 4eb969c7a..09e3ae375 100644 --- a/src/stream/base/stream_module.cc +++ b/src/stream/base/stream_module.cc @@ -238,11 +238,13 @@ bool StreamReloadResourceManager::tinit() bool StreamReloadResourceManager::tune_packet_context() { + ++stream_base_stats.reload_tuning_packets; return tune_resources(max_work); } bool StreamReloadResourceManager::tune_idle_context() { + ++stream_base_stats.reload_tuning_idle; return tune_resources(max_work_idle); } diff --git a/src/stream/base/stream_module.h b/src/stream/base/stream_module.h index c6d3e1128..dd212b228 100644 --- a/src/stream/base/stream_module.h +++ b/src/stream/base/stream_module.h @@ -57,6 +57,8 @@ struct BaseStats PegCount expected_realized; PegCount expected_pruned; PegCount expected_overflows; + PegCount reload_tuning_idle; + PegCount reload_tuning_packets; PegCount reload_total_adds; PegCount reload_total_deletes; PegCount reload_freelist_flow_deletes;