From cdaa13012afeb0d3437c015448d77418f5199699 Mon Sep 17 00:00:00 2001 From: Anoop Saldanha Date: Thu, 18 Jul 2013 14:35:54 +0530 Subject: [PATCH] fix for #882. Refactor the code that initializes the cuda mpm environment. --- src/suricata.c | 3 +++ src/util-mpm-ac.c | 13 ------------- src/util-mpm.c | 26 +++++++++++++++++++++++++- src/util-mpm.h | 2 ++ 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/suricata.c b/src/suricata.c index fc2d3f2ce8..9f5f12507d 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -1361,6 +1361,9 @@ int main(int argc, char **argv) /* load the pattern matchers */ MpmTableSetup(); +#ifdef __SC_CUDA_SUPPORT__ + MpmCudaEnvironmentSetup(); +#endif AppLayerDetectProtoThreadInit(); if (list_app_layer_protocols) { diff --git a/src/util-mpm-ac.c b/src/util-mpm-ac.c index 8c218a0896..0e149547b7 100644 --- a/src/util-mpm-ac.c +++ b/src/util-mpm-ac.c @@ -2163,19 +2163,6 @@ void MpmACCudaRegister(void) mpm_table[MPM_AC_CUDA].PrintThreadCtx = SCACPrintSearchStats; mpm_table[MPM_AC_CUDA].RegisterUnittests = SCACRegisterTests; - if (PatternMatchDefaultMatcher() == MPM_AC_CUDA) { - MpmCudaConf *conf = CudaHandlerGetCudaProfile("mpm"); - if (conf == NULL) { - SCLogError(SC_ERR_AC_CUDA_ERROR, "Error obtaining cuda mpm profile."); - exit(EXIT_FAILURE); - } - - if (MpmCudaBufferSetup() < 0) { - SCLogError(SC_ERR_AC_CUDA_ERROR, "Error setting up env for ac cuda"); - exit(EXIT_FAILURE); - } - } - return; } diff --git a/src/util-mpm.c b/src/util-mpm.c index d9f105c98d..1756f8bfb7 100644 --- a/src/util-mpm.c +++ b/src/util-mpm.c @@ -47,6 +47,7 @@ #include "util-unittest.h" #ifdef __SC_CUDA_SUPPORT__ #include "util-cuda-handlers.h" +#include "detect-engine-mpm.h" #endif /** @@ -378,6 +379,30 @@ static void *MpmCudaConfParse(ConfNode *node) return conf; } + +void MpmCudaEnvironmentSetup() +{ + if (PatternMatchDefaultMatcher() != MPM_AC_CUDA) + return; + + CudaHandlerAddCudaProfileFromConf("mpm", MpmCudaConfParse, MpmCudaConfFree); + + MpmCudaConf *conf = CudaHandlerGetCudaProfile("mpm"); + if (conf == NULL) { + SCLogError(SC_ERR_AC_CUDA_ERROR, "Error obtaining cuda mpm " + "profile."); + exit(EXIT_FAILURE); + } + + if (MpmCudaBufferSetup() < 0) { + SCLogError(SC_ERR_AC_CUDA_ERROR, "Error setting up env for ac " + "cuda"); + exit(EXIT_FAILURE); + } + + return; +} + #endif /** @@ -565,7 +590,6 @@ void MpmTableSetup(void) { MpmACBSRegister(); MpmACGfbsRegister(); #ifdef __SC_CUDA_SUPPORT__ - CudaHandlerAddCudaProfileFromConf("mpm", MpmCudaConfParse, MpmCudaConfFree); MpmACCudaRegister(); #endif /* __SC_CUDA_SUPPORT__ */ } diff --git a/src/util-mpm.h b/src/util-mpm.h index 605b9c6ff6..a352490811 100644 --- a/src/util-mpm.h +++ b/src/util-mpm.h @@ -212,6 +212,8 @@ typedef struct MpmCudaConf_ { int cuda_streams; } MpmCudaConf; +void MpmCudaEnvironmentSetup(); + #endif /* __SC_CUDA_SUPPORT__ */ struct DetectEngineCtx_;