Go to the documentation of this file.
26 #define _THREAD_AFFINITY
36 .
name =
"receive-cpu-set",
42 .name =
"worker-cpu-set",
48 .name =
"verdict-cpu-set",
54 .name =
"management-cpu-set",
79 #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun
80 static void AffinitySetupInit(
void)
90 for (j = 0; j < ncpu; j++) {
98 const char *
name,
SCConfNode *node,
void (*Callback)(
int i,
void *data),
void *data)
109 if (!strcmp(lnode->
val,
"all")) {
113 }
else if (strchr(lnode->
val,
'-') != NULL) {
114 char *sep = strchr(lnode->
val,
'-');
128 SCLogError(
"%s: upper bound (%d) of cpu set is too high, only %d cpu(s)",
name, b,
138 for (i = a; i<= b; i++) {
146 static void AffinityCallback(
int i,
void *data)
148 CPU_SET(i, (cpu_set_t *)data);
151 static void BuildCpuset(
const char *
name,
SCConfNode *node, cpu_set_t *cpu)
163 #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun
174 SCLogInfo(
"can't get cpu-affinity node");
179 if (strcmp(affinity->
val,
"decode-cpu-set") == 0 ||
180 strcmp(affinity->
val,
"stream-cpu-set") == 0 ||
181 strcmp(affinity->
val,
"reject-cpu-set") == 0 ||
182 strcmp(affinity->
val,
"output-cpu-set") == 0) {
186 const char *setname = affinity->
val;
187 if (strcmp(affinity->
val,
"detect-cpu-set") == 0)
188 setname =
"worker-cpu-set";
197 SCLogConfig(
"Found affinity definition for \"%s\"", setname);
205 BuildCpuset(setname, node, &taf->
cpu_set);
215 SCLogDebug(
"unable to find 'low' prio using default value");
222 SCLogDebug(
"unable to find 'medium' prio using default value");
229 SCLogDebug(
"unable to find 'high' prio using default value");
235 if (!strcmp(node->
val,
"low")) {
237 }
else if (!strcmp(node->
val,
"medium")) {
239 }
else if (!strcmp(node->
val,
"high")) {
244 SCLogConfig(
"Using default prio '%s' for set '%s'",
251 if (!strcmp(node->
val,
"exclusive")) {
253 }
else if (!strcmp(node->
val,
"balanced")) {
282 #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun
286 while (!CPU_ISSET(ncpu, &taf->
cpu_set) && iter < 2) {
295 "available cpus, cpu affinity conf is invalid");
297 taf->
lcpu = ncpu + 1;
301 SCLogDebug(
"Setting affinity on CPU %d", ncpu);
309 #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun
312 if (CPU_ISSET(i, &taf->
cpu_set))
339 if (CPU_ISSET(i, &tmpcset))
void AffinitySetupLoadFromConfig(void)
Extract cpu affinity configuration from current config file.
void BuildCpusetWithCallback(const char *name, SCConfNode *node, void(*Callback)(int i, void *data), void *data)
struct HtpBodyChunk_ * next
uint16_t UtilAffinityGetAffinedCPUNum(ThreadsAffinityType *taf)
uint16_t UtilCpuGetNumProcessorsConfigured(void)
Get the number of cpus configured in the system.
#define TAILQ_FOREACH(var, head, field)
uint16_t AffinityGetNextCPU(ThreadsAffinityType *taf)
Return next cpu to use for a given thread family.
#define SCMutexUnlock(mut)
int StringParseUint32(uint32_t *res, int base, size_t len, const char *str)
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
#define SCMutexInit(mut, mutattrs)
SCConfNode * SCConfNodeLookupChild(const SCConfNode *node, const char *name)
Lookup a child configuration node by name.
ThreadsAffinityType thread_affinity[MAX_CPU_SET]
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
SCConfNode * SCConfGetNode(const char *name)
Get a SCConfNode by name.
#define SCLogError(...)
Macro used to log ERROR messages.
int thread_affinity_init_done
ThreadsAffinityType * GetAffinityTypeFromName(const char *name)
find affinity by its name
uint16_t UtilCpuGetNumProcessorsOnline(void)
Get the number of cpus online in the system.