From: Steven Baigal (sbaigal) Date: Tue, 4 Apr 2023 19:18:02 +0000 (+0000) Subject: Pull request #3797: Revert "Pull request #3790: thread_config: remove message use... X-Git-Tag: 3.1.59.0~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d04316847a90436ced0522948c4cabbec17070e;p=thirdparty%2Fsnort3.git Pull request #3797: Revert "Pull request #3790: thread_config: remove message use in wdt" Merge in SNORT/snort3 from ~SBAIGAL/snort3:revert_wgt1 to master Squashed commit of the following: commit 89cecd40161799c1c0afbaf83698cd77af32c172 Author: Steven Baigal Date: Tue Apr 4 14:55:20 2023 -0400 Revert "Pull request #3790: thread_config: remove message use in wdt" This reverts commit 824a06ebdc56f88ec8dfe9c96f31a712e053e00e. --- diff --git a/src/flow/flow_cache.cc b/src/flow/flow_cache.cc index 22460ebb7..39fbce641 100644 --- a/src/flow/flow_cache.cc +++ b/src/flow/flow_cache.cc @@ -28,7 +28,6 @@ #include "hash/hash_defs.h" #include "hash/zhash.h" #include "helpers/flag_context.h" -#include "main/thread_config.h" #include "packet_io/active.h" #include "packet_tracer/packet_tracer.h" #include "stream/base/stream_module.h" @@ -49,7 +48,6 @@ using namespace snort; static const unsigned ALLOWED_FLOWS_ONLY = 1; static const unsigned OFFLOADED_FLOWS_TOO = 2; static const unsigned ALL_FLOWS = 3; -static const unsigned WDT_MASK = 7; // kick watchdog once for every 8 flows deleted //------------------------------------------------------------------------- // FlowCache stuff @@ -456,9 +454,7 @@ unsigned FlowCache::delete_active_flows(unsigned mode, unsigned num_to_delete, u continue; } - if ( (deleted & WDT_MASK) == 0 ) - ThreadConfig::preemptive_kick(); - + // we have a winner... unlink_uni(flow); if ( flow->was_blocked() ) @@ -492,9 +488,6 @@ unsigned FlowCache::delete_flows(unsigned num_to_delete) // delete from the free list first... while ( num_to_delete ) { - if ( (deleted & WDT_MASK) == 0 ) - ThreadConfig::preemptive_kick(); - Flow* flow = (Flow*)hash_table->pop(); if ( !flow ) break; diff --git a/src/flow/test/flow_cache_test.cc b/src/flow/test/flow_cache_test.cc index 6fc0d0e2a..1ceca8f43 100644 --- a/src/flow/test/flow_cache_test.cc +++ b/src/flow/test/flow_cache_test.cc @@ -33,7 +33,6 @@ #include "flow/session.h" #include "main/policy.h" #include "main/snort_config.h" -#include "main/thread_config.h" #include "managers/inspector_manager.h" #include "packet_io/active.h" #include "packet_tracer/packet_tracer.h" @@ -106,7 +105,6 @@ SfIpRet SfIp::set(void const*, int) { return SFIP_SUCCESS; } void snort::trace_vprintf(const char*, TraceLevel, const char*, const Packet*, const char*, va_list) {} uint8_t snort::TraceApi::get_constraints_generation() { return 0; } void snort::TraceApi::filter(const Packet&) {} -void ThreadConfig::preemptive_kick() {} namespace snort { diff --git a/src/main/thread_config.cc b/src/main/thread_config.cc index 1119c8a99..98286047b 100644 --- a/src/main/thread_config.cc +++ b/src/main/thread_config.cc @@ -275,7 +275,7 @@ struct Watchdog class WatchdogKick : public AnalyzerCommand { public: - WatchdogKick(Watchdog* d) : dog(d) { } + WatchdogKick(Watchdog* d) : dog(d) { dog->waiting = true; } bool execute(Analyzer&, void**) override { dog->resp[get_instance_id()] = true; @@ -283,7 +283,7 @@ public: } const char* stringify() override { return "WATCHDOG_KICK"; } - ~WatchdogKick() override { } + ~WatchdogKick() override { dog->waiting = false; } private: Watchdog* dog; }; @@ -294,16 +294,13 @@ void Watchdog::kick() if ( waiting ) { uint16_t thread_count = 0; + WarningMessage("Packet processing threads are unresponsive\n"); + WarningMessage("Unresponsive thread ID: "); for ( unsigned i = 0; i < max; ++i ) { if ( !resp[i] ) { ++thread_count; - if (thread_count == 1) - { - WarningMessage("Packet processing threads are unresponsive\n"); - WarningMessage("Unresponsive thread ID: "); - } const int tid = SnortConfig::get_conf()->thread_config->get_instance_tid(i); if ( tid != -1 ) WarningMessage("%d (TID: %d)", i, tid); @@ -311,10 +308,7 @@ void Watchdog::kick() WarningMessage("%d ", i); } } - - if ( thread_count ) - WarningMessage("\n"); - + WarningMessage("\n"); if ( thread_count >= SnortConfig::get_conf()->watchdog_min_thread_count ) { WarningMessage("Aborting Snort\n"); @@ -326,26 +320,19 @@ void Watchdog::kick() resp[i] = false; main_broadcast_command(new WatchdogKick(this), nullptr); - waiting = true; -} - -static Watchdog& get_watchdog() -{ - static Watchdog s_dog(SnortConfig::get_conf()->watchdog_timer); - return s_dog; } static void s_watchdog_handler(void*) { - Watchdog& dog = get_watchdog(); + static Watchdog s_dog(SnortConfig::get_conf()->watchdog_timer); if ( SnortConfig::get_conf()->watchdog_timer > 0 ) { - if ( dog.seconds_count > 0 ) - dog.seconds_count--; + if ( s_dog.seconds_count > 0 ) + s_dog.seconds_count--; else { - dog.kick(); - dog.seconds_count = SnortConfig::get_conf()->watchdog_timer; + s_dog.kick(); + s_dog.seconds_count = SnortConfig::get_conf()->watchdog_timer; } } } @@ -355,15 +342,6 @@ void ThreadConfig::start_watchdog() Periodic::register_handler(s_watchdog_handler, nullptr, 0, 1000); } -void ThreadConfig::preemptive_kick() -{ - if (SnortConfig::get_conf()->watchdog_timer) - { - Watchdog& dog = get_watchdog(); - dog.resp[get_instance_id()] = true; - } -} - // ----------------------------------------------------------------------------- // unit tests diff --git a/src/main/thread_config.h b/src/main/thread_config.h index ba4096941..c59c7d792 100644 --- a/src/main/thread_config.h +++ b/src/main/thread_config.h @@ -39,7 +39,6 @@ public: static unsigned get_instance_max(); static void term(); static void start_watchdog(); - static void preemptive_kick(); static void set_instance_tid(int); static int get_instance_tid(int);