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

Eric Leblond eleblond at edenwall.com
Sun Nov 21 13:30:53 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 |   60 ++++++++++++++++++++-----------------------------------
 1 files changed, 22 insertions(+), 38 deletions(-)

diff --git a/src/runmodes.c b/src/runmodes.c
index 612389a..5edf49f 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();
@@ -3210,11 +3212,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");
@@ -3243,21 +3241,19 @@ int RunModeIpsNFQAuto(DetectEngineCtx *de_ctx, char *nfq_id) {
     }
     TmVarSlotSetFuncAppend(tv_decode,tm_module,NULL);
 
-    if (threading_set_cpu_affinity) {
-        TmThreadSetCPUAffinity(tv_decode, 0);
-        if (ncpus > 1)
-            TmThreadSetThreadPriority(tv_decode, PRIO_MEDIUM);
-    }
+    TmThreadSetCPU(tv_decode, DECODE_CPU_SET);
 
     if (TmThreadSpawn(tv_decode) != 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;
@@ -3271,7 +3267,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,
                 "decode-queue","simple","verdict-queue","simple","1slot");
@@ -3286,18 +3282,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, DETECT_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) {
@@ -3310,11 +3306,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",
@@ -3337,11 +3328,7 @@ int RunModeIpsNFQAuto(DetectEngineCtx *de_ctx, char *nfq_id) {
     }
     TmVarSlotSetFuncAppend(tv_verdict,tm_module,NULL);
 
-    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");
@@ -3351,11 +3338,8 @@ int RunModeIpsNFQAuto(DetectEngineCtx *de_ctx, char *nfq_id) {
     ThreadVars *tv_outputs = TmThreadCreatePacketHandler("Outputs",
         "alert-queue", "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