From: Shanmugam S (shanms) Date: Thu, 22 Dec 2022 17:06:57 +0000 (+0000) Subject: Pull request #3705: watchdog: Add thread id as well for better identification of... X-Git-Tag: 3.1.51.0~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8f9af55557276006fa987aab681178e936aacc3;p=thirdparty%2Fsnort3.git Pull request #3705: watchdog: Add thread id as well for better identification of unresponsive threads Merge in SNORT/snort3 from ~AMUTTUVA/snort3:watchdog_tid to master Squashed commit of the following: commit c21969d8a3bd28db271f2ee069cec9e1a795c25b Author: Akhilesh MY Date: Fri Dec 16 03:08:01 2022 -0500 watchdog: Print thread id as well for better identification of unresponsive threads --- diff --git a/src/main/analyzer.cc b/src/main/analyzer.cc index 79fc52911..42ba696f4 100644 --- a/src/main/analyzer.cc +++ b/src/main/analyzer.cc @@ -742,7 +742,7 @@ void Analyzer::operator()(Swapper* ps, uint16_t run_num) // init here to pin separately from packet threads DetectionEngine::thread_init(); - + SnortConfig::get_conf()->thread_config->set_instance_tid(id, (int)gettid()); // Perform all packet thread initialization actions that need to be taken with escalated // privileges prior to starting the DAQ module. SnortConfig::get_conf()->thread_config->implement_thread_affinity( diff --git a/src/main/test/distill_verdict_stubs.h b/src/main/test/distill_verdict_stubs.h index cc0008a04..4440c9047 100644 --- a/src/main/test/distill_verdict_stubs.h +++ b/src/main/test/distill_verdict_stubs.h @@ -223,6 +223,7 @@ InspectionPolicy* get_inspection_policy() { return nullptr; } Flow::Flow() = default; Flow::~Flow() = default; void ThreadConfig::implement_thread_affinity(SThreadType, unsigned) { } +void ThreadConfig::set_instance_tid(const int, const int) { } } namespace memory diff --git a/src/main/thread_config.cc b/src/main/thread_config.cc index 5d16c870d..dbcb88cc1 100644 --- a/src/main/thread_config.cc +++ b/src/main/thread_config.cc @@ -162,6 +162,20 @@ void ThreadConfig::set_named_thread_affinity(const string& name, CpuSet* cpuset) ParseWarning(WARN_CONF, "This platform does not support setting thread affinity.\n"); } +void ThreadConfig::set_instance_tid(const int id, const int tid) +{ + instance_id_to_tid.emplace(id,tid); +} + +const int ThreadConfig::get_instance_tid(const int id) +{ + int ret = -1; + auto iter = instance_id_to_tid.find(id); + if ( iter != instance_id_to_tid.end() ) + ret = instance_id_to_tid.at(id); + return ret; +} + static inline string stringify_thread(const SThreadType& type, const unsigned& id) { string info; @@ -283,7 +297,11 @@ void Watchdog::kick() if ( !resp[i] ) { ++thread_count; - WarningMessage("%d ", i); + const int tid = SnortConfig::get_conf()->thread_config->get_instance_tid(i); + if ( tid != -1 ) + WarningMessage("%d (TID: %d)", i, tid); + else + WarningMessage("%d ", i); } } WarningMessage("\n"); diff --git a/src/main/thread_config.h b/src/main/thread_config.h index ca9e97076..0acc082c2 100644 --- a/src/main/thread_config.h +++ b/src/main/thread_config.h @@ -45,6 +45,8 @@ public: void set_named_thread_affinity(const std::string&, CpuSet*); void implement_thread_affinity(SThreadType, unsigned id); void implement_named_thread_affinity(const std::string& name); + void set_instance_tid(const int, const int); + const int get_instance_tid(const int); static constexpr unsigned int DEFAULT_THREAD_ID = 0; @@ -67,6 +69,7 @@ private: }; std::map thread_affinity; std::map named_thread_affinity; + std::map instance_id_to_tid; }; }