Remove all cuda related code in the engine except for the cuda api wrappers

pull/400/head
Anoop Saldanha 13 years ago committed by Victor Julien
parent e2a6cfb6a6
commit b787da5643

@ -32,7 +32,6 @@ app-layer-tls-handshake.c app-layer-tls-handshake.h \
conf.c conf.h \
conf-yaml-loader.c conf-yaml-loader.h \
counters.c counters.h \
cuda-packet-batcher.c cuda-packet-batcher.h \
data-queue.c data-queue.h \
decode.c decode.h \
decode-ethernet.c decode-ethernet.h \
@ -257,7 +256,6 @@ util-coredump-config.c util-coredump-config.h \
util-cpu.c util-cpu.h \
util-crypt.c util-crypt.h \
util-cuda.c util-cuda.h \
util-cuda-handlers.c util-cuda-handlers.h \
util-daemon.c util-daemon.h \
util-debug.c util-debug.h \
util-debug-filters.c util-debug-filters.h \
@ -284,7 +282,6 @@ util-mpm-ac-bs.c util-mpm-ac-bs.h \
util-mpm-ac.c util-mpm-ac.h \
util-mpm-ac-gfbs.c util-mpm-ac-gfbs.h \
util-mpm-b2gc.c util-mpm-b2gc.h \
util-mpm-b2g-cuda.c util-mpm-b2g-cuda.h \
util-mpm-b2g.c util-mpm-b2g.h \
util-mpm-b2gm.c util-mpm-b2gm.h \
util-mpm-b3g.c util-mpm-b3g.h \

@ -51,8 +51,6 @@
#include "output.h"
#include "alert-fastlog.h"
#include "util-mpm-b2g-cuda.h"
#include "util-cuda-handlers.h"
#include "util-privs.h"
#include "util-print.h"
#include "util-proto-name.h"
@ -398,14 +396,6 @@ int AlertFastLogTest01()
else
result = 0;
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadRC();
if (SCCudaHlPushCudaContextFromModule("SC_RULES_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
SigGroupCleanup(de_ctx);
SigCleanSignatures(de_ctx);
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
@ -464,14 +454,6 @@ int AlertFastLogTest02()
result = 0;
}
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadRC();
if (SCCudaHlPushCudaContextFromModule("SC_RULES_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
SigGroupCleanup(de_ctx);
SigCleanSignatures(de_ctx);
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
@ -491,19 +473,9 @@ void AlertFastLogRegisterTests(void)
#ifdef UNITTESTS
#ifdef __SC_CUDA_SUPPORT__
UtRegisterTest("AlertFastLogCudaContextInit",
SCCudaHlTestEnvCudaContextInit, 1);
#endif
UtRegisterTest("AlertFastLogTest01", AlertFastLogTest01, 1);
UtRegisterTest("AlertFastLogTest02", AlertFastLogTest02, 1);
#ifdef __SC_CUDA_SUPPORT__
UtRegisterTest("AlertFastLogCudaContextDeInit",
SCCudaHlTestEnvCudaContextDeInit, 1);
#endif
#endif /* UNITTESTS */
}

@ -53,8 +53,6 @@
#include "output.h"
#include "alert-pcapinfo.h"
#include "util-mpm-b2g-cuda.h"
#include "util-cuda-handlers.h"
#include "util-privs.h"
#include "util-print.h"
#include "util-proto-name.h"

@ -60,16 +60,10 @@
#include "util-spm.h"
#include "util-cuda.h"
#include "util-cuda-handlers.h"
#include "util-mpm-b2g-cuda.h"
#include "util-debug.h"
#define INSPECT_BYTES 32
/* undef __SC_CUDA_SUPPORT__. We will get back to this later. Need to
* analyze the performance of cuda support for app layer */
#undef __SC_CUDA_SUPPORT__
/** global app layer detection context */
AlpProtoDetectCtx alp_proto_ctx;
@ -77,14 +71,8 @@ AlpProtoDetectCtx alp_proto_ctx;
void AlpProtoInit(AlpProtoDetectCtx *ctx) {
memset(ctx, 0x00, sizeof(AlpProtoDetectCtx));
#ifndef __SC_CUDA_SUPPORT__
MpmInitCtx(&ctx->toserver.mpm_ctx, MPM_B2G, -1);
MpmInitCtx(&ctx->toclient.mpm_ctx, MPM_B2G, -1);
#else
ctx->alp_content_module_handle = SCCudaHlRegisterModule("SC_ALP_CONTENT_B2G_CUDA");
MpmInitCtx(&ctx->toserver.mpm_ctx, MPM_B2G_CUDA, ctx->alp_content_module_handle);
MpmInitCtx(&ctx->toclient.mpm_ctx, MPM_B2G_CUDA, ctx->alp_content_module_handle);
#endif
memset(&ctx->toserver.map, 0x00, sizeof(ctx->toserver.map));
memset(&ctx->toclient.map, 0x00, sizeof(ctx->toclient.map));
@ -324,14 +312,6 @@ void AlpProtoFinalizeGlobal(AlpProtoDetectCtx *ctx) {
mpm_table[ctx->toclient.mpm_ctx.mpm_type].Prepare(&ctx->toclient.mpm_ctx);
mpm_table[ctx->toserver.mpm_ctx.mpm_type].Prepare(&ctx->toserver.mpm_ctx);
#ifdef __SC_CUDA_SUPPORT__
CUcontext context;
if (SCCudaCtxPopCurrent(&context) == -1)
exit(EXIT_FAILURE);
if (B2gCudaStartDispatcherThreadAPC("SC_ALP_CONTENT_B2G_CUDA") == -1)
exit(EXIT_FAILURE);
#endif
/* allocate and initialize the mapping between pattern id and signature */
ctx->map = (AlpProtoSignature **)SCMalloc(ctx->sigs * sizeof(AlpProtoSignature *));
if (ctx->map == NULL) {
@ -406,31 +386,10 @@ uint16_t AppLayerDetectGetProtoPMParser(AlpProtoDetectCtx *ctx,
uint32_t cnt = 0;
/* do the mpm search */
#ifndef __SC_CUDA_SUPPORT__
cnt = mpm_table[dir->mpm_ctx.mpm_type].Search(&dir->mpm_ctx,
&tdir->mpm_ctx,
&tdir->pmq, buf,
searchlen);
#else
Packet *p = PacketGetFromAlloc();
if (unlikely(p == NULL))
goto end;
p->cuda_done = 0;
p->cuda_free_packet = 1;
p->cuda_search = 0;
p->cuda_mpm_ctx = &dir->mpm_ctx;
p->cuda_mtc = &tdir->mpm_ctx;
p->cuda_pmq = &tdir->pmq;
p->payload = buf;
p->payload_len = searchlen;
B2gCudaPushPacketTo_tv_CMB2_APC(p);
SCMutexLock(&p->cuda_mutex_q);
SCCondWait(&p->cuda_cond_q, &p->cuda_mutex_q);
p->cuda_done = 1;
SCMutexUnlock(&p->cuda_mutex_q);
cnt = p->cuda_matches;
#endif
SCLogDebug("search cnt %" PRIu32 "", cnt);
if (cnt == 0) {
proto = ALPROTO_UNKNOWN;
@ -745,14 +704,6 @@ int AlpDetectTest01(void) {
int r = 1;
AlpProtoDetectCtx ctx;
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadAPC();
if (SCCudaHlPushCudaContextFromModule("SC_ALP_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
AlpProtoInit(&ctx);
AlpProtoAdd(&ctx, "http", IPPROTO_TCP, ALPROTO_HTTP, buf, 4, 0, STREAM_TOCLIENT);
@ -771,13 +722,6 @@ int AlpDetectTest01(void) {
AlpProtoTestDestroy(&ctx);
#ifdef __SC_CUDA_SUPPORT__
if (SCCudaCtxPopCurrent(NULL) == -1) {
printf("Call to SCCudaCtxPopCurrent() failed\n");
return 0;
}
#endif
return r;
}
@ -786,14 +730,6 @@ int AlpDetectTest02(void) {
int r = 1;
AlpProtoDetectCtx ctx;
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadAPC();
if (SCCudaHlPushCudaContextFromModule("SC_ALP_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
AlpProtoInit(&ctx);
AlpProtoAdd(&ctx, "http", IPPROTO_TCP, ALPROTO_HTTP, buf, 4, 0, STREAM_TOCLIENT);
@ -821,13 +757,6 @@ int AlpDetectTest02(void) {
AlpProtoTestDestroy(&ctx);
#ifdef __SC_CUDA_SUPPORT__
if (SCCudaCtxPopCurrent(NULL) == -1) {
printf("Call to SCCudaCtxPopCurrent() failed\n");
return 0;
}
#endif
return r;
}
@ -838,14 +767,6 @@ int AlpDetectTest03(void) {
AlpProtoDetectCtx ctx;
AlpProtoDetectThreadCtx tctx;
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadAPC();
if (SCCudaHlPushCudaContextFromModule("SC_ALP_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
AlpProtoInit(&ctx);
AlpProtoAdd(&ctx, "http", IPPROTO_TCP, ALPROTO_HTTP, buf, 4, 0, STREAM_TOCLIENT);
@ -874,14 +795,6 @@ int AlpDetectTest03(void) {
AlpProtoFinalizeGlobal(&ctx);
AlpProtoFinalizeThread(&ctx, &tctx);
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadAPC();
if (SCCudaHlPushCudaContextFromModule("SC_ALP_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
uint32_t cnt = mpm_table[ctx.toclient.mpm_ctx.mpm_type].Search(&ctx.toclient.mpm_ctx, &tctx.toclient.mpm_ctx, NULL, l7data, sizeof(l7data));
if (cnt != 1) {
printf("cnt %u != 1: ", cnt);
@ -890,13 +803,6 @@ int AlpDetectTest03(void) {
AlpProtoTestDestroy(&ctx);
#ifdef __SC_CUDA_SUPPORT__
if (SCCudaCtxPopCurrent(NULL) == -1) {
printf("Call to SCCudaCtxPopCurrent() failed\n");
return 0;
}
#endif
return r;
}
@ -907,14 +813,6 @@ int AlpDetectTest04(void) {
AlpProtoDetectCtx ctx;
AlpProtoDetectThreadCtx tctx;
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadAPC();
if (SCCudaHlPushCudaContextFromModule("SC_ALP_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
AlpProtoInit(&ctx);
AlpProtoAdd(&ctx, "http", IPPROTO_TCP, ALPROTO_HTTP, buf, 4, 0, STREAM_TOCLIENT);
@ -931,14 +829,6 @@ int AlpDetectTest04(void) {
AlpProtoFinalizeGlobal(&ctx);
AlpProtoFinalizeThread(&ctx, &tctx);
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadAPC();
if (SCCudaHlPushCudaContextFromModule("SC_ALP_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
uint32_t cnt = mpm_table[ctx.toclient.mpm_ctx.mpm_type].Search(&ctx.toclient.mpm_ctx, &tctx.toclient.mpm_ctx, &tctx.toclient.pmq, l7data, sizeof(l7data));
if (cnt != 1) {
printf("cnt %u != 1: ", cnt);
@ -947,13 +837,6 @@ int AlpDetectTest04(void) {
AlpProtoTestDestroy(&ctx);
#ifdef __SC_CUDA_SUPPORT__
if (SCCudaCtxPopCurrent(NULL) == -1) {
printf("Call to SCCudaCtxPopCurrent() failed\n");
return 0;
}
#endif
return r;
}
@ -965,14 +848,6 @@ int AlpDetectTest05(void) {
AlpProtoDetectCtx ctx;
AlpProtoDetectThreadCtx tctx;
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadAPC();
if (SCCudaHlPushCudaContextFromModule("SC_ALP_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
AlpProtoInit(&ctx);
AlpProtoAdd(&ctx, "http", IPPROTO_TCP, ALPROTO_HTTP, buf, 4, 0, STREAM_TOCLIENT);
@ -1007,23 +882,8 @@ int AlpDetectTest05(void) {
r = 0;
}
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadAPC();
if (SCCudaHlPushCudaContextFromModule("SC_ALP_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
AlpProtoTestDestroy(&ctx);
#ifdef __SC_CUDA_SUPPORT__
if (SCCudaCtxPopCurrent(NULL) == -1) {
printf("Call to SCCudaCtxPopCurrent() failed\n");
return 0;
}
#endif
return r;
}
@ -1034,14 +894,6 @@ int AlpDetectTest06(void) {
AlpProtoDetectCtx ctx;
AlpProtoDetectThreadCtx tctx;
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadAPC();
if (SCCudaHlPushCudaContextFromModule("SC_ALP_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
AlpProtoInit(&ctx);
AlpProtoAdd(&ctx, "http", IPPROTO_TCP, ALPROTO_HTTP, buf, 4, 0, STREAM_TOCLIENT);
@ -1076,23 +928,8 @@ int AlpDetectTest06(void) {
r = 0;
}
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadAPC();
if (SCCudaHlPushCudaContextFromModule("SC_ALP_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
AlpProtoTestDestroy(&ctx);
#ifdef __SC_CUDA_SUPPORT__
if (SCCudaCtxPopCurrent(NULL) == -1) {
printf("Call to SCCudaCtxPopCurrent() failed\n");
return 0;
}
#endif
return r;
}
@ -1103,14 +940,6 @@ int AlpDetectTest07(void) {
AlpProtoDetectCtx ctx;
AlpProtoDetectThreadCtx tctx;
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadAPC();
if (SCCudaHlPushCudaContextFromModule("SC_ALP_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
AlpProtoInit(&ctx);
AlpProtoAdd(&ctx, "http", IPPROTO_TCP, ALPROTO_HTTP, buf, 4, 0, STREAM_TOCLIENT);
@ -1133,23 +962,8 @@ int AlpDetectTest07(void) {
r = 0;
}
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadAPC();
if (SCCudaHlPushCudaContextFromModule("SC_ALP_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
AlpProtoTestDestroy(&ctx);
#ifdef __SC_CUDA_SUPPORT__
if (SCCudaCtxPopCurrent(NULL) == -1) {
printf("Call to SCCudaCtxPopCurrent() failed\n");
return 0;
}
#endif
return r;
}
@ -1171,14 +985,6 @@ int AlpDetectTest08(void) {
AlpProtoDetectCtx ctx;
AlpProtoDetectThreadCtx tctx;
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadAPC();
if (SCCudaHlPushCudaContextFromModule("SC_ALP_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
AlpProtoInit(&ctx);
AlpProtoAdd(&ctx, "smb", IPPROTO_TCP, ALPROTO_SMB, buf, 8, 4, STREAM_TOCLIENT);
@ -1201,23 +1007,8 @@ int AlpDetectTest08(void) {
r = 0;
}
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadAPC();
if (SCCudaHlPushCudaContextFromModule("SC_ALP_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
AlpProtoTestDestroy(&ctx);
#ifdef __SC_CUDA_SUPPORT__
if (SCCudaCtxPopCurrent(NULL) == -1) {
printf("Call to SCCudaCtxPopCurrent() failed\n");
return 0;
}
#endif
return r;
}
@ -1236,14 +1027,6 @@ int AlpDetectTest09(void) {
AlpProtoDetectCtx ctx;
AlpProtoDetectThreadCtx tctx;
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadAPC();
if (SCCudaHlPushCudaContextFromModule("SC_ALP_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
AlpProtoInit(&ctx);
AlpProtoAdd(&ctx, "smb2", IPPROTO_TCP, ALPROTO_SMB2, buf, 8, 4, STREAM_TOCLIENT);
@ -1266,22 +1049,8 @@ int AlpDetectTest09(void) {
r = 0;
}
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadAPC();
if (SCCudaHlPushCudaContextFromModule("SC_ALP_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
AlpProtoTestDestroy(&ctx);
#ifdef __SC_CUDA_SUPPORT__
if (SCCudaCtxPopCurrent(NULL) == -1) {
printf("Call to SCCudaCtxPopCurrent() failed\n");
return 0;
}
#endif
return r;
}
@ -1296,14 +1065,6 @@ int AlpDetectTest10(void) {
AlpProtoDetectCtx ctx;
AlpProtoDetectThreadCtx tctx;
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadAPC();
if (SCCudaHlPushCudaContextFromModule("SC_ALP_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
AlpProtoInit(&ctx);
AlpProtoAdd(&ctx, "dcerpc", IPPROTO_TCP, ALPROTO_DCERPC, buf, 4, 0, STREAM_TOCLIENT);
@ -1326,23 +1087,8 @@ int AlpDetectTest10(void) {
r = 0;
}
#ifdef __SC_CUDA_SUPPORT__
B2gCudaKillDispatcherThreadAPC();
if (SCCudaHlPushCudaContextFromModule("SC_ALP_CONTENT_B2G_CUDA") == -1) {
printf("Call to SCCudaHlPushCudaContextForModule() failed\n");
return 0;
}
#endif
AlpProtoTestDestroy(&ctx);
#ifdef __SC_CUDA_SUPPORT__
if (SCCudaCtxPopCurrent(NULL) == -1) {
printf("Call to SCCudaCtxPopCurrent() failed\n");
return 0;
}
#endif
return r;
}

File diff suppressed because it is too large Load Diff

@ -1,145 +0,0 @@
/**
* Copyright (c) 2010 Open Information Security Foundation.
*
* \author Anoop Saldanha <anoopsaldanha@gmail.com>
*/
#ifndef __CUDA_PACKET_BATCHER_H__
#define __CUDA_PACKET_BATCHER_H__
#include "suricata-common.h"
/* compile in, only if we have a CUDA enabled on this machine */
#ifdef __SC_CUDA_SUPPORT__
#include "util-cuda.h"
/* The min no of packets that we allot the buffer for. We will make
* this user configurable(yaml) based on the traffic they expect. Either ways
* for a low/medium traffic network with occasional sgh matches, we shouldn't
* be enabling cuda. We will only end up screwing performance */
#define SC_CUDA_PB_MIN_NO_OF_PACKETS 4000
/* the maximum payload size we're sending to the card (defined in decode.h) */
#define SC_CUDA_PB_MAX_PAYLOAD_SIZE CUDA_MAX_PAYLOAD_SIZE
/**
* \brief Implement the template SCDQGenericQData to transfer the cuda
* packet buffer from the cuda batcher thread to the dispatcher
* thread using the queue SCDQDataQueue.
*/
typedef struct SCCudaPBPacketsBuffer_ {
/* these members from the template SCDQGenericQData that have to be
* compulsarily implemented */
struct SCDQGenericQData_ *next;
struct SCDQGenericQData_ *prev;
/* if we want to consider this pointer as the head of a list, this var
* holds the no of elements in the list */
//uint16_t len;
/* in case this data instance is the head of a list, we can refer the
* bottomost instance directly using this var */
//struct SCDQGenericaQData *bot;
/* our own members from here on*/
/* current count of packets held in packets_buffer. nop = no of packets */
uint32_t nop_in_buffer;
/* the packets buffer. We will assign buffer for SC_CUDA_PB_MIN_NO_OF_PACKETS
* packets. Basically the size of this buffer would be
* SC_CUDA_PB_MIN_NO_OF_PACKETS * sizeof(SCCudaPBPacketDataForGPU), so that
* we can hold mininum SC_CUDA_PB_MIN_NO_OF_PACKETS */
uint8_t *packets_buffer;
/* length of data buffered so far in packets_buffer, which would be sent
* to the GPU. We will need this to copy the buffered data from the
* packets_buffer here on the host, to the buffer on the GPU */
uint32_t packets_buffer_len;
/* packet offset within the packets_buffer. Each packet would be stored in
* packets buffer at a particular offset. This buffer would indicate the
* offset of a packet inside the packet buffer. We will allot space to hold
* offsets for SC_CUDA_PB_MIN_NO_OF_PACKETS packets
* \todo change it to holds offsets for more than SC_CUDA_PB_MIN_NO_OF_PACKETS
* when we use the buffer to hold packets based on the remaining size in the
* buffer rather than on a fixed limit like SC_CUDA_PB_MIN_NO_OF_PACKETS */
uint32_t *packets_offset_buffer;
/* the total packet payload lengths buffered so far. We will need this to
* transfer the total length of the results buffer that has to be transferred
* back from the gpu */
uint32_t packets_total_payload_len;
/* the payload offsets for the different payload lengths buffered in. For
* example if we buffer 4 packets of lengths 3, 4, 5, 6, we will store four
* offsets in the buffer {0, 3, 7, 12, 18} */
uint32_t *packets_payload_offset_buffer;
/* packet addresses for all the packets buffered in the packets_buffer. We
* will allot space to hold packet addresses for SC_CUDA_PB_MIN_NO_OF_PACKETS.
* We will need this, so that the cuda mpm b2g dispatcher thread can inform
* and store the b2g cuda mpm results for the packet*/
Packet **packets_address_buffer;
} SCCudaPBPacketsBuffer;
/**
* \brief Structure for each packet that is being batched to the GPU.
*/
typedef struct SCCudaPBPacketDataForGPU_ {
/* holds B2gCudaCtx->m */
unsigned int m;
/* holds B2gCudaCtx->cuda_B2g */
CUdeviceptr table;
/* holds the length of the payload */
unsigned int payload_len;
/* holds the payload. While we actually store the payload in the buffer,
* we may not end up using the entire 1480 bytes if the payload is smaller */
uint8_t payload[SC_CUDA_PB_MAX_PAYLOAD_SIZE];
} SCCudaPBPacketDataForGPU;
/**
* \brief Same as struct SCCudaPBPacketDataForGPU_ except for the payload part.
* We will need this for calculating the size of the non-payload part
* of the packet data to be buffered.
*/
typedef struct SCCudaPBPacketDataForGPUNonPayload_ {
/* holds B2gCudaCtx->m */
unsigned int m;
/* holds B2gCudaCtx->cuda_B2g */
CUdeviceptr table;
/* holds the length of the payload */
unsigned int payload_len;
} SCCudaPBPacketDataForGPUNonPayload;
/**
* \brief The cuda packet batcher threading context.
*/
typedef struct SCCudaPBThreadCtx_ {
/* we need the detection engine context to retrieve the sgh while we start
* receiving and batching the packets */
DetectEngineCtx *de_ctx;
/* packets buffer currently in use inside the cuda batcher thread */
SCCudaPBPacketsBuffer *curr_pb;
} SCCudaPBThreadCtx;
SCCudaPBPacketsBuffer *SCCudaPBAllocSCCudaPBPacketsBuffer(void);
void SCCudaPBDeAllocSCCudaPBPacketsBuffer(SCCudaPBPacketsBuffer *);
void SCCudaPBSetBufferPacketThreshhold(uint32_t);
void SCCudaPBCleanUpQueuesAndBuffers(void);
void SCCudaPBSetUpQueuesAndBuffers(void);
void SCCudaPBKillBatchingPackets(void);
TmEcode SCCudaPBBatchPackets(ThreadVars *, Packet *, void *, PacketQueue *, PacketQueue *);
TmEcode SCCudaPBThreadInit(ThreadVars *, void *, void **);
TmEcode SCCudaPBThreadDeInit(ThreadVars *, void *);
void SCCudaPBThreadExitStats(ThreadVars *, void *);
void SCCudaPBRegisterTests(void);
void TmModuleCudaPacketBatcherRegister(void);
void *SCCudaPBTmThreadsSlot1(void *);
void SCCudaPBRunningTests(int);
void SCCudaPBSetProfile(char *);
#endif /* __SC_CUDA_SUPPORT__ */
#endif /* __CUDA_PACKET_BATCHER_H__ */

File diff suppressed because it is too large Load Diff

@ -77,10 +77,6 @@ enum {
#include "app-layer-protos.h"
#ifdef __SC_CUDA_SUPPORT__
#define CUDA_MAX_PAYLOAD_SIZE 1500
#endif
/* forward declaration */
struct DetectionEngineThreadCtx_;
@ -488,26 +484,6 @@ typedef struct Packet_
* It should always point to the lowest
* packet in a encapsulated packet */
/* required for cuda support */
#ifdef __SC_CUDA_SUPPORT__
/* indicates if the cuda mpm would be conducted or a normal cpu mpm would
* be conduced on this packet. If it is set to 0, the cpu mpm; else cuda mpm */
uint8_t cuda_mpm_enabled;
/* indicates if the cuda mpm has finished running the mpm and processed the
* results for this packet, assuming if cuda_mpm_enabled has been set for this
* packet */
uint16_t cuda_done;
/* used by the detect thread and the cuda mpm dispatcher thread. The detect
* thread would wait on this cond var, if the cuda mpm dispatcher thread
* still hasn't processed the packet. The dispatcher would use this cond
* to inform the detect thread(in case it is waiting on this packet), once
* the dispatcher is done processing the packet results */
SCMutex cuda_mutex;
SCCondT cuda_cond;
/* the extra 1 in the 1481, is to hold the no_of_matches from the mpm run */
uint16_t mpm_offsets[CUDA_MAX_PAYLOAD_SIZE + 1];
#endif
#ifdef PROFILING
PktProfiling profile;
#endif
@ -610,23 +586,12 @@ typedef struct DecodeThreadVars_
/**
* \brief Initialize a packet structure for use.
*/
#ifndef __SC_CUDA_SUPPORT__
#define PACKET_INITIALIZE(p) { \
SCMutexInit(&(p)->tunnel_mutex, NULL); \
PACKET_RESET_CHECKSUMS((p)); \
(p)->pkt = ((uint8_t *)(p)) + sizeof(Packet); \
(p)->livedev = NULL; \
}
#else
#define PACKET_INITIALIZE(p) { \
SCMutexInit(&(p)->tunnel_mutex, NULL); \
PACKET_RESET_CHECKSUMS((p)); \
SCMutexInit(&(p)->cuda_mutex, NULL); \
SCCondInit(&(p)->cuda_cond, NULL); \
(p)->pkt = ((uint8_t *)(p)) + sizeof(Packet); \
(p)->livedev = NULL; \
}
#endif
/**
* \brief Recycle a packet structure for reuse.
@ -699,39 +664,17 @@ typedef struct DecodeThreadVars_
PACKET_PROFILING_RESET((p)); \
} while (0)
#ifndef __SC_CUDA_SUPPORT__
#define PACKET_RECYCLE(p) PACKET_DO_RECYCLE((p))
#else
#define PACKET_RECYCLE(p) do { \
PACKET_DO_RECYCLE((p)); \
SCMutexDestroy(&(p)->cuda_mutex); \
SCCondDestroy(&(p)->cuda_cond); \
SCMutexInit(&(p)->cuda_mutex, NULL); \
SCCondInit(&(p)->cuda_cond, NULL); \
PACKET_RESET_CHECKSUMS((p)); \
} while(0)
#endif
/**
* \brief Cleanup a packet so that we can free it. No memset needed..
*/
#ifndef __SC_CUDA_SUPPORT__
#define PACKET_CLEANUP(p) do { \
if ((p)->pktvar != NULL) { \
PktVarFree((p)->pktvar); \
} \
SCMutexDestroy(&(p)->tunnel_mutex); \
} while (0)
#else
#define PACKET_CLEANUP(p) do { \
if ((p)->pktvar != NULL) { \
PktVarFree((p)->pktvar); \
} \
SCMutexDestroy(&(p)->tunnel_mutex); \
SCMutexDestroy(&(p)->cuda_mutex); \
SCCondDestroy(&(p)->cuda_cond); \
} while(0)
#endif
/* macro's for setting the action

@ -49,9 +49,6 @@
#include "stream.h"
#include "util-cuda-handlers.h"
#include "util-mpm-b2g-cuda.h"
#include "util-enum.h"
#include "util-debug.h"
#include "util-print.h"
@ -59,11 +56,7 @@
/** \todo make it possible to use multiple pattern matcher algorithms next to
eachother. */
#ifdef __SC_CUDA_SUPPORT__
#define PM MPM_B2G_CUDA
#else
#define PM MPM_AC
#endif
#define POPULATE_MPM_AVOID_PACKET_MPM_PATTERNS 0x01
#define POPULATE_MPM_AVOID_STREAM_MPM_PATTERNS 0x02
@ -228,36 +221,11 @@ uint32_t PacketPatternSearch(DetectEngineThreadCtx *det_ctx, Packet *p)
if (mpm_ctx == NULL)
SCReturnInt(0);
#ifndef __SC_CUDA_SUPPORT__
ret = mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtc,
&det_ctx->pmq,
p->payload,
p->payload_len);
#else
/* if the user has enabled cuda support, but is not using the cuda mpm
* algo, then we shouldn't take the path of the dispatcher. Call the mpm
* directly */
if (mpm_ctx->mpm_type != MPM_B2G_CUDA) {
ret = mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtc,
&det_ctx->pmq,
p->payload,
p->payload_len);
SCReturnInt(ret);
}
if (p->cuda_mpm_enabled) {
ret = B2gCudaResultsPostProcessing(p, mpm_ctx, &det_ctx->mtc,
&det_ctx->pmq);
} else {
ret = mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
&det_ctx->mtc,
&det_ctx->pmq,
p->payload,
p->payload_len);
}
#endif
SCReturnInt(ret);
}
@ -2125,13 +2093,8 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
SCLogDebug("sh->mpm_proto_tcp_ctx == NULL. This should never happen");
exit(EXIT_FAILURE);
}
#ifndef __SC_CUDA_SUPPORT__
MpmInitCtx(sh->mpm_proto_tcp_ctx_ts, de_ctx->mpm_matcher, -1);
MpmInitCtx(sh->mpm_proto_tcp_ctx_tc, de_ctx->mpm_matcher, -1);
#else
MpmInitCtx(sh->mpm_proto_tcp_ctx_ts, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
MpmInitCtx(sh->mpm_proto_tcp_ctx_tc, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
#endif
if (de_ctx->sgh_mpm_context == ENGINE_SGH_MPM_FACTORY_CONTEXT_SINGLE) {
sh->mpm_proto_udp_ctx_ts = MpmFactoryGetMpmCtxForProfile(de_ctx, de_ctx->sgh_mpm_context_proto_udp_packet, 0);
@ -2144,13 +2107,8 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
SCLogDebug("sh->mpm_proto_udp_ctx == NULL. This should never happen");
exit(EXIT_FAILURE);
}
#ifndef __SC_CUDA_SUPPORT__
MpmInitCtx(sh->mpm_proto_udp_ctx_ts, de_ctx->mpm_matcher, -1);
MpmInitCtx(sh->mpm_proto_udp_ctx_tc, de_ctx->mpm_matcher, -1);
#else
MpmInitCtx(sh->mpm_proto_udp_ctx_ts, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
MpmInitCtx(sh->mpm_proto_udp_ctx_tc, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
#endif
if (de_ctx->sgh_mpm_context == ENGINE_SGH_MPM_FACTORY_CONTEXT_SINGLE) {
sh->mpm_proto_other_ctx =
@ -2163,11 +2121,7 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
SCLogDebug("sh->mpm_proto_other_ctx == NULL. This should never happen");
exit(EXIT_FAILURE);
}
#ifndef __SC_CUDA_SUPPORT__
MpmInitCtx(sh->mpm_proto_other_ctx, de_ctx->mpm_matcher, -1);
#else
MpmInitCtx(sh->mpm_proto_other_ctx, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
#endif
} /* if (has_co_packet) */
if (has_co_stream) {
@ -2182,14 +2136,8 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
SCLogDebug("sh->mpm_stream_ctx == NULL. This should never happen");
exit(EXIT_FAILURE);
}
#ifndef __SC_CUDA_SUPPORT__
MpmInitCtx(sh->mpm_stream_ctx_ts, de_ctx->mpm_matcher, -1);
MpmInitCtx(sh->mpm_stream_ctx_tc, de_ctx->mpm_matcher, -1);
#else
MpmInitCtx(sh->mpm_stream_ctx_ts, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
MpmInitCtx(sh->mpm_stream_ctx_tc, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
#endif
}
if (has_co_uri) {
@ -2205,13 +2153,8 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
exit(EXIT_FAILURE);
}
#ifndef __SC_CUDA_SUPPORT__
MpmInitCtx(sh->mpm_uri_ctx_ts, de_ctx->mpm_matcher, -1);
MpmInitCtx(sh->mpm_uri_ctx_tc, de_ctx->mpm_matcher, -1);
#else
MpmInitCtx(sh->mpm_uri_ctx_ts, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
MpmInitCtx(sh->mpm_uri_ctx_tc, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
#endif
}
if (has_co_hcbd) {
@ -2227,13 +2170,8 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
exit(EXIT_FAILURE);
}
#ifndef __SC_CUDA_SUPPORT__
MpmInitCtx(sh->mpm_hcbd_ctx_ts, de_ctx->mpm_matcher, -1);
MpmInitCtx(sh->mpm_hcbd_ctx_tc, de_ctx->mpm_matcher, -1);
#else
MpmInitCtx(sh->mpm_hcbd_ctx_ts, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
MpmInitCtx(sh->mpm_hcbd_ctx_tc, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
#endif
}
if (has_co_hsbd) {
@ -2249,13 +2187,8 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
exit(EXIT_FAILURE);
}
#ifndef __SC_CUDA_SUPPORT__
MpmInitCtx(sh->mpm_hsbd_ctx_ts, de_ctx->mpm_matcher, -1);
MpmInitCtx(sh->mpm_hsbd_ctx_tc, de_ctx->mpm_matcher, -1);
#else
MpmInitCtx(sh->mpm_hsbd_ctx_ts, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
MpmInitCtx(sh->mpm_hsbd_ctx_tc, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
#endif
}
if (has_co_hhd) {
@ -2271,13 +2204,8 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
exit(EXIT_FAILURE);
}
#ifndef __SC_CUDA_SUPPORT__
MpmInitCtx(sh->mpm_hhd_ctx_ts, de_ctx->mpm_matcher, -1);
MpmInitCtx(sh->mpm_hhd_ctx_tc, de_ctx->mpm_matcher, -1);
#else
MpmInitCtx(sh->mpm_hhd_ctx_ts, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
MpmInitCtx(sh->mpm_hhd_ctx_tc, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
#endif
}
if (has_co_hrhd) {
@ -2293,13 +2221,8 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
exit(EXIT_FAILURE);
}
#ifndef __SC_CUDA_SUPPORT__
MpmInitCtx(sh->mpm_hrhd_ctx_ts, de_ctx->mpm_matcher, -1);
MpmInitCtx(sh->mpm_hrhd_ctx_tc, de_ctx->mpm_matcher, -1);
#else
MpmInitCtx(sh->mpm_hrhd_ctx_ts, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
MpmInitCtx(sh->mpm_hrhd_ctx_tc, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
#endif
}
if (has_co_hmd) {
@ -2315,13 +2238,8 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
exit(EXIT_FAILURE);
}
#ifndef __SC_CUDA_SUPPORT__
MpmInitCtx(sh->mpm_hmd_ctx_ts, de_ctx->mpm_matcher, -1);
MpmInitCtx(sh->mpm_hmd_ctx_tc, de_ctx->mpm_matcher, -1);
#else
MpmInitCtx(sh->mpm_hmd_ctx_ts, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
MpmInitCtx(sh->mpm_hmd_ctx_tc, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
#endif
}
if (has_co_hcd) {
@ -2337,13 +2255,8 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
exit(EXIT_FAILURE);
}
#ifndef __SC_CUDA_SUPPORT__
MpmInitCtx(sh->mpm_hcd_ctx_ts, de_ctx->mpm_matcher, -1);
MpmInitCtx(sh->mpm_hcd_ctx_tc, de_ctx->mpm_matcher, -1);
#else
MpmInitCtx(sh->mpm_hcd_ctx_ts, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
MpmInitCtx(sh->mpm_hcd_ctx_tc, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
#endif
}
if (has_co_hrud) {
@ -2359,13 +2272,8 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
exit(EXIT_FAILURE);
}
#ifndef __SC_CUDA_SUPPORT__
MpmInitCtx(sh->mpm_hrud_ctx_ts, de_ctx->mpm_matcher, -1);
MpmInitCtx(sh->mpm_hrud_ctx_tc, de_ctx->mpm_matcher, -1);
#else
MpmInitCtx(sh->mpm_hrud_ctx_ts, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
MpmInitCtx(sh->mpm_hrud_ctx_tc, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
#endif
}
if (has_co_hsmd) {
@ -2381,13 +2289,8 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
exit(EXIT_FAILURE);
}
#ifndef __SC_CUDA_SUPPORT__
MpmInitCtx(sh->mpm_hsmd_ctx_ts, de_ctx->mpm_matcher, -1);
MpmInitCtx(sh->mpm_hsmd_ctx_tc, de_ctx->mpm_matcher, -1);
#else
MpmInitCtx(sh->mpm_hsmd_ctx_ts, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
MpmInitCtx(sh->mpm_hsmd_ctx_tc, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
#endif
}
if (has_co_hscd) {
@ -2403,13 +2306,8 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
exit(EXIT_FAILURE);
}
#ifndef __SC_CUDA_SUPPORT__
MpmInitCtx(sh->mpm_hscd_ctx_ts, de_ctx->mpm_matcher, -1);
MpmInitCtx(sh->mpm_hscd_ctx_tc, de_ctx->mpm_matcher, -1);
#else
MpmInitCtx(sh->mpm_hscd_ctx_ts, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
MpmInitCtx(sh->mpm_hscd_ctx_tc, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
#endif
}
if (has_co_huad) {
@ -2425,13 +2323,8 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
exit(EXIT_FAILURE);
}
#ifndef __SC_CUDA_SUPPORT__
MpmInitCtx(sh->mpm_huad_ctx_ts, de_ctx->mpm_matcher, -1);
MpmInitCtx(sh->mpm_huad_ctx_tc, de_ctx->mpm_matcher, -1);
#else
MpmInitCtx(sh->mpm_huad_ctx_ts, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
MpmInitCtx(sh->mpm_huad_ctx_tc, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
#endif
}
if (has_co_hhhd) {
@ -2447,13 +2340,8 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
exit(EXIT_FAILURE);
}
#ifndef __SC_CUDA_SUPPORT__
MpmInitCtx(sh->mpm_hhhd_ctx_ts, de_ctx->mpm_matcher, -1);
MpmInitCtx(sh->mpm_hhhd_ctx_tc, de_ctx->mpm_matcher, -1);
#else
MpmInitCtx(sh->mpm_hhhd_ctx_ts, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
MpmInitCtx(sh->mpm_hhhd_ctx_tc, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
#endif
}
if (has_co_hrhhd) {
@ -2469,13 +2357,8 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
exit(EXIT_FAILURE);
}
#ifndef __SC_CUDA_SUPPORT__
MpmInitCtx(sh->mpm_hrhhd_ctx_ts, de_ctx->mpm_matcher, -1);
MpmInitCtx(sh->mpm_hrhhd_ctx_tc, de_ctx->mpm_matcher, -1);
#else
MpmInitCtx(sh->mpm_hrhhd_ctx_ts, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
MpmInitCtx(sh->mpm_hrhhd_ctx_tc, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
#endif
}
if (has_co_packet ||

@ -183,8 +183,6 @@
#include "util-unittest-helper.h"
#include "util-debug.h"
#include "util-hashlist.h"
#include "util-cuda-handlers.h"
#include "util-mpm-b2g-cuda.h"
#include "util-cuda.h"
#include "util-privs.h"
#include "util-profiling.h"
@ -4431,31 +4429,6 @@ int SigGroupBuild(DetectEngineCtx *de_ctx)
exit(EXIT_FAILURE);
}
#ifdef __SC_CUDA_SUPPORT__
size_t cuda_total = 0;
size_t cuda_free_before_alloc = 0;
/* we register a module that would require cuda handler service. This
* module would hold the context for all the patterns in the rules */
de_ctx->cuda_rc_mod_handle = SCCudaHlRegisterModule("SC_RULES_CONTENT_B2G_CUDA");
if (de_ctx->mpm_matcher == MPM_B2G_CUDA) {
CUcontext dummy_context;
if (SCCudaHlGetCudaContext(&dummy_context, "mpm",
de_ctx->cuda_rc_mod_handle) == -1) {
SCLogError(SC_ERR_B2G_CUDA_ERROR, "Error getting a cuda context for the "
"module SC_RULES_CONTENT_B2G_CUDA");
}
SCCudaCtxPushCurrent(dummy_context);
if (SCCudaMemGetInfo(&cuda_free_before_alloc, &cuda_total) == 0) {
SCLogInfo("Total Memory available in the CUDA context used for mpm "
"with b2g: %.2f MB", cuda_total/(1024.0 * 1024.0));
SCLogInfo("Free Memory available in the CUDA context used for b2g "
"mpm before any allocation is made on the GPU for the "
"context: %.2f MB", cuda_free_before_alloc/(1024.0 * 1024.0));
}
}
#endif
if (SigAddressPrepareStage3(de_ctx) != 0) {
SCLogError(SC_ERR_DETECT_PREPARE, "initializing the detection engine failed");
exit(EXIT_FAILURE);
@ -4465,32 +4438,6 @@ int SigGroupBuild(DetectEngineCtx *de_ctx)
exit(EXIT_FAILURE);
}
#ifdef __SC_CUDA_SUPPORT__
size_t cuda_free_after_alloc = 0;
/* if a user has selected some other mpm algo other than b2g_cuda, inspite of
* enabling cuda support, then no cuda contexts or cuda vars would be created.
* Pop the cuda context, only on confirming that the MPM algo selected is the
* CUDA mpm algo */
if (de_ctx->mpm_matcher == MPM_B2G_CUDA) {
if (SCCudaMemGetInfo(&cuda_free_after_alloc, &cuda_total) == 0) {
SCLogInfo("Free Memory available in the CUDA context used for b2g mpm "
"after allocation is made on the GPU for the context: %.2f MB",
cuda_free_after_alloc/(1024.0 * 1024.0));
SCLogInfo("Total memory consumed by the CUDA context for the b2g mpm: "
"%.2f MB", (cuda_free_before_alloc/(1024.0 * 1024.0)) -
(cuda_free_after_alloc/(1024.0 * 1024.0)));
}
/* the AddressPrepareStage3 actually handles the creation of device
* pointers on the gpu. The cuda context that stage3 used would still be
* attached to this host thread. We need to pop this cuda context so that
* the dispatcher thread that we are going to create for the above module
* we registered can attach to this cuda context */
CUcontext context;
if (SCCudaCtxPopCurrent(&context) == -1)
exit(EXIT_FAILURE);
}
#endif
if (de_ctx->sgh_mpm_context == ENGINE_SGH_MPM_FACTORY_CONTEXT_SINGLE) {
MpmCtx *mpm_ctx = NULL;
mpm_ctx = MpmFactoryGetMpmCtxForProfile(de_ctx, de_ctx->sgh_mpm_context_proto_tcp_packet, 0);

@ -622,13 +622,6 @@ typedef struct DetectEngineCtx_ {
uint16_t mpm_matcher; /**< mpm matcher this ctx uses */
#ifdef __SC_CUDA_SUPPORT__
/* cuda rules content module handle. Holds the handler serivice's
* (util-cuda-handler.c) handle for a module. This module would
* hold the cuda context for all the rules content */
int cuda_rc_mod_handle;
#endif
/* Config options */
uint16_t max_uniq_toclient_src_groups;
@ -843,12 +836,6 @@ typedef struct DetectionEngineThreadCtx_ {
} filestore[DETECT_FILESTORE_MAX];
DetectEngineCtx *de_ctx;
#ifdef __SC_CUDA_SUPPORT__
/* each detection thread would have it's own queue where the cuda dispatcher
* thread can dump the packets once it has processed them */
Tmq *cuda_mpm_rc_disp_outq;
#endif
/** store for keyword contexts that need a per thread storage because of
* thread safety issues */
void **keyword_ctxs_array;

@ -48,8 +48,6 @@
#include "util-unittest.h"
#include "util-unittest-helper.h"
#include "util-classification-config.h"
#include "util-mpm-b2g-cuda.h"
#include "util-cuda-handlers.h"
#include "util-privs.h"
#include "util-print.h"
#include "util-proto-name.h"

@ -39,7 +39,6 @@
#include "runmode-af-packet.h"
#include "log-httplog.h"
#include "output.h"
#include "cuda-packet-batcher.h"
#include "detect-engine-mpm.h"
#include "alert-fastlog.h"

@ -22,7 +22,6 @@
#include "runmode-erf-dag.h"
#include "log-httplog.h"
#include "output.h"
#include "cuda-packet-batcher.h"
#include "source-pfring.h"
#include "alert-fastlog.h"

@ -22,7 +22,6 @@
#include "runmode-erf-file.h"
#include "log-httplog.h"
#include "output.h"
#include "cuda-packet-batcher.h"
#include "source-pfring.h"
#include "alert-fastlog.h"

@ -33,7 +33,6 @@
#include "runmode-ipfw.h"
#include "log-httplog.h"
#include "output.h"
#include "cuda-packet-batcher.h"
#include "source-pfring.h"
#include "alert-fastlog.h"

@ -32,7 +32,6 @@
#include "runmode-nfq.h"
#include "log-httplog.h"
#include "output.h"
#include "cuda-packet-batcher.h"
#include "source-pfring.h"
#include "alert-fastlog.h"

@ -22,7 +22,6 @@
#include "runmode-pcap-file.h"
#include "log-httplog.h"
#include "output.h"
#include "cuda-packet-batcher.h"
#include "source-pfring.h"
#include "detect-engine-mpm.h"
@ -150,7 +149,6 @@ int RunModeFilePcapAuto(DetectEngineCtx *de_ctx)
char tname[16];
uint16_t cpu = 0;
TmModule *tm_module;
int cuda = 0;
RunModeInitialize();
/* Available cpus */
@ -165,116 +163,42 @@ int RunModeFilePcapAuto(DetectEngineCtx *de_ctx)
TimeModeSetOffline();
#if defined(__SC_CUDA_SUPPORT__)
if (PatternMatchDefaultMatcher() == MPM_B2G_CUDA) {
cuda = 1;
/* create the threads */
ThreadVars *tv_receivepcap =
TmThreadCreatePacketHandler("ReceivePcapFile",
"packetpool", "packetpool",
"detect-queue1", "simple",
"pktacqloop");
if (tv_receivepcap == NULL) {
printf("ERROR: TmThreadsCreate failed\n");
exit(EXIT_FAILURE);
}
#endif
if (cuda == 0) {
/* create the threads */
ThreadVars *tv_receivepcap =
TmThreadCreatePacketHandler("ReceivePcapFile",
"packetpool", "packetpool",
"detect-queue1", "simple",
"pktacqloop");
if (tv_receivepcap == NULL) {
printf("ERROR: TmThreadsCreate failed\n");
exit(EXIT_FAILURE);
}
tm_module = TmModuleGetByName("ReceivePcapFile");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName failed for ReceivePcap\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_receivepcap, tm_module, file);
tm_module = TmModuleGetByName("DecodePcapFile");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName DecodePcap failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_receivepcap, tm_module, NULL);
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_receivepcap, tm_module, (void *)de_ctx);
TmThreadSetCPU(tv_receivepcap, RECEIVE_CPU_SET);
if (TmThreadSpawn(tv_receivepcap) != TM_ECODE_OK) {
printf("ERROR: TmThreadSpawn failed\n");
exit(EXIT_FAILURE);
}
#if defined(__SC_CUDA_SUPPORT__)
} else {
/* create the threads */
ThreadVars *tv_receivepcap =
TmThreadCreatePacketHandler("ReceivePcapFile",
"packetpool", "packetpool",
"cuda-pb", "simple",
"pktacqloop");
if (tv_receivepcap == NULL) {
printf("ERROR: TmThreadsCreate failed\n");
exit(EXIT_FAILURE);
}
tm_module = TmModuleGetByName("ReceivePcapFile");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName failed for ReceivePcap\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_receivepcap, tm_module, file);
TmThreadSetCPU(tv_receivepcap, RECEIVE_CPU_SET);
tm_module = TmModuleGetByName("DecodePcapFile");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName DecodePcap failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_receivepcap, tm_module, NULL);
TmThreadSetCPU(tv_receivepcap, RECEIVE_CPU_SET);
if (TmThreadSpawn(tv_receivepcap) != TM_ECODE_OK) {
printf("ERROR: TmThreadSpawn failed\n");
exit(EXIT_FAILURE);
}
ThreadVars *tv_cuda_PB =
TmThreadCreate("CUDA_PB",
"cuda-pb", "simple",
"detect-queue1", "simple",
"custom", SCCudaPBTmThreadsSlot1, 0);
if (tv_cuda_PB == NULL) {
printf("ERROR: TmThreadsCreate failed for CUDA_PB\n");
exit(EXIT_FAILURE);
}
tv_cuda_PB->type = TVT_PPT;
tm_module = TmModuleGetByName("ReceivePcapFile");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName failed for ReceivePcap\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_receivepcap, tm_module, file);
tm_module = TmModuleGetByName("CudaPacketBatcher");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName CudaPacketBatcher failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_cuda_PB, tm_module, de_ctx);
tm_module = TmModuleGetByName("DecodePcapFile");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName DecodePcap failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_receivepcap, tm_module, NULL);
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_cuda_PB, tm_module, NULL);
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_receivepcap, tm_module, (void *)de_ctx);
if (TmThreadSpawn(tv_cuda_PB) != TM_ECODE_OK) {
printf("ERROR: TmThreadSpawn failed\n");
exit(EXIT_FAILURE);
}
TmThreadSetCPU(tv_receivepcap, RECEIVE_CPU_SET);
#endif
if (TmThreadSpawn(tv_receivepcap) != TM_ECODE_OK) {
printf("ERROR: TmThreadSpawn failed\n");
exit(EXIT_FAILURE);
}
/* start with cpu 1 so that if we're creating an odd number of detect

@ -22,7 +22,6 @@
#include "runmode-pcap.h"
#include "log-httplog.h"
#include "output.h"
#include "cuda-packet-batcher.h"
#include "source-pfring.h"
#include "detect-engine-mpm.h"

@ -23,7 +23,6 @@
#include "source-pfring.h"
#include "log-httplog.h"
#include "output.h"
#include "cuda-packet-batcher.h"
#include "source-pfring.h"
#include "alert-fastlog.h"

@ -22,7 +22,6 @@
#include "runmode-pcap-file.h"
#include "log-httplog.h"
#include "output.h"
#include "cuda-packet-batcher.h"
#include "source-pfring.h"
#include "detect-engine-mpm.h"

@ -46,8 +46,6 @@
#include "output.h"
#include "cuda-packet-batcher.h"
#include "source-pfring.h"
int debuglog_enabled = 0;

@ -178,11 +178,6 @@
#include "util-daemon.h"
#include "reputation.h"
/* holds the cuda b2g module */
#include "util-mpm-b2g-cuda.h"
#include "util-cuda-handlers.h"
#include "cuda-packet-batcher.h"
#include "output.h"
#include "util-privs.h"
@ -1455,11 +1450,6 @@ int main(int argc, char **argv)
* logging module. */
SCLogLoadConfig(daemon);
#ifdef __SC_CUDA_SUPPORT__
/* load the cuda configuration */
SCCudaHlGetYamlConf();
#endif /* __SC_CUDA_SUPPORT__ */
/* Load the Host-OS lookup. */
SCHInfoLoadFromConfig();
if (!list_keywords && !list_app_layer_protocols &&
@ -1598,11 +1588,6 @@ int main(int argc, char **argv)
/* file log */
TmModuleLogFileLogRegister();
TmModuleLogFilestoreRegister();
/* cuda */
#ifdef __SC_CUDA_SUPPORT__
TmModuleCudaMpmB2gRegister();
TmModuleCudaPacketBatcherRegister();
#endif
TmModuleDebugList();
AppLayerHtpNeedFileInspection();
@ -1724,15 +1709,6 @@ 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);
}
@ -1897,10 +1873,6 @@ int main(int argc, char **argv)
if (sig_file == NULL && rule_reload == 1)
UtilSignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2);
#ifdef __SC_CUDA_SUPPORT__
SCCudaPBSetUpQueuesAndBuffers();
#endif /* __SC_CUDA_SUPPORT__ */
SCThresholdConfInitContext(de_ctx,NULL);
SCAsn1LoadConfig();
@ -1962,14 +1934,6 @@ int main(int argc, char **argv)
RunModeDispatch(run_mode, runmode_custom_mode, de_ctx);
#ifdef __SC_CUDA_SUPPORT__
if (PatternMatchDefaultMatcher() == MPM_B2G_CUDA) {
/* start the dispatcher thread for this module */
if (B2gCudaStartDispatcherThreadRC("SC_RULES_CONTENT_B2G_CUDA") == -1)
exit(EXIT_FAILURE);
}
#endif
/* In Unix socket runmode, Flow manager is started on demand */
if (run_mode != RUNMODE_UNIX_SOCKET) {
/* Spawn the unix socket manager thread */
@ -2050,10 +2014,6 @@ int main(int argc, char **argv)
/* Update the engine stage/status flag */
(void) SC_ATOMIC_CAS(&engine_stage, SURICATA_RUNTIME, SURICATA_DEINIT);
#ifdef __SC_CUDA_SUPPORT__
SCCudaPBKillBatchingPackets();
#endif
UnixSocketKillSocketThread();
if (run_mode != RUNMODE_UNIX_SOCKET) {
@ -2119,30 +2079,6 @@ int main(int argc, char **argv)
SCPidfileRemove(pid_filename);
/** \todo review whats needed here */
#ifdef __SC_CUDA_SUPPORT__
if (PatternMatchDefaultMatcher() == MPM_B2G_CUDA) {
/* all threadvars related to cuda should be free by now, which means
* the cuda contexts would be floating */
if (SCCudaHlPushCudaContextFromModule("SC_RULES_CONTENT_B2G_CUDA") == -1) {
SCLogError(SC_ERR_CUDA_HANDLER_ERROR, "Call to "
"SCCudaHlPushCudaContextForModule() failed during the "
"shutdown phase just before the call to SigGroupCleanup()");
}
}
#endif
#ifdef __SC_CUDA_SUPPORT__
if (PatternMatchDefaultMatcher() == MPM_B2G_CUDA) {
/* pop the cuda context we just pushed before the call to SigGroupCleanup() */
if (SCCudaCtxPopCurrent(NULL) == -1) {
SCLogError(SC_ERR_CUDA_HANDLER_ERROR, "Call to SCCudaCtxPopCurrent() "
"during the shutdown phase just before the call to "
"SigGroupCleanup()");
return 0;
}
}
#endif
AppLayerHtpPrintStats();
if (global_de_ctx) {
@ -2174,13 +2110,6 @@ int main(int argc, char **argv)
SCProfilingDestroy();
#endif
#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
#ifdef OS_WIN32
if (daemon) {
return 0;

@ -255,10 +255,6 @@ const char * TmModuleTmmIdToString(TmmId id)
CASE_CODE (TMM_DECODEIPFW);
CASE_CODE (TMM_VERDICTIPFW);
CASE_CODE (TMM_RECEIVEIPFW);
#ifdef __SC_CUDA_SUPPORT__
CASE_CODE (TMM_CUDA_MPM_B2G);
CASE_CODE (TMM_CUDA_PACKET_BATCHER);
#endif
CASE_CODE (TMM_RECEIVEERFFILE);
CASE_CODE (TMM_DECODEERFFILE);
CASE_CODE (TMM_RECEIVEERFDAG);

@ -65,10 +65,6 @@ typedef enum {
TMM_DECODEIPFW,
TMM_VERDICTIPFW,
TMM_RECEIVEIPFW,
#ifdef __SC_CUDA_SUPPORT__
TMM_CUDA_MPM_B2G,
TMM_CUDA_PACKET_BATCHER,
#endif
TMM_RECEIVEERFFILE,
TMM_DECODEERFFILE,
TMM_RECEIVEERFDAG,

File diff suppressed because it is too large Load Diff

@ -1,119 +0,0 @@
/* Copyright (C) 2007-2010 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* \file Provides cuda utility functions.
*
* \author Anoop Saldanha <anoopsaldanha@gmail.com>
*/
/* macros decides if cuda is enabled for the platform or not */
#ifdef __SC_CUDA_SUPPORT__
#include <cuda.h>
#ifndef __UTIL_MPM_CUDA_HANDLERS_H__
#define __UTIL_MPM_CUDA_HANDLERS_H__
typedef enum {
SC_CUDA_HL_MTYPE_RULE_NONE = -1,
SC_CUDA_HL_MTYPE_RULE_CONTENTS = 0,
SC_CUDA_HL_MTYPE_RULE_URICONTENTS,
SC_CUDA_HL_MTYPE_APP_LAYER,
SC_CUDA_HL_MTYPE_RULE_CUSTOM,
SC_CUDA_HL_MTYPE_MAX,
} SCCudaHlModuleType;
typedef struct SCCudaHlModuleDevicePointer_ {
/* device pointer name. This is a primary key. For the same module you
* can't register different device pointers */
char *name;
CUdeviceptr d_ptr;
struct SCCudaHlModuleDevicePointer_ *next;
} SCCudaHlModuleDevicePointer;
typedef struct SCCudaHlModuleCUmodule_ {
/* Handle for this CUmodule. This has to be first obtained from the
* call to SCCudaHlGetCudaModule() or SCCudaHlGetCudaModuleFromFile() */
int cuda_module_handle;
CUmodule cuda_module;
SCCudaHlModuleDevicePointer *device_ptrs;
struct SCCudaHlModuleCUmodule_ *next;
} SCCudaHlModuleCUmodule;
typedef struct SCCudaHlModuleData_ {
/* The unique module handle. This has to be first obtained from the
* call to SCCudaHlGetUniqueHandle() */
const char *name;
int handle;
CUcontext cuda_context;
SCCudaHlModuleCUmodule *cuda_modules;
void *(*SCCudaHlDispFunc)(void *);
struct SCCudaHlModuleData_ *next;
} SCCudaHlModuleData;
/**
* \brief Used to hold the cuda configuration from our conf yaml file
*/
typedef struct SCCudaHlCudaProfile_ {
/* profile name. Should be unique */
char *name;
/* the data associated with this profile */
void *data;
struct SCCudaHlCudaProfile_ *next;
} SCCudaHlCudaProfile;
void SCCudaHlGetYamlConf(void);
void *SCCudaHlGetProfile(char *);
void SCCudaHlCleanProfiles(void);
void SCCudaHlBackupRegisteredProfiles(void);
void SCCudaHlRestoreBackupRegisteredProfiles(void);
int SCCudaHlGetCudaContext(CUcontext *, char *, int);
int SCCudaHlGetCudaModule(CUmodule *, const char *, int);
int SCCudaHlGetCudaModuleFromFile(CUmodule *, const char *, int);
int SCCudaHlGetCudaDevicePtr(CUdeviceptr *, const char *, size_t, void *, int, int);
int SCCudaHlFreeCudaDevicePtr(const char *, int, int);
int SCCudaHlRegisterDispatcherFunc(void *(*SCCudaHlDispFunc)(void *), int);
SCCudaHlModuleData *SCCudaHlGetModuleData(uint8_t);
const char *SCCudaHlGetModuleName(int);
int SCCudaHlGetModuleHandle(const char *);
int SCCudaHlRegisterModule(const char *);
int SCCudaHlDeRegisterModule(const char *);
void SCCudaHlDeRegisterAllRegisteredModules(void);
int SCCudaHlPushCudaContextFromModule(const char *);
int SCCudaHlTestEnvCudaContextInit(void);
int SCCudaHlTestEnvCudaContextDeInit(void);
void SCCudaHlProcessPacketWithDispatcher(Packet *, DetectEngineThreadCtx *,
void *);
void SCCudaHlProcessUriWithDispatcher(uint8_t *, uint16_t, DetectEngineThreadCtx *,
void *);
#endif /* __UTIL_CUDA_HANDLERS__ */
#endif /* __SC_CUDA_SUPPORT__ */

File diff suppressed because it is too large Load Diff

@ -1,144 +0,0 @@
/* Copyright (C) 2007-2010 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* \file
*
* \author Victor Julien <victor@inliniac.net>
* \author Anoop Saldanha <anoopsaldanha@gmail.com>
* \author Martin Beyer <martin.beyer@marasystems.de>
*/
#ifndef __UTIL_MPM_B2G_CUDA_H__
#define __UTIL_MPM_B2G_CUDA_H__
#ifdef __SC_CUDA_SUPPORT__
#include <cuda.h>
#include "decode.h"
#include "util-mpm.h"
#include "util-bloomfilter.h"
#define B2G_CUDA_HASHSHIFT 4
#define B2G_CUDA_TYPE uint32_t
#define B2G_CUDA_WORD_SIZE 32
#define B2G_CUDA_Q 2
#define B2G_CUDA_HASH16(a, b) (((a) << B2G_CUDA_HASHSHIFT) | (b))
#define B2G_CUDA_SEARCHFUNC B2gCudaSearchBNDMq
#define B2G_CUDA_SEARCHFUNC_NAME "B2gCudaSearchBNDMq"
typedef struct B2gCudaPattern_ {
uint8_t flags;
/** \todo we're limited to 32/64 byte lengths, uint8_t would be fine here */
uint16_t len;
/* case sensitive */
uint8_t *cs;
/* case INsensitive */
uint8_t *ci;
struct B2gCudaPattern_ *next;
uint32_t id;
uint8_t *original_pat;
} B2gCudaPattern;
typedef struct B2gCudaHashItem_ {
uint16_t idx;
uint8_t flags;
struct B2gCudaHashItem_ *nxt;
} B2gCudaHashItem;
typedef struct B2gCudaCtx_ {
/* unique handle given by the cuda-handlers API, which indicates the module
* in the engine that is holding this B2g_Cuda_Ctx */
int module_handle;
/* cuda device pointer to B2gCudaCtx->B2G */
CUdeviceptr cuda_B2G;
B2G_CUDA_TYPE *B2G;
B2G_CUDA_TYPE m;
BloomFilter **bloom;
/* array containing the minimal length of the patters in a hash bucket.
* Used for the BloomFilter. */
uint8_t *pminlen;
/* pattern arrays */
B2gCudaPattern **parray;
uint16_t pat_1_cnt;
#ifdef B2G_CUDA_SEARCH2
uint16_t pat_2_cnt;
#endif
uint16_t pat_x_cnt;
uint32_t hash_size;
B2gCudaHashItem **hash;
B2gCudaHashItem hash1[256];
#ifdef B2G_CUDA_SEARCH2
B2gCudaHashItem **hash2;
#endif
/* hash used during ctx initialization */
B2gCudaPattern **init_hash;
uint8_t s0;
/* we store our own multi byte search func ptr here for B2gCudaSearch1 */
uint32_t (*Search)(struct MpmCtx_ *, struct MpmThreadCtx_ *,
PatternMatcherQueue *, uint8_t *, uint16_t);
/* we store our own multi byte search func ptr here for B2gCudaSearch2 */
uint32_t (*MBSearch2)(struct MpmCtx_ *, struct MpmThreadCtx_ *,
PatternMatcherQueue *, uint8_t *, uint16_t);
uint32_t (*MBSearch)(struct MpmCtx_ *, struct MpmThreadCtx_ *,
PatternMatcherQueue *, uint8_t *, uint16_t);
} B2gCudaCtx;
typedef struct B2gCudaThreadCtx_ {
#ifdef B2G_CUDA_COUNTERS
uint32_t stat_pminlen_calls;
uint32_t stat_pminlen_total;
uint32_t stat_bloom_calls;
uint32_t stat_bloom_hits;
uint32_t stat_calls;
uint32_t stat_m_total;
uint32_t stat_d0;
uint32_t stat_d0_hashloop;
uint32_t stat_loop_match;
uint32_t stat_loop_no_match;
uint32_t stat_num_shift;
uint32_t stat_total_shift;
#endif /* B2G_CUDA_COUNTERS */
} B2gCudaThreadCtx;
void MpmB2gCudaRegister(void);
void TmModuleCudaMpmB2gRegister(void);
int B2gCudaStartDispatcherThreadRC(const char *);
void B2gCudaKillDispatcherThreadRC(void);
int B2gCudaResultsPostProcessing(Packet *, MpmCtx *, MpmThreadCtx *,
PatternMatcherQueue *);
uint32_t B2gCudaSearch1(MpmCtx *, MpmThreadCtx *, PatternMatcherQueue *,
uint8_t *, uint16_t);
#ifdef B2G_CUDA_SEARCH2
uint32_t B2gCudaSearch2(MpmCtx *, MpmThreadCtx *, PatternMatcherQueue *,
uint8_t *, uint16_t);
#endif
#endif /* __SC_CUDA_SUPPORT__ */
#endif /* __UTIL_MPM_B2G_CUDA_H__ */

@ -30,7 +30,6 @@
/* include pattern matchers */
#include "util-mpm-wumanber.h"
#include "util-mpm-b2g.h"
#include "util-mpm-b2g-cuda.h"
#include "util-mpm-b3g.h"
#include "util-mpm-b2gc.h"
#include "util-mpm-b2gm.h"
@ -40,7 +39,6 @@
#include "util-hashlist.h"
#include "detect-engine.h"
#include "util-cuda-handlers.h"
#include "util-cuda.h"
#include "util-misc.h"
#include "conf.h"
@ -445,9 +443,6 @@ void MpmTableSetup(void) {
MpmWuManberRegister();
MpmB2gRegister();
#ifdef __SC_CUDA_SUPPORT__
MpmB2gCudaRegister();
#endif
MpmB3gRegister();
MpmB2gcRegister();
MpmB2gmRegister();
@ -512,765 +507,9 @@ uint32_t MpmGetBloomSize(const char *conf_val)
SCReturnInt(bloom_value);
}
#ifdef __SC_CUDA_SUPPORT__
/**
* \brief Parse the "mpm" profile under the cuda subsection of our conf file.
*
* \retval profile Pointer to a struct containing the parsed data.
*/
MpmCudaConf *MpmCudaConfParse(void)
{
ConfNode *cuda_node = NULL;
ConfNode *seq_node = NULL;
MpmCudaConf *profile = NULL;
const char *packet_buffer_limit = NULL;
const char *packet_size_limit = NULL;
const char *packet_buffers = NULL;
const char *batching_timeout = NULL;
const char *page_locked = NULL;
const char *device_id = NULL;
const char *cuda_streams = NULL;
if ((profile = SCMalloc(sizeof(MpmCudaConf))) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
memset(profile, 0, sizeof(MpmCudaConf));
profile->packet_buffer_limit = MPM_PACKET_BUFFER_LIMIT;
profile->packet_size_limit = MPM_PACKET_SIZE_LIMIT;
profile->packet_buffers = MPM_PACKET_BUFFERS;
profile->batching_timeout = MPM_BATCHING_TIMEOUT;
profile->page_locked = MPM_PAGE_LOCKED;
profile->device_id = SC_CUDA_DEFAULT_DEVICE;
profile->cuda_streams = MPM_CUDA_STREAMS;
cuda_node = ConfGetNode("cuda");
if (cuda_node == NULL) {
SCLogInfo("No conf found for \"cuda\" in yaml file. Use default conf");
goto end;
}
TAILQ_FOREACH(seq_node, &cuda_node->head, next) {
if (strcasecmp(seq_node->val, "mpm") == 0) {
packet_buffer_limit = ConfNodeLookupChildValue
(seq_node->head.tqh_first, "packet-buffer-limit");
packet_size_limit = ConfNodeLookupChildValue
(seq_node->head.tqh_first, "packet-size-limit");
packet_buffers = ConfNodeLookupChildValue
(seq_node->head.tqh_first, "packet-buffers");
batching_timeout = ConfNodeLookupChildValue
(seq_node->head.tqh_first, "batching-timeout");
page_locked = ConfNodeLookupChildValue
(seq_node->head.tqh_first, "page-locked");
device_id = ConfNodeLookupChildValue
(seq_node->head.tqh_first, "device-id");
cuda_streams = ConfNodeLookupChildValue
(seq_node->head.tqh_first, "cuda-streams");
/* packet_buffer_size */
if (packet_buffer_limit == NULL || strcasecmp(packet_buffer_limit, "") == 0) {
SCLogError(SC_ERR_INVALID_YAML_CONF_ENTRY, "Invalid entry for "
"cuda.mpm.packet_buffer_limit. Either NULL or empty");
} else {
profile->packet_buffer_limit = atoi(packet_buffer_limit);
if (profile->packet_buffer_limit <= 0) {
SCLogError(SC_ERR_INVALID_YAML_CONF_ENTRY, "Invalid entry for "
"cuda.mpm.packet_buffer_limit - %s", packet_buffer_limit);
profile->packet_buffer_limit = MPM_PACKET_BUFFER_LIMIT;
}
}
/* packet_size_limit */
if (packet_size_limit == NULL || strcasecmp(packet_size_limit, "") == 0) {
SCLogError(SC_ERR_INVALID_YAML_CONF_ENTRY, "Invalid entry for "
"cuda.mpm.packet_size_limit. Either NULL or empty");
} else {
if (ParseSizeStringU16(packet_size_limit, &profile->packet_size_limit) < 0) {
SCLogError(SC_ERR_INVALID_YAML_CONF_ENTRY, "Invalid entry for "
"cuda.mpm.packet_size_limit - %s", packet_size_limit);
exit(EXIT_FAILURE);
}
if (profile->packet_size_limit <= 0) {
SCLogError(SC_ERR_INVALID_YAML_CONF_ENTRY, "Invalid entry for "
"cuda.mpm.packet_size_limit - %s", packet_size_limit);
profile->packet_size_limit = MPM_PACKET_SIZE_LIMIT;
}
}
/* packet_buffers */
if (packet_buffers == NULL || strcasecmp(packet_buffers, "") == 0) {
SCLogError(SC_ERR_INVALID_YAML_CONF_ENTRY, "Invalid entry for "
"cuda.mpm.packet_buffers. Either NULL or empty");
} else {
profile->packet_buffers = atoi(packet_buffers);
if (profile->packet_buffers <= 0) {
SCLogError(SC_ERR_INVALID_YAML_CONF_ENTRY, "Invalid entry for "
"cuda.mpm.packet_buffers - %s", packet_buffers);
profile->packet_buffers = MPM_PACKET_BUFFERS;
}
}
/* batching_timeout */
if (batching_timeout == NULL || strcasecmp(batching_timeout, "") == 0) {
SCLogError(SC_ERR_INVALID_YAML_CONF_ENTRY, "Invalid entry for "
"cuda.mpm.batching_timeout. Either NULL or empty");
} else {
profile->batching_timeout = atof(batching_timeout);
if (profile->batching_timeout < 0.000001) {
SCLogError(SC_ERR_INVALID_YAML_CONF_ENTRY, "Invalid entry for "
"cuda.mpm.batching_timeout - %s", batching_timeout);
profile->batching_timeout = MPM_BATCHING_TIMEOUT;
}
}
/* page_locked */
if (page_locked == NULL || strcasecmp(page_locked, "") == 0) {
SCLogError(SC_ERR_INVALID_YAML_CONF_ENTRY, "Invalid entry for "
"cuda.mpm.page_locked. Either NULL or empty");
} else {
if (strcasecmp(page_locked, "enabled") == 0) {
profile->page_locked = MPM_PAGE_LOCKED;
} else if (strcasecmp(page_locked, "disabled") == 0) {
profile->page_locked = !MPM_PAGE_LOCKED;
} else {
SCLogError(SC_ERR_INVALID_YAML_CONF_ENTRY, "Invalid entry for "
"cuda.mpm.page_locked - %s", page_locked);
}
}
/* device_id */
if (device_id == NULL || strcasecmp(device_id, "") == 0) {
SCLogError(SC_ERR_INVALID_YAML_CONF_ENTRY, "Invalid entry for "
"cuda.mpm.device_id Either NULL or empty");
profile->device_id = SC_CUDA_DEFAULT_DEVICE;
continue;
} else {
profile->device_id = atoi(device_id);
if (profile->device_id < 0) {
SCLogError(SC_ERR_INVALID_YAML_CONF_ENTRY, "Invalid entry for "
"cuda.mpm.device_id - %s", device_id);
profile->device_id = SC_CUDA_DEFAULT_DEVICE;
continue;
}
}
/* cuda_streams */
if (cuda_streams == NULL || strcasecmp(cuda_streams, "") == 0) {
SCLogError(SC_ERR_INVALID_YAML_CONF_ENTRY, "Invalid entry for "
"cuda.mpm.cuda_streams Either NULL or empty");
profile->cuda_streams = MPM_CUDA_STREAMS;
continue;
} else {
profile->cuda_streams = atoi(cuda_streams);
if (profile->cuda_streams < 1) {
SCLogError(SC_ERR_INVALID_YAML_CONF_ENTRY, "Invalid entry for "
"cuda.mpm.cuda_streams - %s", cuda_streams);
profile->cuda_streams = MPM_CUDA_STREAMS;
continue;
}
}
} /* if (strcasecmp(seq_node->val, "mpm") == 0) */
} /* TAILQ_FOREACH(seq_node, &cuda_node->head, next) */
end:
SCLogDebug("Configuration for \"cuda.mpm\"\n"
"packet_buffer_size: %u\n"
"packet_size_limit: %d\n"
"packet_buffers: %d\n"
"batching_timeout: %d\n"
"page_locked: %d\n"
"device_id: %d\n",
profile->packet_buffer_limit, profile->packet_size_limit,
profile->packet_buffers, profile->batching_timeout,
profile->page_locked, profile->device_id);
return profile;
}
/**
* \brief Cleanup the parsed "mpm" profile cuda conf.
*/
void MpmCudaConfCleanup(MpmCudaConf *conf)
{
if (conf != NULL)
SCFree(conf);
return;
}
#endif /* __SC_CUDA_SUPPORT */
/************************************Unittests*********************************/
#ifdef UNITTESTS
#ifdef __SC_CUDA_SUPPORT__
static int MpmInitYamlConf(char *conf)
{
ConfCreateContextBackup();
ConfInit();
return ConfYamlLoadString(conf, strlen(conf));
}
static void MpmDeInitYamlConf(void)
{
ConfDeInit();
ConfRestoreContextBackup();
return;
}
static int MpmTest01(void)
{
char *conf =
"%YAML 1.1\n"
"---\n"
"cuda:\n"
" - mpm:\n"
" packet_buffer_limit: 4000\n"
" packet_size_limit: 1500\n"
" packet_buffers: 10\n"
" batching_timeout: 1\n"
" page_locked: enabled\n"
" device_id: 0\n"
" cuda_streams: 2\n";
DetectEngineCtx *de_ctx = NULL;
int result = 0;
if (MpmInitYamlConf(conf) == -1)
return 0;
de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL)
goto end;
SCCudaHlBackupRegisteredProfiles();
SCCudaHlGetYamlConf();
MpmCudaConf *profile = SCCudaHlGetProfile("mpm");
if (profile == NULL) {
printf("Error retrieving mpm profile\n");
goto end;
}
result = (profile->packet_buffer_limit == 4000);
result &= (profile->packet_size_limit == 1500);
result &= (profile->packet_buffers == 10);
result &= (profile->batching_timeout == 1);
result &= (profile->page_locked == 1);
result &= (profile->device_id == 0);
result &= (profile->cuda_streams == 2);
end:
SCCudaHlCleanProfiles();
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
MpmDeInitYamlConf();
SCCudaHlRestoreBackupRegisteredProfiles();
return result;
}
static int MpmTest02(void)
{
char *conf =
"%YAML 1.1\n"
"---\n"
"cuda:\n"
" - mpm:\n"
" packet_buffer_limit: 4001\n"
" packet_size_limit: 1500\n"
" packet_buffers: 12\n"
" batching_timeout: 10\n"
" page_locked: disabled\n"
" device_id: 5\n"
" cuda_streams: 4\n";
DetectEngineCtx *de_ctx = NULL;
int result = 0;
if (MpmInitYamlConf(conf) == -1)
return 0;
de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL)
goto end;
SCCudaHlBackupRegisteredProfiles();
SCCudaHlGetYamlConf();
MpmCudaConf *profile = SCCudaHlGetProfile("mpm");
if (profile == NULL) {
printf("Error retrieving mpm profile\n");
goto end;
}
result = (profile->packet_buffer_limit == 4001);
result &= (profile->packet_size_limit == 1500);
result &= (profile->packet_buffers == 12);
result &= (profile->batching_timeout == 10);
result &= (profile->page_locked == 0);
result &= (profile->device_id == 5);
result &= (profile->cuda_streams == 4);
end:
SCCudaHlCleanProfiles();
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
MpmDeInitYamlConf();
SCCudaHlRestoreBackupRegisteredProfiles();
return result;
}
static int MpmTest03(void)
{
char *conf =
"%YAML 1.1\n"
"---\n"
"cuda:\n"
" - mpm:\n"
" packet_buffer_limit: 0\n"
" packet_size_limit: 0\n"
" packet_buffers: 0\n"
" batching_timeout: 0\n"
" page_locked: enbled\n"
" device_id: -1\n"
" cuda_streams: -1\n";
DetectEngineCtx *de_ctx = NULL;
int result = 0;
if (MpmInitYamlConf(conf) == -1)
return 0;
de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL)
goto end;
SCCudaHlBackupRegisteredProfiles();
SCCudaHlGetYamlConf();
MpmCudaConf *profile = SCCudaHlGetProfile("mpm");
if (profile == NULL) {
printf("Error retrieving mpm profile\n");
goto end;
}
result = (profile->packet_buffer_limit == MPM_PACKET_BUFFER_LIMIT);
result &= (profile->packet_size_limit == MPM_PACKET_SIZE_LIMIT);
result &= (profile->packet_buffers == MPM_PACKET_BUFFERS);
result &= (profile->batching_timeout == MPM_BATCHING_TIMEOUT);
result &= (profile->page_locked == MPM_PAGE_LOCKED);
result &= (profile->device_id == SC_CUDA_DEFAULT_DEVICE);
result &= (profile->cuda_streams == MPM_CUDA_STREAMS);
end:
SCCudaHlCleanProfiles();
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
MpmDeInitYamlConf();
SCCudaHlRestoreBackupRegisteredProfiles();
return result;
}
static int MpmTest04(void)
{
char *conf =
"%YAML 1.1\n"
"---\n"
"cuda:\n"
" - mpm:\n"
" packet_buffer_limit: -1\n"
" packet_size_limit: -1\n"
" packet_buffers: -1\n"
" batching_timeout: -1\n"
" page_locked: enbled\n"
" device_id: -1\n"
" cuda_streams: -1\n";
DetectEngineCtx *de_ctx = NULL;
int result = 0;
if (MpmInitYamlConf(conf) == -1)
return 0;
de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL)
goto end;
SCCudaHlBackupRegisteredProfiles();
SCCudaHlGetYamlConf();
MpmCudaConf *profile = SCCudaHlGetProfile("mpm");
if (profile == NULL) {
printf("Error retrieving mpm profile\n");
goto end;
}
result = (profile->packet_buffer_limit == MPM_PACKET_BUFFER_LIMIT);
result &= (profile->packet_size_limit == MPM_PACKET_SIZE_LIMIT);
result &= (profile->packet_buffers == MPM_PACKET_BUFFERS);
result &= (profile->batching_timeout == MPM_BATCHING_TIMEOUT);
result &= (profile->page_locked == MPM_PAGE_LOCKED);
result &= (profile->device_id == SC_CUDA_DEFAULT_DEVICE);
result &= (profile->cuda_streams == MPM_CUDA_STREAMS);
end:
SCCudaHlCleanProfiles();
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
MpmDeInitYamlConf();
SCCudaHlRestoreBackupRegisteredProfiles();
return result;
}
static int MpmTest05(void)
{
char *conf =
"%YAML 1.1\n"
"---\n"
"cuda:\n"
" - mpm:\n"
" packet_buffer_limit:\n"
" packet_size_limit:\n"
" packet_buffers:\n"
" batching_timeout: 2\n"
" page_locked: enabled\n"
" device_id: 1\n"
" cuda_streams: 0\n";
DetectEngineCtx *de_ctx = NULL;
int result = 0;
if (MpmInitYamlConf(conf) == -1)
return 0;
de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL)
goto end;
SCCudaHlBackupRegisteredProfiles();
SCCudaHlGetYamlConf();
MpmCudaConf *profile = SCCudaHlGetProfile("mpm");
if (profile == NULL) {
printf("Error retrieving mpm profile\n");
goto end;
}
result = (profile->packet_buffer_limit == MPM_PACKET_BUFFER_LIMIT);
result &= (profile->packet_size_limit == MPM_PACKET_SIZE_LIMIT);
result &= (profile->packet_buffers == MPM_PACKET_BUFFERS);
result &= (profile->batching_timeout == 2);
result &= (profile->page_locked == 1);
result &= (profile->device_id == 1);
result &= (profile->cuda_streams == 0);
end:
SCCudaHlCleanProfiles();
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
MpmDeInitYamlConf();
SCCudaHlRestoreBackupRegisteredProfiles();
return result;
}
static int MpmTest06(void)
{
char *conf =
"%YAML 1.1\n"
"---\n"
"cuda:\n"
" - mpm:\n"
" packet_buffer_limit: \n"
" packet_size_limit: \n"
" packet_buffers: \n"
" batching_timeout: \n"
" page_locked: \n"
" device_id: \n"
" cuda_streams: \n";
DetectEngineCtx *de_ctx = NULL;
int result = 0;
if (MpmInitYamlConf(conf) == -1)
return 0;
de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL)
goto end;
SCCudaHlBackupRegisteredProfiles();
SCCudaHlGetYamlConf();
MpmCudaConf *profile = SCCudaHlGetProfile("mpm");
if (profile == NULL) {
printf("Error retrieving mpm profile\n");
goto end;
}
result = (profile->packet_buffer_limit == MPM_PACKET_BUFFER_LIMIT);
result &= (profile->packet_size_limit == MPM_PACKET_SIZE_LIMIT);
result &= (profile->packet_buffers == MPM_PACKET_BUFFERS);
result &= (profile->batching_timeout == MPM_BATCHING_TIMEOUT);
result &= (profile->page_locked == MPM_PAGE_LOCKED);
result &= (profile->device_id == SC_CUDA_DEFAULT_DEVICE);
result &= (profile->cuda_streams == MPM_CUDA_STREAMS);
end:
SCCudaHlCleanProfiles();
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
MpmDeInitYamlConf();
SCCudaHlRestoreBackupRegisteredProfiles();
return result;
}
static int MpmTest07(void)
{
char *conf =
"%YAML 1.1\n"
"---\n"
"cuda:\n"
" - mpm:\n"
" packet_buffer_limit:\n"
" packet_size_limit:\n"
" packet_buffers:\n"
" batching_timeout:\n"
" page_locked:\n"
" device_id:\n"
" cuda_streams:\n";
DetectEngineCtx *de_ctx = NULL;
int result = 0;
if (MpmInitYamlConf(conf) == -1)
return 0;
de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL)
goto end;
SCCudaHlBackupRegisteredProfiles();
SCCudaHlGetYamlConf();
MpmCudaConf *profile = SCCudaHlGetProfile("mpm");
if (profile == NULL) {
printf("Error retrieving mpm profile\n");
goto end;
}
result = (profile->packet_buffer_limit == MPM_PACKET_BUFFER_LIMIT);
result &= (profile->packet_size_limit == MPM_PACKET_SIZE_LIMIT);
result &= (profile->packet_buffers == MPM_PACKET_BUFFERS);
result &= (profile->batching_timeout == MPM_BATCHING_TIMEOUT);
result &= (profile->page_locked == MPM_PAGE_LOCKED);
result &= (profile->device_id == SC_CUDA_DEFAULT_DEVICE);
result &= (profile->cuda_streams == MPM_CUDA_STREAMS);
end:
SCCudaHlCleanProfiles();
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
MpmDeInitYamlConf();
SCCudaHlRestoreBackupRegisteredProfiles();
return result;
}
static int MpmTest08(void)
{
char *conf =
"%YAML 1.1\n"
"---\n"
"cuda:\n"
" - mpm:\n"
" packet_size_limit: 2000\n"
" page_locked: disabled\n"
" device_id: 4\n"
" cuda_streams: 8\n";
DetectEngineCtx *de_ctx = NULL;
int result = 0;
if (MpmInitYamlConf(conf) == -1)
return 0;
de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL)
goto end;
SCCudaHlBackupRegisteredProfiles();
SCCudaHlGetYamlConf();
MpmCudaConf *profile = SCCudaHlGetProfile("mpm");
if (profile == NULL) {
printf("Error retrieving mpm profile\n");
goto end;
}
result = (profile->packet_buffer_limit == MPM_PACKET_BUFFER_LIMIT);
result &= (profile->packet_size_limit == 2000);
result &= (profile->packet_buffers == MPM_PACKET_BUFFERS);
result &= (profile->batching_timeout == MPM_BATCHING_TIMEOUT);
result &= (profile->page_locked == !MPM_PAGE_LOCKED);
result &= (profile->device_id == 4);
result &= (profile->cuda_streams == 8);
end:
SCCudaHlCleanProfiles();
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
MpmDeInitYamlConf();
SCCudaHlRestoreBackupRegisteredProfiles();
return result;
}
static int MpmTest09(void)
{
char *conf =
"%YAML 1.1\n"
"---\n"
"cuda:\n"
" - mpm:\n";
DetectEngineCtx *de_ctx = NULL;
int result = 0;
if (MpmInitYamlConf(conf) == -1)
return 0;
de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL)
goto end;
SCCudaHlBackupRegisteredProfiles();
SCCudaHlGetYamlConf();
MpmCudaConf *profile = SCCudaHlGetProfile("mpm");
if (profile == NULL) {
printf("Error retrieving mpm profile\n");
goto end;
}
result = (profile->packet_buffer_limit == MPM_PACKET_BUFFER_LIMIT);
result &= (profile->packet_size_limit == MPM_PACKET_SIZE_LIMIT);
result &= (profile->packet_buffers == MPM_PACKET_BUFFERS);
result &= (profile->batching_timeout == MPM_BATCHING_TIMEOUT);
result &= (profile->page_locked == MPM_PAGE_LOCKED);
result &= (profile->device_id == SC_CUDA_DEFAULT_DEVICE);
result &= (profile->cuda_streams == MPM_CUDA_STREAMS);
end:
SCCudaHlCleanProfiles();
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
MpmDeInitYamlConf();
SCCudaHlRestoreBackupRegisteredProfiles();
return result;
}
static int MpmTest10(void)
{
char *conf =
"%YAML 1.1\n"
"---\n"
"cuda:\n";
DetectEngineCtx *de_ctx = NULL;
int result = 0;
if (MpmInitYamlConf(conf) == -1)
return 0;
de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL)
goto end;
SCCudaHlBackupRegisteredProfiles();
SCCudaHlGetYamlConf();
MpmCudaConf *profile = SCCudaHlGetProfile("mpm");
if (profile == NULL) {
printf("Error retrieving mpm profile\n");
goto end;
}
result = (profile->packet_buffer_limit == MPM_PACKET_BUFFER_LIMIT);
result &= (profile->packet_size_limit == MPM_PACKET_SIZE_LIMIT);
result &= (profile->packet_buffers == MPM_PACKET_BUFFERS);
result &= (profile->batching_timeout == MPM_BATCHING_TIMEOUT);
result &= (profile->page_locked == MPM_PAGE_LOCKED);
result &= (profile->device_id == SC_CUDA_DEFAULT_DEVICE);
result &= (profile->cuda_streams == MPM_CUDA_STREAMS);
end:
SCCudaHlCleanProfiles();
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
MpmDeInitYamlConf();
SCCudaHlRestoreBackupRegisteredProfiles();
return result;
}
static int MpmTest11(void)
{
char *conf =
"%YAML 1.1\n"
"---\n";
DetectEngineCtx *de_ctx = NULL;
int result = 0;
if (MpmInitYamlConf(conf) == -1)
return 0;
de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL)
goto end;
SCCudaHlBackupRegisteredProfiles();
SCCudaHlGetYamlConf();
MpmCudaConf *profile = SCCudaHlGetProfile("mpm");
if (profile == NULL) {
printf("Error retrieving mpm profile\n");
goto end;
}
result = (profile->packet_buffer_limit == MPM_PACKET_BUFFER_LIMIT);
result &= (profile->packet_size_limit == MPM_PACKET_SIZE_LIMIT);
result &= (profile->packet_buffers == MPM_PACKET_BUFFERS);
result &= (profile->batching_timeout == MPM_BATCHING_TIMEOUT);
result &= (profile->page_locked == MPM_PAGE_LOCKED);
result &= (profile->device_id == SC_CUDA_DEFAULT_DEVICE);
result &= (profile->cuda_streams == MPM_CUDA_STREAMS);
end:
SCCudaHlCleanProfiles();
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
MpmDeInitYamlConf();
SCCudaHlRestoreBackupRegisteredProfiles();
return result;
}
#endif /* __SC_CUDA_SUPPORT__ */
#endif /* UNITTESTS */
void MpmRegisterTests(void) {
@ -1288,19 +527,5 @@ void MpmRegisterTests(void) {
}
}
#ifdef __SC_CUDA_SUPPORT__
UtRegisterTest("MpmTest01", MpmTest01, 1);
UtRegisterTest("MpmTest02", MpmTest02, 1);
UtRegisterTest("MpmTest03", MpmTest03, 1);
UtRegisterTest("MpmTest04", MpmTest04, 1);
UtRegisterTest("MpmTest05", MpmTest05, 1);
UtRegisterTest("MpmTest06", MpmTest06, 1);
UtRegisterTest("MpmTest07", MpmTest07, 1);
UtRegisterTest("MpmTest08", MpmTest08, 1);
UtRegisterTest("MpmTest09", MpmTest09, 1);
UtRegisterTest("MpmTest10", MpmTest10, 1);
UtRegisterTest("MpmTest11", MpmTest11, 1);
#endif /* __SC_CUDA_SUPPORT__ */
#endif
}

@ -51,13 +51,6 @@
#define BLOOMSIZE_HIGH 2048 /**< High bloomfilter size for the multi
pattern matcher algorithms */
#define MPM_PACKET_BUFFER_LIMIT 2400
#define MPM_PACKET_SIZE_LIMIT 1500
#define MPM_PACKET_BUFFERS 10
#define MPM_BATCHING_TIMEOUT 1
#define MPM_PAGE_LOCKED 1
#define MPM_CUDA_STREAMS 2
enum {
MPM_NOTSET = 0,
@ -65,9 +58,6 @@ enum {
MPM_WUMANBER,
/* bndmq 2 gram */
MPM_B2G,
#ifdef __SC_CUDA_SUPPORT__
MPM_B2G_CUDA,
#endif
/* bndmq 3 gram */
MPM_B3G,
MPM_B2GC,
@ -194,36 +184,12 @@ MpmCtx *MpmFactoryGetMpmCtxForProfile(struct DetectEngineCtx_ *, int32_t, int);
void MpmFactoryDeRegisterAllMpmCtxProfiles(struct DetectEngineCtx_ *);
int32_t MpmFactoryIsMpmCtxAvailable(struct DetectEngineCtx_ *, MpmCtx *);
/* macros decides if cuda is enabled for the platform or not */
#ifdef __SC_CUDA_SUPPORT__
/**
* \brief Cuda configuration for "mpm" profile. We can further extend this
* to have conf for specific mpms. For now its common for all mpms.
*/
typedef struct MpmCudaConf_ {
int32_t packet_buffer_limit;
uint16_t packet_size_limit;
int8_t packet_buffers;
double batching_timeout;
int8_t page_locked;
int8_t device_id;
int8_t cuda_streams;
} MpmCudaConf;
#endif /* __SC_CUDA_SUPPORT__ */
int PmqSetup(PatternMatcherQueue *, uint32_t, uint32_t);
void PmqMerge(PatternMatcherQueue *src, PatternMatcherQueue *dst);
void PmqReset(PatternMatcherQueue *);
void PmqCleanup(PatternMatcherQueue *);
void PmqFree(PatternMatcherQueue *);
#ifdef __SC_CUDA_SUPPORT__
MpmCudaConf *MpmCudaConfParse(void);
void MpmCudaConfCleanup(MpmCudaConf *);
#endif /* __SC_CUDA_SUPPORT */
void MpmTableSetup(void);
void MpmRegisterTests(void);

@ -32,7 +32,6 @@
#include "runmode-af-packet.h"
#include "log-httplog.h"
#include "output.h"
#include "cuda-packet-batcher.h"
#include "detect-engine-mpm.h"
#include "alert-fastlog.h"
@ -163,111 +162,6 @@ int RunModeSetLiveCaptureAuto(DetectEngineCtx *de_ctx,
}
}
#if defined(__SC_CUDA_SUPPORT__)
if (PatternMatchDefaultMatcher() == MPM_B2G_CUDA) {
ThreadVars *tv_decode1 =
TmThreadCreatePacketHandler("Decode",
"pickup-queue", "simple",
"decode-queue1", "simple",
"1slot");
if (tv_decode1 == NULL) {
SCLogError(SC_ERR_RUNMODE, "TmThreadsCreate failed for Decode1");
exit(EXIT_FAILURE);
}
tm_module = TmModuleGetByName(decode_mod_name);
if (tm_module == NULL) {
SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName %s failed", decode_mod_name);
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmThreadSetCPU(tv_decode1, DECODE_CPU_SET);
if (TmThreadSpawn(tv_decode1) != TM_ECODE_OK) {
SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
exit(EXIT_FAILURE);
}
ThreadVars *tv_cuda_PB =
TmThreadCreate("CUDA_PB",
"decode-queue1", "simple",
"cuda-pb-queue1", "simple",
"custom", SCCudaPBTmThreadsSlot1, 0);
if (tv_cuda_PB == NULL) {
SCLogError(SC_ERR_RUNMODE, "TmThreadsCreate failed for CUDA_PB");
exit(EXIT_FAILURE);
}
tv_cuda_PB->type = TVT_PPT;
tm_module = TmModuleGetByName("CudaPacketBatcher");
if (tm_module == NULL) {
SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName CudaPacketBatcher failed");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_cuda_PB, tm_module, (void *)de_ctx);
TmThreadSetCPU(tv_cuda_PB, DETECT_CPU_SET);
if (TmThreadSpawn(tv_cuda_PB) != TM_ECODE_OK) {
SCLogError(SC_ERR_THREAD_SPAWN, "TmThreadSpawn failed");
exit(EXIT_FAILURE);
}
ThreadVars *tv_stream1 =
TmThreadCreatePacketHandler("Stream1",
"cuda-pb-queue1", "simple",
"stream-queue1", "simple",
"1slot");
if (tv_stream1 == NULL) {
SCLogError(SC_ERR_RUNMODE, "TmThreadsCreate failed for Stream1");
exit(EXIT_FAILURE);
}
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName StreamTcp failed");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_stream1, tm_module, NULL);
TmThreadSetCPU(tv_stream1, STREAM_CPU_SET);
if (TmThreadSpawn(tv_stream1) != TM_ECODE_OK) {
SCLogError(SC_ERR_THREAD_SPAWN, "TmThreadSpawn failed");
exit(EXIT_FAILURE);
}
} else {
ThreadVars *tv_decode1 =
TmThreadCreatePacketHandler("Decode & Stream",
"pickup-queue", "simple",
"stream-queue1", "simple",
"varslot");
if (tv_decode1 == NULL) {
SCLogError(SC_ERR_RUNMODE, "TmThreadsCreate failed for Decode1");
exit(EXIT_FAILURE);
}
tm_module = TmModuleGetByName(decode_mod_name);
if (tm_module == NULL) {
SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName %s failed", decode_mod_name);
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName StreamTcp failed");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmThreadSetCPU(tv_decode1, DECODE_CPU_SET);
if (TmThreadSpawn(tv_decode1) != TM_ECODE_OK) {
SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
exit(EXIT_FAILURE);
}
}
#else
ThreadVars *tv_decode1 =
TmThreadCreatePacketHandler("Decode & Stream",
"pickup-queue", "simple",
@ -297,7 +191,6 @@ int RunModeSetLiveCaptureAuto(DetectEngineCtx *de_ctx,
SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
exit(EXIT_FAILURE);
}
#endif
/* always create at least one thread */
int thread_max = TmThreadGetNbThreads(DETECT_CPU_SET);

Loading…
Cancel
Save