diff --git a/src/cuda-packet-batcher.c b/src/cuda-packet-batcher.c index 9906c9b326..aa50a76f88 100644 --- a/src/cuda-packet-batcher.c +++ b/src/cuda-packet-batcher.c @@ -79,7 +79,7 @@ static int run_batcher = 1; * on the traffic * \todo make this user configurable, as well allow dynamic update of this * variable based on the traffic seen */ -static uint32_t buffer_packet_threshhold = 1280; +static uint32_t buffer_packet_threshhold = 2400; /* flag used by the SIG_ALRM handler to indicate that the batcher TM should queue * the buffer to be processed by the Cuda Mpm B2g Batcher Thread for further @@ -546,13 +546,27 @@ TmEcode SCCudaPBBatchPackets(ThreadVars *tv, Packet *p, void *data, PacketQueue /* the sgh to which the incoming packet belongs */ SigGroupHead *sgh = NULL; - /* get the signature group head to which this packet belongs. If it belongs - * to no sgh, we don't need to buffer this packet. - * \todo Get rid of this, once we get the sgh from the flow */ - sgh = SCCudaPBGetSgh(tctx->de_ctx, p); + if (p->flow != NULL) { + /* Get the stored sgh from the flow (if any). Make sure we're not using + * the sgh for icmp error packets part of the same stream. */ + if (p->proto == p->flow->proto) { /* filter out icmp */ + if (p->flowflags & FLOW_PKT_TOSERVER && p->flow->flags & FLOW_SGH_TOSERVER) { + sgh = p->flow->sgh_toserver; + } else if (p->flowflags & FLOW_PKT_TOCLIENT && p->flow->flags & FLOW_SGH_TOCLIENT) { + sgh = p->flow->sgh_toclient; + } + } + } + if (sgh == NULL) { - SCLogDebug("No SigGroupHead match for this packet"); - return TM_ECODE_OK; + /* get the signature group head to which this packet belongs. If it belongs + * to no sgh, we don't need to buffer this packet. + * \todo Get rid of this, once we get the sgh from the flow */ + sgh = SCCudaPBGetSgh(tctx->de_ctx, p); + if (sgh == NULL) { + SCLogDebug("No SigGroupHead match for this packet"); + return TM_ECODE_OK; + } } /* if the payload is less than the maximum content length in this sgh we @@ -747,7 +761,7 @@ void SCCudaPBSetUpQueuesAndBuffers(void) /* \todo This needs to be changed ASAP. This can't exceed max_pending_packets. * Also we need to make this user configurable and allow dynamic updaes * based on live traffic */ - buffer_packet_threshhold = 1280; + buffer_packet_threshhold = 2400; return; } diff --git a/src/suricata.c b/src/suricata.c index 2b8030c4e8..059ca69ee4 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -355,6 +355,7 @@ int main(int argc, char **argv) #endif int dump_config = 0; int list_unittests = 0; + int list_cuda_cards = 0; int daemon = 0; char *user_name = NULL; char *group_name = NULL; @@ -412,6 +413,7 @@ int main(int argc, char **argv) {"pcap-buffer-size", required_argument, 0, 0}, {"unittest-filter", required_argument, 0, 'U'}, {"list-unittests", 0, &list_unittests, 1}, + {"list-cuda-cards", 0, &list_cuda_cards, 1}, #ifdef OS_WIN32 {"service-install", 0, 0, 0}, {"service-remove", 0, 0, 0}, @@ -482,6 +484,12 @@ int main(int argc, char **argv) #else fprintf(stderr, "ERROR: Unit tests not enabled. Make sure to pass --enable-unittests to configure when building.\n"); exit(EXIT_FAILURE); +#endif /* UNITTESTS */ + } else if(strcmp((long_opts[option_index]).name, "list-cuda-cards") == 0) { +#ifndef __SC_CUDA_SUPPORT__ + fprintf(stderr, "ERROR: Cuda not enabled. Make sure to pass " + "--enable-cuda to configure when building.\n"); + exit(EXIT_FAILURE); #endif /* UNITTESTS */ } #ifdef OS_WIN32 @@ -690,6 +698,10 @@ int main(int argc, char **argv) #ifdef __SC_CUDA_SUPPORT__ /* Init the CUDA environment */ SCCudaInitCudaEnvironment(); + if (list_cuda_cards) { + SCCudaListCards(); + exit(EXIT_SUCCESS); + } #endif if (!CheckValidDaemonModes(daemon, run_mode)) { diff --git a/src/util-cuda-handlers.c b/src/util-cuda-handlers.c index e6b51eba87..ae477b67ad 100644 --- a/src/util-cuda-handlers.c +++ b/src/util-cuda-handlers.c @@ -65,6 +65,7 @@ #include "tmqh-simple.h" +#include "conf.h" #include "util-error.h" #include "util-debug.h" #include "util-unittest.h" @@ -226,9 +227,23 @@ int SCCudaHlGetCudaContext(CUcontext *p_context, int handle) return 0; } + /* Get default log level and format. */ + char *cuda_device_id_str = NULL; + int cuda_device_id = SC_CUDA_DEFAULT_DEVICE; + if (ConfGet("cuda.device_id", &cuda_device_id_str) == 1) { + cuda_device_id = atoi(cuda_device_id_str); + if (!SCCudaIsCudaDeviceIdValid(cuda_device_id)) { + SCLogError(SC_ERR_CUDA_ERROR, "Invalid device id \"%s\" supplied " + "in the conf file", cuda_device_id_str); + cuda_device_id = SC_CUDA_DEFAULT_DEVICE; + } + } else { + cuda_device_id = SC_CUDA_DEFAULT_DEVICE; + } + /* Get the device list for this CUDA platform and create a new cuda context */ devices = SCCudaGetDeviceList(); - if (SCCudaCtxCreate(p_context, 0, devices->devices[0]->device) == -1) + if (SCCudaCtxCreate(p_context, 0, devices->devices[cuda_device_id]->device) == -1) goto error; data->cuda_context = p_context[0]; diff --git a/src/util-cuda.c b/src/util-cuda.c index bd511a7a68..5210b821cd 100644 --- a/src/util-cuda.c +++ b/src/util-cuda.c @@ -4069,6 +4069,56 @@ int SCCudaInitCudaEnvironment(void) return -1; } +/**********************************Cuda_Utility********************************/ + +/** + * \brief List the cuda cards on the system. + * + */ +void SCCudaListCards(void) +{ + int i = 0; + + if (devices == NULL) { + SCLogWarning(SC_ERR_CUDA_ERROR, "CUDA engine not initalized! Please " + "initialize the cuda environment using " + "SCCudaInitCudaEnvironment()."); + return; + } + + printf("CUDA Cards recognized by the suricata CUDA module - \n"); + printf("|-----------------------------------------------------------------------------|\n"); + printf("| %-10s | %-20s | %-10s | %-10s | %-13s |\n", + "Device Id", " Device Name", " Multi-", "Clock Rate", "Cuda Compute"); + printf("| %-10s | %-20s | %-10s | %-10s | %-13s |\n", + "", "", "Processors", " (MHz)", "Capability"); + printf("|-----------------------------------------------------------------------------|\n"); + for (i = 0; i < devices->count; i++) { + printf("| %-10d | %-20s | %-10d | %-10d | %d.%-11d |\n", + i, + devices->devices[i]->name, + devices->devices[i]->attr_multiprocessor_count, + devices->devices[i]->attr_clock_rate/1000, + devices->devices[i]->major_rev, + devices->devices[i]->minor_rev); + } + printf("|-----------------------------------------------------------------------------|\n"); + + return; +} + +int SCCudaIsCudaDeviceIdValid(int cuda_device_id) +{ + if (devices == NULL) { + SCLogWarning(SC_ERR_CUDA_ERROR, "CUDA engine not initalized! Please " + "initialize the cuda environment using " + "SCCudaInitCudaEnvironment()."); + return 0; + } + + return (cuda_device_id < devices->count); +} + /**********************************Unittests***********************************/ int SCCudaTest01(void) diff --git a/src/util-cuda.h b/src/util-cuda.h index 304ec0a25a..8410a009d9 100644 --- a/src/util-cuda.h +++ b/src/util-cuda.h @@ -28,6 +28,7 @@ #include +#define SC_CUDA_DEFAULT_DEVICE 0 #define SC_CUDA_DEVICE_NAME_MAX_LEN 128 typedef struct SCCudaDevice_ { @@ -176,6 +177,9 @@ SCCudaDevices *SCCudaGetDeviceList(void); int SCCudaInitCudaEnvironment(void); +void SCCudaListCards(void); +int SCCudaIsCudaDeviceIdValid(int); + void SCCudaRegisterTests(void); #endif /* __SC_CUDA_SUPPORT__ */ diff --git a/suricata.yaml b/suricata.yaml index 9160381169..4e81ea9eb2 100644 --- a/suricata.yaml +++ b/suricata.yaml @@ -120,6 +120,12 @@ threading: # detect_thread_ratio: 1.5 +# Select the cuda device to use. The device_id identifies the device to be used +# if one has multiple devices on the system. To find out device_id associated +# with the card(s) on the system run "suricata --list_cuda_cards". +cuda: + device_id: 0 + # Select the multi pattern algorithm you want to run for scan/search the # in the engine. The supported algorithms are b2g, b3g and wumanber. #