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 void (*Callback)(
int i,
void * data),
110 if (!strcmp(lnode->
val,
"all")) {
114 }
else if (strchr(lnode->
val,
'-') != NULL) {
115 char *sep = strchr(lnode->
val,
'-');
129 SCLogError(
"%s: upper bound (%d) of cpu set is too high, only %d cpu(s)",
name, b,
139 for (i = a; i<= b; i++) {
147 static void AffinityCallback(
int i,
void *data)
149 CPU_SET(i, (cpu_set_t *)data);
152 static void BuildCpuset(
const char *
name,
ConfNode *node, cpu_set_t *cpu)
164 #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun
175 SCLogInfo(
"can't get cpu-affinity node");
180 if (strcmp(affinity->
val,
"decode-cpu-set") == 0 ||
181 strcmp(affinity->
val,
"stream-cpu-set") == 0 ||
182 strcmp(affinity->
val,
"reject-cpu-set") == 0 ||
183 strcmp(affinity->
val,
"output-cpu-set") == 0) {
187 const char *setname = affinity->
val;
188 if (strcmp(affinity->
val,
"detect-cpu-set") == 0)
189 setname =
"worker-cpu-set";
198 SCLogConfig(
"Found affinity definition for \"%s\"", setname);
206 BuildCpuset(setname, node, &taf->
cpu_set);
216 SCLogDebug(
"unable to find 'low' prio using default value");
223 SCLogDebug(
"unable to find 'medium' prio using default value");
230 SCLogDebug(
"unable to find 'high' prio using default value");
236 if (!strcmp(node->
val,
"low")) {
238 }
else if (!strcmp(node->
val,
"medium")) {
240 }
else if (!strcmp(node->
val,
"high")) {
245 SCLogConfig(
"Using default prio '%s' for set '%s'",
252 if (!strcmp(node->
val,
"exclusive")) {
254 }
else if (!strcmp(node->
val,
"balanced")) {
283 #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun
287 while (!CPU_ISSET(ncpu, &taf->
cpu_set) && iter < 2) {
296 "available cpus, cpu affinity conf is invalid");
298 taf->
lcpu = ncpu + 1;
302 SCLogDebug(
"Setting affinity on CPU %d", ncpu);
310 #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun
313 if (CPU_ISSET(i, &taf->
cpu_set))
340 if (CPU_ISSET(i, &tmpcset))
void AffinitySetupLoadFromConfig(void)
Extract cpu affinity configuration from current config file.
struct HtpBodyChunk_ * next
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
uint16_t UtilAffinityGetAffinedCPUNum(ThreadsAffinityType *taf)
void BuildCpusetWithCallback(const char *name, ConfNode *node, void(*Callback)(int i, void *data), void *data)
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)
ConfNode * ConfNodeLookupChild(const ConfNode *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.
#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.