]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #3705: watchdog: Add thread id as well for better identification of...
authorShanmugam S (shanms) <shanms@cisco.com>
Thu, 22 Dec 2022 17:06:57 +0000 (17:06 +0000)
committerShanmugam S (shanms) <shanms@cisco.com>
Thu, 22 Dec 2022 17:06:57 +0000 (17:06 +0000)
Merge in SNORT/snort3 from ~AMUTTUVA/snort3:watchdog_tid to master

Squashed commit of the following:

commit c21969d8a3bd28db271f2ee069cec9e1a795c25b
Author: Akhilesh MY <amuttuva@cisco.com>
Date:   Fri Dec 16 03:08:01 2022 -0500

    watchdog: Print thread id as well for better identification of unresponsive threads

src/main/analyzer.cc
src/main/test/distill_verdict_stubs.h
src/main/thread_config.cc
src/main/thread_config.h

index 79fc52911b957b53686634ab389cdd6751aaaf8c..42ba696f466cd8aac5008d01c1752937b40b0c79 100644 (file)
@@ -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(
index cc0008a042c3e3bff6179adb425dec358f3abbfe..4440c90477ebddfc05f9b3236fd5765a7087af8b 100644 (file)
@@ -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
index 5d16c870d6d295c37d79fb97613a3a9e78b2116a..dbcb88cc115bc41a66b1979a4175f11d744df64b 100644 (file)
@@ -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");
index ca9e9707677e15a35a9aeed1d5caff1c4f59bc05..0acc082c25613a44e65f542b66d21d20cdc77739 100644 (file)
@@ -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<TypeIdPair, CpuSet*, TypeIdPairComparer> thread_affinity;
     std::map<std::string, CpuSet*> named_thread_affinity;
+    std::map<int, int> instance_id_to_tid;
 };
 }