Go to the documentation of this file.
26 #define _THREAD_AFFINITY
37 .
name =
"receive-cpu-set",
43 .name =
"worker-cpu-set",
49 .name =
"verdict-cpu-set",
55 .name =
"management-cpu-set",
80 #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun
81 static void AffinitySetupInit(
void)
91 for (j = 0; j < ncpu; j++) {
100 void (*Callback)(
int i,
void * data),
109 if (!strcmp(lnode->
val,
"all")) {
113 }
else if (strchr(lnode->
val,
'-') != NULL) {
114 char *sep = strchr(lnode->
val,
'-');
116 a = strtoul(lnode->
val, &end, 10);
119 "%s: invalid cpu range (start invalid): \"%s\"",
124 b = strtol(sep + 1, &end, 10);
125 if (end != sep + strlen(sep)) {
127 "%s: invalid cpu range (end invalid): \"%s\"",
134 "%s: invalid cpu range (bad order): \"%s\"",
141 "%s: upper bound (%ld) of cpu set is too high, only %d cpu(s)",
147 a = strtoul(lnode->
val, &end, 10);
148 if (end != lnode->
val + strlen(lnode->
val)) {
150 "%s: invalid cpu range (not an integer): \"%s\"",
157 for (i = a; i<= b; i++) {
165 static void AffinityCallback(
int i,
void *data)
167 CPU_SET(i, (cpu_set_t *)data);
170 static void BuildCpuset(
const char *name,
ConfNode *node, cpu_set_t *cpu)
182 #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun
193 SCLogInfo(
"can't get cpu-affinity node");
198 if (strcmp(affinity->
val,
"decode-cpu-set") == 0 ||
199 strcmp(affinity->
val,
"stream-cpu-set") == 0 ||
200 strcmp(affinity->
val,
"reject-cpu-set") == 0 ||
201 strcmp(affinity->
val,
"output-cpu-set") == 0) {
205 const char *setname = affinity->
val;
206 if (strcmp(affinity->
val,
"detect-cpu-set") == 0)
207 setname =
"worker-cpu-set";
216 SCLogConfig(
"Found affinity definition for \"%s\"", setname);
224 BuildCpuset(setname, node, &taf->
cpu_set);
234 SCLogDebug(
"unable to find 'low' prio using default value");
241 SCLogDebug(
"unable to find 'medium' prio using default value");
248 SCLogDebug(
"unable to find 'high' prio using default value");
254 if (!strcmp(node->
val,
"low")) {
256 }
else if (!strcmp(node->
val,
"medium")) {
258 }
else if (!strcmp(node->
val,
"high")) {
263 SCLogConfig(
"Using default prio '%s' for set '%s'",
270 if (!strcmp(node->
val,
"exclusive")) {
272 }
else if (!strcmp(node->
val,
"balanced")) {
283 "count: '%s'", node->
val);
300 #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun
304 while (!CPU_ISSET(ncpu, &taf->
cpu_set) && iter < 2) {
313 "available cpus, cpu affinity conf is invalid");
315 taf->
lcpu = ncpu + 1;
319 SCLogDebug(
"Setting affinity on CPU %d", ncpu);
struct HtpBodyChunk_ * next
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
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)
@ SC_ERR_INVALID_ARGUMENT
#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]
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
#define FatalError(x,...)
void AffinitySetupLoadFromConfig()
Extract cpu affinity configuration from current config file.
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
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.