]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2589 in SNORT/snort3 from ~MASHASAN/snort3:log_tid to master
authorMasud Hasan (mashasan) <mashasan@cisco.com>
Thu, 29 Oct 2020 20:00:13 +0000 (20:00 +0000)
committerMasud Hasan (mashasan) <mashasan@cisco.com>
Thu, 29 Oct 2020 20:00:13 +0000 (20:00 +0000)
Squashed commit of the following:

commit 79590d9aa276ef75ad2d58ec0b5772fe852a43ef
Author: Masud Hasan <mashasan@cisco.com>
Date:   Tue Oct 27 15:17:04 2020 -0400

    thread_config: Show thread id when logging binding information

src/main/thread_config.cc

index e7859b140c97b44f932bd6322bb517e35be08386..879ebb916f65a28cc915fc01fe040070f9d2b750 100644 (file)
@@ -33,6 +33,7 @@
 #endif
 
 using namespace snort;
+using namespace std;
 
 static hwloc_topology_t topology = nullptr;
 static hwloc_cpuset_t process_cpuset = nullptr;
@@ -144,7 +145,7 @@ void ThreadConfig::set_thread_affinity(SThreadType type, unsigned id, CpuSet* cp
         ParseWarning(WARN_CONF, "This platform does not support setting thread affinity.\n");
 }
 
-void ThreadConfig::set_named_thread_affinity(const std::string& name, CpuSet* cpuset)
+void ThreadConfig::set_named_thread_affinity(const string& name, CpuSet* cpuset)
 {
     if (topology_support->cpubind->set_thisthread_cpubind)
     {
@@ -157,6 +158,19 @@ void ThreadConfig::set_named_thread_affinity(const std::string& name, CpuSet* cp
         ParseWarning(WARN_CONF, "This platform does not support setting thread affinity.\n");
 }
 
+static inline string stringify_thread(const SThreadType& type, const unsigned& id)
+{
+    string info;
+    if ( type == STHREAD_TYPE_MAIN )
+        info = "main thread ";
+    else if ( type == STHREAD_TYPE_PACKET )
+        info = "packet thread ";
+    else
+        info = "other thread ";
+    info += to_string(id) + " (TID " + to_string((int)gettid()) + ")";
+    return info;
+}
+
 void ThreadConfig::implement_thread_affinity(SThreadType type, unsigned id)
 {
     if (!topology_support->cpubind->set_thisthread_cpubind)
@@ -179,19 +193,19 @@ void ThreadConfig::implement_thread_affinity(SThreadType type, unsigned id)
     current_cpuset = hwloc_bitmap_alloc();
     hwloc_get_cpubind(topology, current_cpuset, HWLOC_CPUBIND_THREAD);
     if (!hwloc_bitmap_isequal(current_cpuset, desired_cpuset))
-        LogMessage("Binding thread %u (type %u) to %s.\n", id, type, s);
+        LogMessage("Binding %s to CPU %s.\n", stringify_thread(type, id).c_str(), s);
     hwloc_bitmap_free(current_cpuset);
 
     if (hwloc_set_cpubind(topology, desired_cpuset, HWLOC_CPUBIND_THREAD))
     {
-        FatalError("Failed to pin thread %u (type %u) to %s: %s (%d)\n",
-            id, type, s, get_error(errno), errno);
+        FatalError("Failed to pin %s to CPU %s: %s (%d)\n",
+            stringify_thread(type, id).c_str(), s, get_error(errno), errno);
     }
 
     free(s);
 }
 
-void ThreadConfig::implement_named_thread_affinity(const std::string& name)
+void ThreadConfig::implement_named_thread_affinity(const string& name)
 {
     if (!topology_support->cpubind->set_thisthread_cpubind)
         return;