[Oisf-devel] [PATCH 6/6] Convert RunModeIpsNFQAuto to new affinity mode.

Eric Leblond eleblond at edenwall.com
Fri Nov 12 11:05:07 UTC 2010


The default NFQ run mode is now using the new affinity system. It
thus can be configured via suricata.yaml.

Signed-off-by: Eric Leblond <eleblond at edenwall.com>
---
 src/runmodes.c |   72 ++++++++++++++++++-------------------------------------
 1 files changed, 24 insertions(+), 48 deletions(-)

diff --git a/src/runmodes.c b/src/runmodes.c
index d4131b1..cb5162e 100644
--- a/src/runmodes.c
+++ b/src/runmodes.c
@@ -3185,7 +3185,9 @@ int RunModeIpsIPFWAuto(DetectEngineCtx *de_ctx) {
 int RunModeIpsNFQAuto(DetectEngineCtx *de_ctx, char *nfq_id) {
     SCEnter();
     char tname[12];
+#if 0
     uint16_t cpu = 0;
+#endif
 
     /* Available cpus */
     uint16_t ncpus = UtilCpuGetNumProcessorsOnline();
@@ -3207,11 +3209,7 @@ int RunModeIpsNFQAuto(DetectEngineCtx *de_ctx, char *nfq_id) {
     }
     Tm1SlotSetFunc(tv_receivenfq,tm_module,nfq_id);
 
-    if (threading_set_cpu_affinity) {
-        TmThreadSetCPUAffinity(tv_receivenfq, 0);
-        if (ncpus > 1)
-            TmThreadSetThreadPriority(tv_receivenfq, PRIO_MEDIUM);
-    }
+    TmThreadSetCPU(tv_receivenfq, RECEIVE_CPU_SET);
 
     if (TmThreadSpawn(tv_receivenfq) != TM_ECODE_OK) {
         printf("ERROR: TmThreadSpawn failed\n");
@@ -3230,11 +3228,7 @@ int RunModeIpsNFQAuto(DetectEngineCtx *de_ctx, char *nfq_id) {
     }
     Tm1SlotSetFunc(tv_decode1,tm_module,NULL);
 
-    if (threading_set_cpu_affinity) {
-        TmThreadSetCPUAffinity(tv_decode1, 0);
-        if (ncpus > 1)
-            TmThreadSetThreadPriority(tv_decode1, PRIO_MEDIUM);
-    }
+    TmThreadSetCPU(tv_decode1, DECODE_CPU_SET);
 
     if (TmThreadSpawn(tv_decode1) != TM_ECODE_OK) {
         printf("ERROR: TmThreadSpawn failed\n");
@@ -3253,21 +3247,19 @@ int RunModeIpsNFQAuto(DetectEngineCtx *de_ctx, char *nfq_id) {
     }
     Tm1SlotSetFunc(tv_stream1,tm_module,NULL);
 
-    if (threading_set_cpu_affinity) {
-        TmThreadSetCPUAffinity(tv_stream1, 0);
-        if (ncpus > 1)
-            TmThreadSetThreadPriority(tv_stream1, PRIO_MEDIUM);
-    }
+    TmThreadSetCPU(tv_stream1, STREAM_CPU_SET);
 
     if (TmThreadSpawn(tv_stream1) != TM_ECODE_OK) {
         printf("ERROR: TmThreadSpawn failed\n");
         exit(EXIT_FAILURE);
     }
 
+#if 0
     /* start with cpu 1 so that if we're creating an odd number of detect
      * threads we're not creating the most on CPU0. */
     if (ncpus > 0)
         cpu = 1;
+#endif
 
     /* always create at least one thread */
     int thread_max = ncpus * threading_detect_ratio;
@@ -3281,7 +3273,7 @@ int RunModeIpsNFQAuto(DetectEngineCtx *de_ctx, char *nfq_id) {
             break;
 
         char *thread_name = SCStrdup(tname);
-        SCLogDebug("Assigning %s affinity to cpu %u", thread_name, cpu);
+        SCLogDebug("Assigning %s affinity", thread_name);
 
         ThreadVars *tv_detect_ncpu = TmThreadCreatePacketHandler(thread_name,"stream-queue1","simple","verdict-queue","simple","1slot");
         if (tv_detect_ncpu == NULL) {
@@ -3295,18 +3287,18 @@ int RunModeIpsNFQAuto(DetectEngineCtx *de_ctx, char *nfq_id) {
         }
         Tm1SlotSetFunc(tv_detect_ncpu,tm_module,(void *)de_ctx);
 
-        if (threading_set_cpu_affinity) {
-            TmThreadSetCPUAffinity(tv_detect_ncpu, (int)cpu);
-            /* If we have more than one core/cpu, the first Detect thread
-             * (at cpu 0) will have less priority (higher 'nice' value)
-             * In this case we will set the thread priority to +10 (default is 0)
-             */
-            if (cpu == 0 && ncpus > 1) {
-                TmThreadSetThreadPriority(tv_detect_ncpu, PRIO_LOW);
-            } else if (ncpus > 1) {
-                TmThreadSetThreadPriority(tv_detect_ncpu, PRIO_MEDIUM);
-            }
-        }
+	TmThreadSetCPU(tv_detect_ncpu, DECODE_CPU_SET);
+#if 0
+	/* If we have more than one core/cpu, the first Detect thread
+	 * (at cpu 0) will have less priority (higher 'nice' value)
+	 * In this case we will set the thread priority to +10 (default is 0)
+	 */
+	if (cpu == 0 && ncpus > 1) {
+	    TmThreadSetThreadPriority(tv_detect_ncpu, PRIO_LOW);
+	} else if (ncpus > 1) {
+	    TmThreadSetThreadPriority(tv_detect_ncpu, PRIO_MEDIUM);
+	}
+#endif
 
         char *thread_group_name = SCStrdup("Detect");
         if (thread_group_name == NULL) {
@@ -3319,11 +3311,6 @@ int RunModeIpsNFQAuto(DetectEngineCtx *de_ctx, char *nfq_id) {
             printf("ERROR: TmThreadSpawn failed\n");
             exit(EXIT_FAILURE);
         }
-
-        if ((cpu + 1) == ncpus)
-            cpu = 0;
-        else
-            cpu++;
     }
 
     ThreadVars *tv_verdict = TmThreadCreatePacketHandler("Verdict","verdict-queue","simple","respond-queue","simple","1slot");
@@ -3338,11 +3325,7 @@ int RunModeIpsNFQAuto(DetectEngineCtx *de_ctx, char *nfq_id) {
     }
     Tm1SlotSetFunc(tv_verdict,tm_module,nfq_id);
 
-    if (threading_set_cpu_affinity) {
-        TmThreadSetCPUAffinity(tv_verdict, 0);
-        if (ncpus > 1)
-            TmThreadSetThreadPriority(tv_verdict, PRIO_MEDIUM);
-    }
+    TmThreadSetCPU(tv_verdict, VERDICT_CPU_SET);
 
     if (TmThreadSpawn(tv_verdict) != TM_ECODE_OK) {
         printf("ERROR: TmThreadSpawn failed\n");
@@ -3361,11 +3344,7 @@ int RunModeIpsNFQAuto(DetectEngineCtx *de_ctx, char *nfq_id) {
     }
     Tm1SlotSetFunc(tv_rreject,tm_module,NULL);
 
-    if (threading_set_cpu_affinity) {
-        TmThreadSetCPUAffinity(tv_rreject, 0);
-        if (ncpus > 1)
-            TmThreadSetThreadPriority(tv_rreject, PRIO_MEDIUM);
-    }
+    TmThreadSetCPU(tv_rreject, VERDICT_CPU_SET);
 
     if (TmThreadSpawn(tv_rreject) != TM_ECODE_OK) {
         printf("ERROR: TmThreadSpawn failed\n");
@@ -3375,11 +3354,8 @@ int RunModeIpsNFQAuto(DetectEngineCtx *de_ctx, char *nfq_id) {
     ThreadVars *tv_outputs = TmThreadCreatePacketHandler("Outputs",
         "alert-queue1", "simple", "packetpool", "packetpool", "varslot");
 
-    if (threading_set_cpu_affinity) {
-        TmThreadSetCPUAffinity(tv_outputs, 0);
-        if (ncpus > 1)
-            TmThreadSetThreadPriority(tv_outputs, PRIO_MEDIUM);
-    }
+    TmThreadSetCPU(tv_outputs, OUTPUT_CPU_SET);
+
     SetupOutputs(tv_outputs);
     if (TmThreadSpawn(tv_outputs) != TM_ECODE_OK) {
         printf("ERROR: TmThreadSpawn failed\n");
-- 
1.7.2.3




More information about the Oisf-devel mailing list