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),
107 if (!strcmp(lnode->
val,
"all")) {
111 }
else if (strchr(lnode->
val,
'-') != NULL) {
112 char *sep = strchr(lnode->
val,
'-');
114 a = strtoul(lnode->
val, &end, 10);
116 SCLogError(
"%s: invalid cpu range (start invalid): \"%s\"", name, lnode->
val);
119 b = strtol(sep + 1, &end, 10);
120 if (end != sep + strlen(sep)) {
121 SCLogError(
"%s: invalid cpu range (end invalid): \"%s\"", name, lnode->
val);
125 SCLogError(
"%s: invalid cpu range (bad order): \"%s\"", name, lnode->
val);
129 SCLogError(
"%s: upper bound (%ld) of cpu set is too high, only %d cpu(s)", name, b,
134 a = strtoul(lnode->
val, &end, 10);
135 if (end != lnode->
val + strlen(lnode->
val)) {
136 SCLogError(
"%s: invalid cpu range (not an integer): \"%s\"", name, lnode->
val);
141 for (i = a; i<= b; i++) {
149 static void AffinityCallback(
int i,
void *data)
151 CPU_SET(i, (cpu_set_t *)data);
154 static void BuildCpuset(
const char *name,
ConfNode *node, cpu_set_t *cpu)
166 #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun
177 SCLogInfo(
"can't get cpu-affinity node");
182 if (strcmp(affinity->
val,
"decode-cpu-set") == 0 ||
183 strcmp(affinity->
val,
"stream-cpu-set") == 0 ||
184 strcmp(affinity->
val,
"reject-cpu-set") == 0 ||
185 strcmp(affinity->
val,
"output-cpu-set") == 0) {
189 const char *setname = affinity->
val;
190 if (strcmp(affinity->
val,
"detect-cpu-set") == 0)
191 setname =
"worker-cpu-set";
200 SCLogConfig(
"Found affinity definition for \"%s\"", setname);
208 BuildCpuset(setname, node, &taf->
cpu_set);
218 SCLogDebug(
"unable to find 'low' prio using default value");
225 SCLogDebug(
"unable to find 'medium' prio using default value");
232 SCLogDebug(
"unable to find 'high' prio using default value");
238 if (!strcmp(node->
val,
"low")) {
240 }
else if (!strcmp(node->
val,
"medium")) {
242 }
else if (!strcmp(node->
val,
"high")) {
247 SCLogConfig(
"Using default prio '%s' for set '%s'",
254 if (!strcmp(node->
val,
"exclusive")) {
256 }
else if (!strcmp(node->
val,
"balanced")) {
285 #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun
289 while (!CPU_ISSET(ncpu, &taf->
cpu_set) && iter < 2) {
298 "available cpus, cpu affinity conf is invalid");
300 taf->
lcpu = ncpu + 1;
304 SCLogDebug(
"Setting affinity on CPU %d", ncpu);
312 #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun
315 if (CPU_ISSET(i, &taf->
cpu_set))
342 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.