valgrind fixes for b2g cuda mpm

remotes/origin/master-1.0.x
Anoop Saldanha 15 years ago committed by Victor Julien
parent 41e6735b92
commit a2948fc25c

@ -97,6 +97,7 @@
/* holds the cuda b2g module */
#include "util-mpm-b2g-cuda.h"
#include "util-cuda-handlers.h"
#include "output.h"
@ -389,8 +390,10 @@ int main(int argc, char **argv)
/* Initialize the configuration module. */
ConfInit();
#ifdef __SC_CUDA_SUPPORT__
/* Init the CUDA environment */
SCCudaInitCudaEnvironment();
#endif
struct option long_opts[] = {
{"dump-config", 0, &dump_config, 1},
@ -731,6 +734,15 @@ int main(int argc, char **argv)
else {
uint32_t failed = UtRunTests(regex_arg);
UtCleanup();
#ifdef __SC_CUDA_SUPPORT__
/* need this in case any of the cuda dispatcher threads are still
* running, kill them, so that we can free the cuda contexts. We
* need to free those cuda contexts so that next when we call
* deregister functions, we will need to attach to those contexts
* the contexts and its associated data */
TmThreadKillThreads();
SCCudaHlDeRegisterAllRegisteredModules();
#endif
if (failed) {
exit(EXIT_FAILURE);
}
@ -910,5 +922,13 @@ int main(int argc, char **argv)
RunModeShutDown();
OutputDeregisterAll();
#ifdef __SC_CUDA_SUPPORT__
/* all cuda contexts attached to any threads should be free by now.
* if any host_thread is still attached to any cuda_context, they need
* to pop them by the time we reach here, if they aren't using those
* cuda contexts in any way */
SCCudaHlDeRegisterAllRegisteredModules();
#endif
exit(EXIT_SUCCESS);
}

@ -514,6 +514,11 @@ int SCCudaHlDeRegisterModule(const char *name)
return -1;
}
/* the applicationg must take care to check that the following cuda context
* which is being freed is floating(not attached to any host thread) */
if (data->cuda_context != 0)
SCCudaCtxPushCurrent(data->cuda_context);
/* looks like we do have a module registered by this name */
/* first clean the cuda device pointers */
device_ptr = data->device_ptrs;
@ -527,6 +532,9 @@ int SCCudaHlDeRegisterModule(const char *name)
}
data->device_ptrs = NULL;
if (data->name != NULL)
free((void *)data->name);
/* clean the dispatcher function registered */
data->SCCudaHlDispFunc = NULL;
@ -561,6 +569,29 @@ int SCCudaHlDeRegisterModule(const char *name)
return -1;
}
/**
* \brief DeRegister all the modules registered under cuda handlers.
*/
void SCCudaHlDeRegisterAllRegisteredModules(void)
{
SCCudaHlModuleData *data = module_datas;
SCCudaHlModuleData *next_data = NULL;
next_data = data;
while (data != NULL) {
next_data = data->next;
if (SCCudaHlDeRegisterModule(data->name) == -1) {
SCLogError(SC_ERR_CUDA_HANDLER_ERROR, "Error de-registering module "
"\"%s\"", data->name);
}
data = next_data;
}
module_datas = NULL;
return;
}
/**
* \brief Pushes a cuda context for the calling thread.
*

@ -55,6 +55,7 @@ int SCCudaHlGetModuleHandle(const char *);
int SCCudaHlRegisterModule(const char *);
int SCCudaHlDeRegisterModule(const char *);
void SCCudaHlDeRegisterAllRegisteredModules(void);
int SCCudaHlPushCudaContextFromModule(const char *);

@ -1637,6 +1637,12 @@ void B2gCudaDestroyCtx(MpmCtx *mpm_ctx)
ctx->cuda_search_B2G = 0;
}
if (ctx->cuda_scan_B2G != 0) {
if (SCCudaMemFree(ctx->cuda_scan_B2G) == -1)
SCLogError(SC_ERR_B2G_CUDA_ERROR, "Error freeing ctx->cuda_scan_B2G ");
ctx->cuda_scan_B2G = 0;
}
free(mpm_ctx->ctx);
mpm_ctx->memory_cnt--;
mpm_ctx->memory_size -= sizeof(B2gCudaCtx);

Loading…
Cancel
Save