threading: let cpu set building callback return a value

pull/13397/head
Lukas Sismis 1 year ago committed by Victor Julien
parent 8817a959e8
commit ba7a42b4eb

@ -222,7 +222,7 @@ static void AffinitySetupInit(void)
}
}
void BuildCpusetWithCallback(
int BuildCpusetWithCallback(
const char *name, SCConfNode *node, void (*Callback)(int i, void *data), void *data)
{
SCConfNode *lnode;
@ -242,15 +242,15 @@ void BuildCpusetWithCallback(
char *sep = strchr(lnode->val, '-');
if (StringParseUint32(&a, 10, sep - lnode->val, lnode->val) < 0) {
SCLogError("%s: invalid cpu range (start invalid): \"%s\"", name, lnode->val);
exit(EXIT_FAILURE);
return -1;
}
if (StringParseUint32(&b, 10, strlen(sep) - 1, sep + 1) < 0) {
SCLogError("%s: invalid cpu range (end invalid): \"%s\"", name, lnode->val);
exit(EXIT_FAILURE);
return -1;
}
if (a > b) {
SCLogError("%s: invalid cpu range (bad order): \"%s\"", name, lnode->val);
exit(EXIT_FAILURE);
return -1;
}
if (b > max) {
SCLogError("%s: upper bound (%d) of cpu set is too high, only %d cpu(s)", name, b,
@ -259,7 +259,7 @@ void BuildCpusetWithCallback(
} else {
if (StringParseUint32(&a, 10, strlen(lnode->val), lnode->val) < 0) {
SCLogError("%s: invalid cpu range (not an integer): \"%s\"", name, lnode->val);
exit(EXIT_FAILURE);
return -1;
}
b = a;
}
@ -270,6 +270,7 @@ void BuildCpusetWithCallback(
break;
}
}
return 0;
}
static void AffinityCallback(int i, void *data)
@ -277,9 +278,9 @@ static void AffinityCallback(int i, void *data)
CPU_SET(i, (cpu_set_t *)data);
}
static void BuildCpuset(const char *name, SCConfNode *node, cpu_set_t *cpu)
static int BuildCpuset(const char *name, SCConfNode *node, cpu_set_t *cpu)
{
BuildCpusetWithCallback(name, node, AffinityCallback, (void *) cpu);
return BuildCpusetWithCallback(name, node, AffinityCallback, (void *)cpu);
}
/**
@ -303,7 +304,9 @@ static void SetupCpuSets(ThreadsAffinityType *taf, SCConfNode *affinity, const c
CPU_ZERO(&taf->cpu_set);
SCConfNode *cpu_node = SCConfNodeLookupChild(affinity, "cpu");
if (cpu_node != NULL) {
BuildCpuset(setname, cpu_node, &taf->cpu_set);
if (BuildCpuset(setname, cpu_node, &taf->cpu_set) < 0) {
SCLogWarning("Failed to parse CPU set for %s", setname);
}
} else {
SCLogWarning("Unable to find 'cpu' node for set %s", setname);
}
@ -317,7 +320,9 @@ static void BuildPriorityCpuset(ThreadsAffinityType *taf, SCConfNode *prio_node,
{
SCConfNode *node = SCConfNodeLookupChild(prio_node, priority);
if (node != NULL) {
BuildCpuset(setname, node, cpuset);
if (BuildCpuset(setname, node, cpuset) < 0) {
SCLogWarning("Failed to parse %s priority CPU set for %s", priority, setname);
}
} else {
SCLogDebug("Unable to find '%s' priority for set %s", priority, setname);
}

@ -112,7 +112,11 @@ uint16_t UtilAffinityCpusOverlap(ThreadsAffinityType *taf1, ThreadsAffinityType
void UtilAffinityCpusExclude(ThreadsAffinityType *mod_taf, ThreadsAffinityType *static_taf);
#endif /* HAVE_DPDK */
void BuildCpusetWithCallback(
int BuildCpusetWithCallback(
const char *name, SCConfNode *node, void (*Callback)(int i, void *data), void *data);
#ifdef UNITTESTS
void ThreadingAffinityRegisterTests(void);
#endif
#endif /* SURICATA_UTIL_AFFINITY_H */

@ -980,9 +980,10 @@ void EBPFBuildCPUSet(SCConfNode *node, char *iface)
BPF_ANY);
return;
}
BuildCpusetWithCallback("xdp-cpu-redirect", node,
EBPFRedirectMapAddCPU,
iface);
if (BuildCpusetWithCallback("xdp-cpu-redirect", node, EBPFRedirectMapAddCPU, iface) < 0) {
SCLogWarning("Failed to parse XDP CPU redirect configuration");
return;
}
bpf_map_update_elem(mapfd, &key0, &g_redirect_iface_cpu_counter,
BPF_ANY);
}

Loading…
Cancel
Save