affinity: small cleanups to output & code

pull/2137/head
Victor Julien 9 years ago
parent 5f9de1e734
commit b5633b9bfd

@ -1026,8 +1026,9 @@ void TmThreadSetPrio(ThreadVars *tv)
#else #else
int ret = nice(tv->thread_priority); int ret = nice(tv->thread_priority);
if (ret == -1) { if (ret == -1) {
SCLogError(SC_ERR_THREAD_NICE_PRIO, "Error setting nice value " SCLogError(SC_ERR_THREAD_NICE_PRIO, "Error setting nice value %d "
"for thread %s: %s", tv->name, strerror(errno)); "for thread %s: %s", tv->thread_priority, tv->name,
strerror(errno));
} else { } else {
SCLogDebug("Nice value set to %"PRId32" for thread %s", SCLogDebug("Nice value set to %"PRId32" for thread %s",
tv->thread_priority, tv->name); tv->thread_priority, tv->name);
@ -1090,7 +1091,7 @@ int TmThreadGetNbThreads(uint8_t type)
TmEcode TmThreadSetupOptions(ThreadVars *tv) TmEcode TmThreadSetupOptions(ThreadVars *tv)
{ {
if (tv->thread_setup_flags & THREAD_SET_AFFINITY) { if (tv->thread_setup_flags & THREAD_SET_AFFINITY) {
SCLogInfo("Setting affinity for \"%s\" Module to cpu/core " SCLogPerf("Setting affinity for thread \"%s\"to cpu/core "
"%"PRIu16", thread id %lu", tv->name, tv->cpu_affinity, "%"PRIu16", thread id %lu", tv->name, tv->cpu_affinity,
SCGetThreadIdLong()); SCGetThreadIdLong());
SetCPUAffinity(tv->cpu_affinity); SetCPUAffinity(tv->cpu_affinity);
@ -1114,14 +1115,14 @@ TmEcode TmThreadSetupOptions(ThreadVars *tv)
} else { } else {
tv->thread_priority = taf->prio; tv->thread_priority = taf->prio;
} }
SCLogInfo("Setting prio %d for \"%s\" Module to cpu/core " SCLogPerf("Setting prio %d for thread \"%s\" to cpu/core "
"%d, thread id %lu", tv->thread_priority, "%d, thread id %lu", tv->thread_priority,
tv->name, cpu, SCGetThreadIdLong()); tv->name, cpu, SCGetThreadIdLong());
} else { } else {
SetCPUAffinitySet(&taf->cpu_set); SetCPUAffinitySet(&taf->cpu_set);
tv->thread_priority = taf->prio; tv->thread_priority = taf->prio;
SCLogInfo("Setting prio %d for \"%s\" thread " SCLogPerf("Setting prio %d for thread \"%s\", "
", thread id %lu", tv->thread_priority, "thread id %lu", tv->thread_priority,
tv->name, SCGetThreadIdLong()); tv->name, SCGetThreadIdLong());
} }
TmThreadSetPrio(tv); TmThreadSetPrio(tv);

@ -1,4 +1,4 @@
/* Copyright (C) 2010 Open Information Security Foundation /* Copyright (C) 2010-2016 Open Information Security Foundation
* *
* You can copy, redistribute or modify this Program under the terms of * You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free * the GNU General Public License version 2 as published by the Free
@ -95,7 +95,7 @@ static void AffinitySetupInit()
return; return;
} }
static void build_cpuset(const char *name, ConfNode *node, cpu_set_t *cpu) static void BuildCpuset(const char *name, ConfNode *node, cpu_set_t *cpu)
{ {
ConfNode *lnode; ConfNode *lnode;
TAILQ_FOREACH(lnode, &node->head, next) { TAILQ_FOREACH(lnode, &node->head, next) {
@ -201,8 +201,7 @@ void AffinitySetupLoadFromConfig()
SCLogError(SC_ERR_INVALID_ARGUMENT, "unknown cpu-affinity type"); SCLogError(SC_ERR_INVALID_ARGUMENT, "unknown cpu-affinity type");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} else { } else {
SCLogInfo("Found affinity definition for \"%s\"", SCLogConfig("Found affinity definition for \"%s\"", setname);
setname);
} }
CPU_ZERO(&taf->cpu_set); CPU_ZERO(&taf->cpu_set);
@ -210,7 +209,7 @@ void AffinitySetupLoadFromConfig()
if (node == NULL) { if (node == NULL) {
SCLogInfo("unable to find 'cpu'"); SCLogInfo("unable to find 'cpu'");
} else { } else {
build_cpuset(setname, node, &taf->cpu_set); BuildCpuset(setname, node, &taf->cpu_set);
} }
CPU_ZERO(&taf->lowprio_cpu); CPU_ZERO(&taf->lowprio_cpu);
@ -222,21 +221,21 @@ void AffinitySetupLoadFromConfig()
if (node == NULL) { if (node == NULL) {
SCLogDebug("unable to find 'low' prio using default value"); SCLogDebug("unable to find 'low' prio using default value");
} else { } else {
build_cpuset(setname, node, &taf->lowprio_cpu); BuildCpuset(setname, node, &taf->lowprio_cpu);
} }
node = ConfNodeLookupChild(nprio, "medium"); node = ConfNodeLookupChild(nprio, "medium");
if (node == NULL) { if (node == NULL) {
SCLogDebug("unable to find 'medium' prio using default value"); SCLogDebug("unable to find 'medium' prio using default value");
} else { } else {
build_cpuset(setname, node, &taf->medprio_cpu); BuildCpuset(setname, node, &taf->medprio_cpu);
} }
node = ConfNodeLookupChild(nprio, "high"); node = ConfNodeLookupChild(nprio, "high");
if (node == NULL) { if (node == NULL) {
SCLogDebug("unable to find 'high' prio using default value"); SCLogDebug("unable to find 'high' prio using default value");
} else { } else {
build_cpuset(setname, node, &taf->hiprio_cpu); BuildCpuset(setname, node, &taf->hiprio_cpu);
} }
node = ConfNodeLookupChild(nprio, "default"); node = ConfNodeLookupChild(nprio, "default");
if (node != NULL) { if (node != NULL) {
@ -250,7 +249,8 @@ void AffinitySetupLoadFromConfig()
SCLogError(SC_ERR_INVALID_ARGUMENT, "unknown cpu_affinity prio"); SCLogError(SC_ERR_INVALID_ARGUMENT, "unknown cpu_affinity prio");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
SCLogInfo("Using default prio '%s'", node->val); SCLogConfig("Using default prio '%s' for set '%s'",
node->val, setname);
} }
} }
@ -285,7 +285,6 @@ void AffinitySetupLoadFromConfig()
int AffinityGetNextCPU(ThreadsAffinityType *taf) int AffinityGetNextCPU(ThreadsAffinityType *taf)
{ {
int ncpu = 0; int ncpu = 0;
#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__
int iter = 0; int iter = 0;
SCMutexLock(&taf->taf_mutex); SCMutexLock(&taf->taf_mutex);
@ -298,13 +297,14 @@ int AffinityGetNextCPU(ThreadsAffinityType *taf)
} }
} }
if (iter == 2) { if (iter == 2) {
SCLogError(SC_ERR_INVALID_ARGUMENT, "cpu_set does not contain available cpus, cpu affinity conf is invalid"); SCLogError(SC_ERR_INVALID_ARGUMENT, "cpu_set does not contain "
"available cpus, cpu affinity conf is invalid");
} }
taf->lcpu = ncpu + 1; taf->lcpu = ncpu + 1;
if (taf->lcpu >= UtilCpuGetNumProcessorsOnline()) if (taf->lcpu >= UtilCpuGetNumProcessorsOnline())
taf->lcpu = 0; taf->lcpu = 0;
SCMutexUnlock(&taf->taf_mutex); SCMutexUnlock(&taf->taf_mutex);
SCLogInfo("Setting affinity on CPU %d", ncpu); SCLogDebug("Setting affinity on CPU %d", ncpu);
#endif /* OS_WIN32 and __OpenBSD__ */ #endif /* OS_WIN32 and __OpenBSD__ */
return ncpu; return ncpu;
} }

Loading…
Cancel
Save