affinity: change config format and misc fixes

This patch fixes some problem with affinity work and modify the
configuration file format.

For example, the detect cup set can be formatted as follow:
     - detect_cpu_set:
        cpu: [ "all" ]
        mode: "exclusive" # run detect threads in these cpus
        prio:
          low: [ 0 ] # threads on CPU 0 have low prio
          medium: [ "1-2" ] # threads on CPU 1 and 2 have medium prio
          high: [ 3 ] # threads on CPU 3 have high prio
          default: "medium" #default priority is "medium"
remotes/origin/master-1.1.x
Eric Leblond 14 years ago committed by Victor Julien
parent 2600d203cc
commit 0b5e5b8772

@ -124,7 +124,7 @@ static void build_cpuset(ConfNode *node, cpu_set_t *cpu)
int stop = 0;
if (!strcmp(lnode->val, "all")) {
a = 0;
b = UtilCpuGetNumProcessorsConfigured();
b = UtilCpuGetNumProcessorsOnline() - 1;
stop = 1;
} else if (index(lnode->val, '-') != NULL) {
char *sep = index(lnode->val, '-');
@ -188,6 +188,7 @@ void AffinitySetupLoadFromConfig()
TAILQ_FOREACH(affinity, &root->head, next) {
ThreadsAffinityType *taf = GetAffinityTypeFromName(affinity->val);
ConfNode *node = NULL;
ConfNode *nprio = NULL;
if (taf == NULL) {
SCLogError(SC_ERR_INVALID_ARGUMENT, "unknown cpu_affinity type");
@ -206,29 +207,45 @@ void AffinitySetupLoadFromConfig()
}
CPU_ZERO(&taf->lowprio_cpu);
node = ConfNodeLookupChild(affinity->head.tqh_first, "low_prio");
if (node == NULL) {
SCLogDebug("unable to find 'low_prio' using default value");
} else {
build_cpuset(node, &taf->lowprio_cpu);
}
CPU_ZERO(&taf->medprio_cpu);
node = ConfNodeLookupChild(affinity->head.tqh_first, "medium_prio");
if (node == NULL) {
SCLogDebug("unable to find 'medium_prio' using default value");
} else {
build_cpuset(node, &taf->medprio_cpu);
}
CPU_ZERO(&taf->hiprio_cpu);
node = ConfNodeLookupChild(affinity->head.tqh_first, "high_prio");
if (node == NULL) {
SCLogDebug("unable to find 'high_prio' using default value");
} else {
build_cpuset(node, &taf->hiprio_cpu);
}
nprio = ConfNodeLookupChild(affinity->head.tqh_first, "prio");
if (nprio != NULL) {
node = ConfNodeLookupChild(nprio, "low");
if (node == NULL) {
SCLogDebug("unable to find 'low' prio using default value");
} else {
build_cpuset(node, &taf->lowprio_cpu);
}
node = ConfNodeLookupChild(nprio, "medium");
if (node == NULL) {
SCLogDebug("unable to find 'medium' prio using default value");
} else {
build_cpuset(node, &taf->medprio_cpu);
}
node = ConfNodeLookupChild(nprio, "high");
if (node == NULL) {
SCLogDebug("unable to find 'high' prio using default value");
} else {
build_cpuset(node, &taf->hiprio_cpu);
}
node = ConfNodeLookupChild(nprio, "default");
if (node != NULL) {
if (!strcmp(node->val, "low")) {
taf->prio = PRIO_LOW;
} else if (!strcmp(node->val, "medium")) {
taf->prio = PRIO_MEDIUM;
} else if (!strcmp(node->val, "high")) {
taf->prio = PRIO_HIGH;
} else {
SCLogError(SC_ERR_INVALID_ARGUMENT, "unknown cpu_affinity prio");
exit(EXIT_FAILURE);
}
SCLogInfo("Using default prio '%s'", node->val);
}
}
node = ConfNodeLookupChild(affinity->head.tqh_first, "mode");
if (node != NULL) {
@ -242,20 +259,6 @@ void AffinitySetupLoadFromConfig()
}
}
node = ConfNodeLookupChild(affinity->head.tqh_first, "prio");
if (node != NULL) {
if (!strcmp(node->val, "low")) {
taf->prio = PRIO_LOW;
} else if (!strcmp(node->val, "medium")) {
taf->prio = PRIO_MEDIUM;
} else if (!strcmp(node->val, "high")) {
taf->prio = PRIO_HIGH;
} else {
SCLogError(SC_ERR_INVALID_ARGUMENT, "unknown cpu_affinity prio");
exit(EXIT_FAILURE);
}
}
node = ConfNodeLookupChild(affinity->head.tqh_first, "threads");
if (node != NULL) {
taf->nb_threads = atoi(node->val);

@ -47,7 +47,7 @@ typedef struct ThreadsAffinityType_ {
char *name;
cpu_set_t cpu_set;
uint8_t mode_flag;
uint8_t prio;
int prio;
int nb_threads;
cpu_set_t lowprio_cpu;
cpu_set_t medprio_cpu;

@ -188,19 +188,23 @@ threading:
- detect_cpu_set:
cpu: [ "all" ]
mode: "exclusive" # run detect threads in these cpus
low_prio: [ 0 ]
medium_prio: [ "1-2" ]
high_prio: [ 3 ]
prio: "medium"
prio:
low: [ 0 ]
medium: [ "1-2" ]
high: [ 3 ]
default: "medium"
- verdict_cpu_set:
cpu: [ 0 ]
prio: "high"
prio:
default: "high"
- reject_cpu_set:
cpu: [ 0 ]
prio: "low"
prio:
default: "low"
- output_cpu_set:
cpu: [ "all" ]
prio: "medium"
prio:
default: "medium"
#
# By default Suricata creates one "detect" thread per available CPU/CPU core.
# This setting allows controlling this behaviour. A ratio setting of 2 will

Loading…
Cancel
Save