From: Masud Hasan (mashasan) Date: Thu, 29 Oct 2020 20:00:13 +0000 (+0000) Subject: Merge pull request #2589 in SNORT/snort3 from ~MASHASAN/snort3:log_tid to master X-Git-Tag: 3.0.3-5~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0dc8a9bb58b7e71c0c83458464859b69fccfe83a;p=thirdparty%2Fsnort3.git Merge pull request #2589 in SNORT/snort3 from ~MASHASAN/snort3:log_tid to master Squashed commit of the following: commit 79590d9aa276ef75ad2d58ec0b5772fe852a43ef Author: Masud Hasan Date: Tue Oct 27 15:17:04 2020 -0400 thread_config: Show thread id when logging binding information --- diff --git a/src/main/thread_config.cc b/src/main/thread_config.cc index e7859b140..879ebb916 100644 --- a/src/main/thread_config.cc +++ b/src/main/thread_config.cc @@ -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;