]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
thread_config: Only log when actually changing thread affinity
authorMichael Altizer <mialtize@cisco.com>
Tue, 29 Mar 2016 16:04:03 +0000 (12:04 -0400)
committerMichael Altizer <mialtize@cisco.com>
Wed, 13 Apr 2016 20:06:27 +0000 (16:06 -0400)
src/main/thread_config.cc

index ca43597b4173118b3b0fd03db12171ad92f66729..e2128c1bed00318b2289caa1841daa1113483d04 100644 (file)
@@ -140,24 +140,28 @@ void ThreadConfig::implement_thread_affinity(SThreadType type, unsigned id)
         return;
 
     TypeIdPair key { type, id };
-    hwloc_cpuset_t desired_cpuset;
+    hwloc_cpuset_t current_cpuset, desired_cpuset;
+    char* s;
 
     auto iter = thread_affinity.find(key);
     if (iter != thread_affinity.end())
         desired_cpuset = iter->second->cpuset;
     else
         desired_cpuset = process_cpuset;
-
-    char* s;
     hwloc_bitmap_list_asprintf(&s, desired_cpuset);
+
+    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);
+    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);
     }
-#ifndef REG_TEST
-    LogMessage("Bound thread %u (type %u) to %s.\n", id, type, s);
-#endif
+
     free(s);
 }