From 9d5f08e0d99db541cdf1528905424ebd579f14cd Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Mon, 24 Jan 2011 13:26:53 +0100 Subject: [PATCH] Pcap mode: use CPU affinity setting This patch adds support for CPU affinity settings in pcap mode. Signed-off-by: Eric Leblond --- src/runmodes.c | 69 +++++++++----------------------------------------- 1 file changed, 12 insertions(+), 57 deletions(-) diff --git a/src/runmodes.c b/src/runmodes.c index f3d126d44f..9646e252a2 100644 --- a/src/runmodes.c +++ b/src/runmodes.c @@ -2106,11 +2106,8 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx, char *iface) { } Tm1SlotSetFunc(tv_receivepcap,tm_module,(void *)iface); - if (threading_set_cpu_affinity) { - TmThreadSetCPUAffinity(tv_receivepcap, 0); - if (ncpus > 1) - TmThreadSetThreadPriority(tv_receivepcap, PRIO_MEDIUM); - } + TmThreadSetCPU(tv_receivepcap, RECEIVE_CPU_SET); + if (TmThreadSpawn(tv_receivepcap) != TM_ECODE_OK) { printf("ERROR: TmThreadSpawn failed\n"); exit(EXIT_FAILURE); @@ -2143,11 +2140,7 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx, char *iface) { } Tm1SlotSetFunc(tv_receivepcap,tm_module,(void *)pcap_devc); - if (threading_set_cpu_affinity) { - TmThreadSetCPUAffinity(tv_receivepcap, 0); - if (ncpus > 1) - TmThreadSetThreadPriority(tv_receivepcap, PRIO_MEDIUM); - } + TmThreadSetCPU(tv_receivepcap, RECEIVE_CPU_SET); if (TmThreadSpawn(tv_receivepcap) != TM_ECODE_OK) { printf("ERROR: TmThreadSpawn failed\n"); @@ -2173,11 +2166,7 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx, char *iface) { } 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"); @@ -2201,11 +2190,8 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx, char *iface) { } Tm1SlotSetFunc(tv_cuda_PB, tm_module, (void *)de_ctx); - if (threading_set_cpu_affinity) { - TmThreadSetCPUAffinity(tv_cuda_PB, 0); - if (ncpus > 1) - TmThreadSetThreadPriority(tv_cuda_PB, PRIO_MEDIUM); - } + + TmThreadSetCPU(tv_cuda_PB, DETECT_CPU_SET); if (TmThreadSpawn(tv_cuda_PB) != TM_ECODE_OK) { printf("ERROR: TmThreadSpawn failed\n"); @@ -2227,11 +2213,7 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx, char *iface) { } 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"); @@ -2260,11 +2242,7 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx, char *iface) { } TmVarSlotSetFuncAppend(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"); @@ -2293,11 +2271,7 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx, char *iface) { } TmVarSlotSetFuncAppend(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"); @@ -2334,18 +2308,7 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx, char *iface) { } 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); char *thread_group_name = SCStrdup("Detect"); if (thread_group_name == NULL) { @@ -2377,11 +2340,7 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx, char *iface) { } 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, REJECT_CPU_SET); if (TmThreadSpawn(tv_rreject) != TM_ECODE_OK) { printf("ERROR: TmThreadSpawn failed\n"); @@ -2392,11 +2351,7 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx, char *iface) { "alert-queue", "simple", "packetpool", "packetpool", "varslot"); SetupOutputs(tv_outputs); - if (threading_set_cpu_affinity) { - TmThreadSetCPUAffinity(tv_outputs, 0); - if (ncpus > 1) - TmThreadSetThreadPriority(tv_outputs, PRIO_MEDIUM); - } + TmThreadSetCPU(tv_outputs, OUTPUT_CPU_SET); if (TmThreadSpawn(tv_outputs) != TM_ECODE_OK) { printf("ERROR: TmThreadSpawn failed\n");