From 3a0dadc0f3b3527ce657884385100b5f59f5734a Mon Sep 17 00:00:00 2001 From: Anoop Saldanha Date: Tue, 20 Jul 2010 21:38:47 +0530 Subject: [PATCH] Fix seg fault while running cuda tests. Don't set the alarm while running unittests, inside cuda-packet-batcher.c. Will result in a seg while the sig handler for ALRM in invoked --- src/cuda-packet-batcher.c | 30 ++++++++++++++++++++++++++---- src/cuda-packet-batcher.h | 2 ++ src/util-mpm-b2g-cuda.c | 2 ++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/cuda-packet-batcher.c b/src/cuda-packet-batcher.c index aa50a76f88..6ce9cf3b8f 100644 --- a/src/cuda-packet-batcher.c +++ b/src/cuda-packet-batcher.c @@ -86,6 +86,8 @@ static uint32_t buffer_packet_threshhold = 2400; * processing on the GPU */ static int queue_buffer = 0; +static int unittest_mode = 0; + /** * \internal * \brief The SIG_ALRM handler. We will set the "queue_buffer" flag thus @@ -484,8 +486,13 @@ TmEcode SCCudaPBThreadInit(ThreadVars *tv, void *initdata, void **data) /* set the SIG_ALRM handler */ SCCudaPBSetBatcherAlarmTimeHandler(); - /* Set the alarm time limit during which the batcher thread would buffer packets */ - alarm(SC_CUDA_PB_BATCHER_ALARM_TIME); + /* if we are running unittests, don't set the alarm handler. It will only + * cause a seg fault if the tests take too long */ + if (!unittest_mode) { + /* Set the alarm time limit during which the batcher thread would + * buffer packets */ + alarm(SC_CUDA_PB_BATCHER_ALARM_TIME); + } return TM_ECODE_OK; } @@ -514,7 +521,11 @@ TmEcode SCCudaPBBatchPackets(ThreadVars *tv, Packet *p, void *data, PacketQueue "buffer and reseting the alarm"); queue_buffer = 0; SCCudaPBQueueBuffer(data); - alarm(SC_CUDA_PB_BATCHER_ALARM_TIME); + /* if we are running unittests, don't set the alarm handler. It will only + * cause a seg fault if the tests take too long */ + if (!unittest_mode) { + alarm(SC_CUDA_PB_BATCHER_ALARM_TIME); + } } /* this is possible, since we are using a custom slot function that calls this @@ -674,7 +685,11 @@ TmEcode SCCudaPBBatchPackets(ThreadVars *tv, Packet *p, void *data, PacketQueue "time limit. Buffering the packet buffer and reseting the " "alarm.", buffer_packet_threshhold); SCCudaPBQueueBuffer(tctx); - alarm(SC_CUDA_PB_BATCHER_ALARM_TIME); + /* if we are running unittests, don't set the alarm handler. It will only + * cause a seg fault if the tests take too long */ + if (!unittest_mode) { + alarm(SC_CUDA_PB_BATCHER_ALARM_TIME); + } } return TM_ECODE_OK; @@ -842,6 +857,11 @@ void SCCudaPBKillBatchingPackets(void) return; } +void SCCudaPBRunningTests(int status) +{ + unittest_mode = status; +} + /***********************************Unittests**********************************/ #ifdef UNITTESTS @@ -991,6 +1011,7 @@ int SCCudaPBTest01(void) result &= (dq->len == 0); dq = &data_queues[tmq_inq->id]; result &= (dq->len == 10); + SCCudaPBRunningTests(1); SCCudaPBThreadInit(&tv_cuda_PB, de_ctx, (void *)&tctx); SCCudaPBSetBufferPacketThreshhold(sizeof(strings)/sizeof(char *)); @@ -1216,6 +1237,7 @@ int SCCudaPBTest02(void) result &= (dq->len == 0); dq = &data_queues[tmq_inq->id]; result &= (dq->len == 10); + SCCudaPBRunningTests(1); SCCudaPBThreadInit(&tv_cuda_PB, de_ctx, (void *)&tctx); result = 1; diff --git a/src/cuda-packet-batcher.h b/src/cuda-packet-batcher.h index c320ffea23..2c53c4520a 100644 --- a/src/cuda-packet-batcher.h +++ b/src/cuda-packet-batcher.h @@ -137,6 +137,8 @@ void TmModuleCudaPacketBatcherRegister(void); void *SCCudaPBTmThreadsSlot1(void *); +void SCCudaPBRunningTests(int); + #endif /* __SC_CUDA_SUPPORT__ */ #endif /* __CUDA_PACKET_BATCHER_H__ */ diff --git a/src/util-mpm-b2g-cuda.c b/src/util-mpm-b2g-cuda.c index 87b973f070..55c63ae2ba 100644 --- a/src/util-mpm-b2g-cuda.c +++ b/src/util-mpm-b2g-cuda.c @@ -2520,6 +2520,7 @@ static int B2gCudaTest02(void) dq = &data_queues[tmq_inq->id]; result &= (dq->len == 10); + SCCudaPBRunningTests(1); /* init the TM thread */ SCCudaPBThreadInit(&tv, de_ctx, (void *)&pb_tctx); SCCudaPBSetBufferPacketThreshhold(no_of_pkts); @@ -2819,6 +2820,7 @@ static int B2gCudaTest03(void) dq = &data_queues[tmq_inq->id]; result &= (dq->len == 10); + SCCudaPBRunningTests(1); /* init the TM thread */ SCCudaPBThreadInit(&tv, de_ctx, (void *)&pb_tctx); SCCudaPBSetBufferPacketThreshhold(no_of_pkts);