Some updates to add Solaris thread/cpu affinity. More work is needed on util-affinity.c which I'll tack on later.
--- ../../suricata-master.orig/src/threads.h 2013-12-01 21:37:52.000000000 +1100
+++ threads.h 2013-12-04 15:00:59.382631457 +1100
@@ -218,6 +218,13 @@
u_long tid = (u_long)tmpthid; \
tid; \
})
+#elif OS_SOLARIS
+#define SCGetThreadIdLong(...) ({ \
+ pthread_t tpid; \
+ tpid = pthread_self(); \
+ u_long tid = (u_long)tpid; \
+ tid; \
+})
#elif __OpenBSD__
#define SCGetThreadIdLong(...) ({ \
pid_t tpid; \
--- ../../suricata-master.orig/src/tm-threads.c 2013-12-01 21:37:52.000000000 +1100
+++ tm-threads.c 2013-12-04 15:12:31.613134151 +1100
@@ -70,6 +70,12 @@
#define cpu_set_t cpuset_t
#endif /* OS_FREEBSD */
+#if defined(OS_SOLARIS)
+#include <sys/types.h>
+#include <sys/processor.h>
+#include <sys/procset.h>
+#endif /* SO_SOLARIS */
+
/* prototypes */
static int SetCPUAffinity(uint16_t cpu);
@@ -1143,7 +1149,7 @@
return NULL;
}
-#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__
+#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined(OS_SOLARIS)
static int SetCPUAffinitySet(cpu_set_t *cs) {
#if defined OS_FREEBSD
int r = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID,
@@ -1195,6 +1201,15 @@
return 0;
+#elif defined(OS_SOLARIS)
+ u_long my_thr_id = SCGetThreadIdLong();
+ int rc = processor_bind(P_MYID, my_thr_id, cpuid, 0);
+ if (rc != 0) {
+ printf("Warning: sched_setaffinity failed (%" PRId32 "): %s\n", rc, strerror(errno));
+ return -1;
+ }
+ SCLogDebug("CPU Affinity for thread %lu set to CPU %" PRId16, SCGetThreadIdLong(), cpuid);
+ return 0;
#else
cpu_set_t cs;
@@ -1309,7 +1324,7 @@
SetCPUAffinity(tv->cpu_affinity);
}
-#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__
+#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined(OS_SOLARIS)
if (tv->thread_setup_flags & THREAD_SET_PRIORITY)
TmThreadSetPrio(tv);
if (tv->thread_setup_flags & THREAD_SET_AFFTYPE) {
--- ../../suricata-master.orig/src/util-affinity.h 2013-12-01 21:37:52.000000000 +1100
+++ util-affinity.h 2013-12-03 11:54:43.138628057 +1100
@@ -66,13 +66,13 @@
typedef struct ThreadsAffinityType_ {
char *name;
-#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__
+#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined __sun
cpu_set_t cpu_set;
#endif
uint8_t mode_flag;
int prio;
int nb_threads;
-#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__
+#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined __sun
cpu_set_t lowprio_cpu;
cpu_set_t medprio_cpu;
cpu_set_t hiprio_cpu;