]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
threads/runmode: Changes to thread config behaviour
authorJoshua Lumb <joshua.lumb@gmail.com>
Fri, 17 Jul 2020 13:29:20 +0000 (09:29 -0400)
committerVictor Julien <victor@inliniac.net>
Tue, 21 Jul 2020 14:50:06 +0000 (16:50 +0200)
src/tm-threads.c
src/tm-threads.h
src/util-runmodes.c

index 549af74baa121251b4a386a7bdeee16c1ea734ae..dd9a4fcec67cd6886b13a750c0605811c35a5bd6 100644 (file)
@@ -2177,6 +2177,22 @@ void TmThreadsGetMinimalTimestamp(struct timeval *ts)
     SCLogDebug("ts->tv_sec %"PRIuMAX, (uintmax_t)ts->tv_sec);
 }
 
+uint16_t TmThreadsGetWorkerThreadMax()
+{
+    uint16_t ncpus = UtilCpuGetNumProcessorsOnline();
+    int thread_max = TmThreadGetNbThreads(WORKER_CPU_SET);
+    /* always create at least one thread */
+    if (thread_max == 0)
+        thread_max = ncpus * threading_detect_ratio;
+    if (thread_max < 1)
+        thread_max = 1;
+    if (thread_max > 1024) {
+        SCLogWarning(SC_ERR_RUNMODE, "limited number of 'worker' threads to 1024. Wanted %d", thread_max);
+        thread_max = 1024;
+    }
+    return thread_max;
+}
+
 /**
  *  \retval r 1 if packet was accepted, 0 otherwise
  *  \note if packet was not accepted, it's still the responsibility
index 6d901e8f18d25ab84e534b217b713cdabdb40fe7..278e156bb5e5c923036cafb4352447da0eeab8c7 100644 (file)
@@ -243,6 +243,7 @@ int TmThreadsInjectPacketsById(Packet **, int id);
 void TmThreadsInitThreadsTimestamp(const struct timeval *ts);
 void TmThreadsSetThreadTimestamp(const int id, const struct timeval *ts);
 void TmThreadsGetMinimalTimestamp(struct timeval *ts);
+uint16_t TmThreadsGetWorkerThreadMax(void);
 bool TmThreadsTimeSubsysIsReady(void);
 
 #endif /* __TM_THREADS_H__ */
index 2788ab1f038a0e39ac108e814b70a121f7cb292b..889a459ca669c9d92918214545b0968347fc8f50 100644 (file)
@@ -97,18 +97,8 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser,
     char qname[TM_QUEUE_NAME_MAX];
 
     /* Available cpus */
-    uint16_t ncpus = UtilCpuGetNumProcessorsOnline();
     int nlive = LiveGetDeviceCount();
-    int thread_max = TmThreadGetNbThreads(WORKER_CPU_SET);
-    /* always create at least one thread */
-    if (thread_max == 0)
-        thread_max = ncpus * threading_detect_ratio;
-    if (thread_max < 1)
-        thread_max = 1;
-    if (thread_max > 1024) {
-        SCLogWarning(SC_ERR_RUNMODE, "limited number of 'worker' threads to 1024. Wanted %d", thread_max);
-        thread_max = 1024;
-    }
+    uint16_t thread_max = TmThreadsGetWorkerThreadMax();
 
     char *queues = RunmodeAutoFpCreatePickupQueuesString(thread_max);
     if (queues == NULL) {
@@ -129,7 +119,7 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser,
                   threads_count, recv_mod_name);
 
         /* create the threads */
-        for (int thread = 0; thread < MIN(thread_max, threads_count); thread++) {
+        for (int thread = 0; thread < threads_count; thread++) {
             snprintf(tname, sizeof(tname), "%s#%02d", thread_name, thread+1);
             ThreadVars *tv_receive =
                 TmThreadCreatePacketHandler(tname,
@@ -266,11 +256,12 @@ static int RunModeSetLiveCaptureWorkersForDevice(ConfigIfaceThreadsCountFunc Mod
                               unsigned char single_mode)
 {
     int threads_count;
+    uint16_t thread_max = TmThreadsGetWorkerThreadMax();
 
     if (single_mode) {
         threads_count = 1;
     } else {
-        threads_count = ModThreadsCount(aconf);
+        threads_count = MIN(ModThreadsCount(aconf), thread_max);
         SCLogInfo("Going to use %" PRId32 " thread(s)", threads_count);
     }
 
@@ -418,19 +409,9 @@ int RunModeSetIPSAutoFp(ConfigIPSParserFunc ConfigParser,
     TmModule *tm_module ;
 
     /* Available cpus */
-    uint16_t ncpus = UtilCpuGetNumProcessorsOnline();
     const int nqueue = LiveGetDeviceCount();
 
-    int thread_max = TmThreadGetNbThreads(WORKER_CPU_SET);
-    /* always create at least one thread */
-    if (thread_max == 0)
-        thread_max = ncpus * threading_detect_ratio;
-    if (thread_max < 1)
-        thread_max = 1;
-    if (thread_max > 1024) {
-        SCLogWarning(SC_ERR_RUNMODE, "limited number of 'worker' threads to 1024. Wanted %d", thread_max);
-        thread_max = 1024;
-    }
+    uint16_t thread_max = TmThreadsGetWorkerThreadMax();
 
     char *queues = RunmodeAutoFpCreatePickupQueuesString(thread_max);
     if (queues == NULL) {