From f9e453e14cbf66883d684d72914a16abfba7c86a Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Mon, 24 Jan 2011 13:26:57 +0100 Subject: [PATCH] affinity: Use configured 'threads' value if set This patch modifies runmodes to make them use the new 'threads' variable. Signed-off-by: Eric Leblond --- src/runmodes.c | 36 +++++++++++++++++++++++++++--------- src/tm-threads.c | 9 +++++++++ src/tm-threads.h | 1 + 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/runmodes.c b/src/runmodes.c index 92b25619d9..b37a88471a 100644 --- a/src/runmodes.c +++ b/src/runmodes.c @@ -2284,7 +2284,9 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx, char *iface) { cpu = 1; /* always create at least one thread */ - int thread_max = ncpus * threading_detect_ratio; + int thread_max = TmThreadGetNbThreads(DETECT_CPU_SET); + if (thread_max == 0) + thread_max = ncpus * threading_detect_ratio; if (thread_max < 1) thread_max = 1; @@ -2548,7 +2550,9 @@ int RunModeFilePcapAuto(DetectEngineCtx *de_ctx, char *file) { cpu = 1; /* always create at least one thread */ - int thread_max = ncpus * threading_detect_ratio; + int thread_max = TmThreadGetNbThreads(DETECT_CPU_SET); + if (thread_max == 0) + thread_max = ncpus * threading_detect_ratio; if (thread_max < 1) thread_max = 1; @@ -2643,7 +2647,9 @@ int RunModeFilePcapAutoFp(DetectEngineCtx *de_ctx, char *file) { cpu = 1; /* always create at least one thread */ - int thread_max = ncpus * threading_detect_ratio; + int thread_max = TmThreadGetNbThreads(DETECT_CPU_SET); + if (thread_max == 0) + thread_max = ncpus * threading_detect_ratio; if (thread_max < 1) thread_max = 1; @@ -2828,7 +2834,9 @@ int RunModeFilePcapAuto2(DetectEngineCtx *de_ctx, char *file) { cpu = 1; /* always create at least one thread */ - int thread_max = ncpus * threading_detect_ratio; + int thread_max = TmThreadGetNbThreads(DETECT_CPU_SET); + if (thread_max == 0) + thread_max = ncpus * threading_detect_ratio; if (thread_max < 1) thread_max = 1; @@ -3005,7 +3013,9 @@ int RunModeIpsIPFWAuto(DetectEngineCtx *de_ctx) { cpu = 1; /* always create at least one thread */ - int thread_max = ncpus * threading_detect_ratio; + int thread_max = TmThreadGetNbThreads(DETECT_CPU_SET); + if (thread_max == 0) + thread_max = ncpus * threading_detect_ratio; if (thread_max < 1) thread_max = 1; @@ -3217,7 +3227,9 @@ int RunModeIpsNFQAuto(DetectEngineCtx *de_ctx, char *nfq_id) { #endif /* always create at least one thread */ - int thread_max = ncpus * threading_detect_ratio; + int thread_max = TmThreadGetNbThreads(DETECT_CPU_SET); + if (thread_max == 0) + thread_max = ncpus * threading_detect_ratio; if (thread_max < 1) thread_max = 1; @@ -3416,7 +3428,9 @@ int RunModeIdsPfringAuto(DetectEngineCtx *de_ctx, char *iface) { cpu = 1; /* always create at least one thread */ - int thread_max = ncpus * threading_detect_ratio; + int thread_max = TmThreadGetNbThreads(DETECT_CPU_SET); + if (thread_max == 0) + thread_max = ncpus * threading_detect_ratio; if (thread_max < 1) thread_max = 1; @@ -3589,7 +3603,9 @@ int RunModeErfFileAuto(DetectEngineCtx *de_ctx, char *file) cpu = 1; /* always create at least one thread */ - int thread_max = ncpus * threading_detect_ratio; + int thread_max = TmThreadGetNbThreads(DETECT_CPU_SET); + if (thread_max == 0) + thread_max = ncpus * threading_detect_ratio; if (thread_max < 1) thread_max = 1; @@ -3756,7 +3772,9 @@ int RunModeErfDagAuto(DetectEngineCtx *de_ctx, char *file) cpu = 1; /* always create at least one thread */ - int thread_max = ncpus * threading_detect_ratio; + int thread_max = TmThreadGetNbThreads(DETECT_CPU_SET); + if (thread_max == 0) + thread_max = ncpus * threading_detect_ratio; if (thread_max < 1) thread_max = 1; diff --git a/src/tm-threads.c b/src/tm-threads.c index 9b1e6f63bd..2fb9d788af 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -782,6 +782,15 @@ TmEcode TmThreadSetCPU(ThreadVars *tv, uint8_t type) { return TM_ECODE_OK; } +int TmThreadGetNbThreads(uint8_t type) +{ + if (type > MAX_CPU_SET) { + SCLogError(SC_ERR_INVALID_ARGUMENT, "invalid cpu type family"); + return 0; + } + return thread_affinity[type].nb_threads; +} + /** * \brief Set the thread options (cpu affinitythread) * Priority should be already set by pthread_create diff --git a/src/tm-threads.h b/src/tm-threads.h index 01bf295c78..2a61653999 100644 --- a/src/tm-threads.h +++ b/src/tm-threads.h @@ -96,6 +96,7 @@ TmEcode TmThreadSetThreadPriority(ThreadVars *, int); TmEcode TmThreadSetCPU(ThreadVars *, uint8_t); TmEcode TmThreadSetupOptions(ThreadVars *); void TmThreadSetPrio(ThreadVars *); +int TmThreadGetNbThreads(uint8_t type); void TmThreadInitMC(ThreadVars *); void TmThreadTestThreadUnPaused(ThreadVars *);