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++) {
99 void (*Callback)(
int i,
void * data),
108 if (!strcmp(lnode->
val,
"all")) {
112 }
else if (strchr(lnode->
val,
'-') != NULL) {
113 char *sep = strchr(lnode->
val,
'-');
115 a = strtoul(lnode->
val, &end, 10);
117 SCLogError(
"%s: invalid cpu range (start invalid): \"%s\"", name, lnode->
val);
120 b = strtol(sep + 1, &end, 10);
121 if (end != sep + strlen(sep)) {
122 SCLogError(
"%s: invalid cpu range (end invalid): \"%s\"", name, lnode->
val);
126 SCLogError(
"%s: invalid cpu range (bad order): \"%s\"", name, lnode->
val);
130 SCLogError(
"%s: upper bound (%ld) of cpu set is too high, only %d cpu(s)", name, b,
135 a = strtoul(lnode->
val, &end, 10);
136 if (end != lnode->
val + strlen(lnode->
val)) {
137 SCLogError(
"%s: invalid cpu range (not an integer): \"%s\"", name, lnode->
val);
142 for (i = a; i<= b; i++) {
150 static void AffinityCallback(
int i,
void *data)
152 CPU_SET(i, (cpu_set_t *)data);
155 static void BuildCpuset(
const char *name,
ConfNode *node, cpu_set_t *cpu)
167 #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun
178 SCLogInfo(
"can't get cpu-affinity node");
183 if (strcmp(affinity->
val,
"decode-cpu-set") == 0 ||
184 strcmp(affinity->
val,
"stream-cpu-set") == 0 ||
185 strcmp(affinity->
val,
"reject-cpu-set") == 0 ||
186 strcmp(affinity->
val,
"output-cpu-set") == 0) {
190 const char *setname = affinity->
val;
191 if (strcmp(affinity->
val,
"detect-cpu-set") == 0)
192 setname =
"worker-cpu-set";
201 SCLogConfig(
"Found affinity definition for \"%s\"", setname);
209 BuildCpuset(setname, node, &taf->
cpu_set);
219 SCLogDebug(
"unable to find 'low' prio using default value");
226 SCLogDebug(
"unable to find 'medium' prio using default value");
233 SCLogDebug(
"unable to find 'high' prio using default value");
239 if (!strcmp(node->
val,
"low")) {
241 }
else if (!strcmp(node->
val,
"medium")) {
243 }
else if (!strcmp(node->
val,
"high")) {
248 SCLogConfig(
"Using default prio '%s' for set '%s'",
255 if (!strcmp(node->
val,
"exclusive")) {
257 }
else if (!strcmp(node->
val,
"balanced")) {
286 #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun
290 while (!CPU_ISSET(ncpu, &taf->
cpu_set) && iter < 2) {
299 "available cpus, cpu affinity conf is invalid");
301 taf->
lcpu = ncpu + 1;
305 SCLogDebug(
"Setting affinity on CPU %d", ncpu);
void AffinitySetupLoadFromConfig(void)
Extract cpu affinity configuration from current config file.
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)
#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.