hwloc_cpuset_t current_cpuset, desired_cpuset;
char* s;
+ std::string thread_name_suffix;
+ std::string thread_name;
+
auto iter = thread_affinity.find(key);
if (iter != thread_affinity.end())
desired_cpuset = iter->second->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 %s to CPU %s.\n", stringify_thread(type, id).c_str(), s);
+ thread_name_suffix = ".core-";
+ thread_name_suffix.append(s);
+ }
+ else
+ {
+ thread_name_suffix = ".ins-";
+ thread_name_suffix.append(std::to_string(id));
+ }
+
+ // Thread name is snort.ins-X for unpinned threads, and snort.core-X
+ // for threads pinned to CPU x
+ if (type == STHREAD_TYPE_MAIN)
+ {
+ thread_name = "snort3";
+ thread_name_suffix = "";
+ }
+ else
+ {
+ thread_name = "snort";
+ }
+
+ thread_name.append(thread_name_suffix);
+ SET_THREAD_NAME(pthread_self(), thread_name.c_str());
+
hwloc_bitmap_free(current_cpuset);
if (hwloc_set_cpubind(topology, desired_cpuset, HWLOC_CPUBIND_THREAD))
#include "main/snort_types.h"
+// Note: thread names > 15 chars aren't supported on most systems
+#if defined(__linux__)
+ #include <pthread.h>
+ #define SET_THREAD_NAME(thread, name) \
+ pthread_setname_np(thread, name)
+
+#elif defined(__OpenBSD__) || defined(__FreeBSD__)
+ #include <pthread_np.h>
+ #define SET_THREAD_NAME(thread, name) \
+ pthread_set_name_np(thread, name)
+
+#else
+ #define SET_THREAD_NAME(thread, name) \
+ UNUSED(thread);\
+ UNUSED(name);
+
+#endif
+
#define TIMEBUF_SIZE 27
#define SECONDS_PER_DAY 86400 /* number of seconds in a day */