Fixed the Perf API startup issue

remotes/origin/master-1.0.x
Anoop Saldanha 16 years ago committed by Victor Julien
parent 07bb501aca
commit 3a45b2711c

@ -304,6 +304,8 @@ void *AppLayerDetectProtoThread(void *td)
StreamMsgQueueSetMinInitChunkLen(FLOW_PKT_TOSERVER, INSPECT_BYTES); StreamMsgQueueSetMinInitChunkLen(FLOW_PKT_TOSERVER, INSPECT_BYTES);
StreamMsgQueueSetMinInitChunkLen(FLOW_PKT_TOCLIENT, INSPECT_BYTES); StreamMsgQueueSetMinInitChunkLen(FLOW_PKT_TOCLIENT, INSPECT_BYTES);
tv->flags |= THV_INIT_DONE;
/* main loop */ /* main loop */
while(run) { while(run) {
TmThreadTestThreadUnPaused(tv); TmThreadTestThreadUnPaused(tv);
@ -361,9 +363,11 @@ void *AppLayerDetectProtoThread(void *td)
StreamMsgReturnToPool(smsg); StreamMsgReturnToPool(smsg);
} }
if (tv->flags & THV_KILL) if (tv->flags & THV_KILL) {
PerfUpdateCounterArray(tv->pca, &tv->pctx, 0);
run = 0; run = 0;
} }
}
pthread_exit((void *) 0); pthread_exit((void *) 0);
} }

@ -144,6 +144,7 @@ void * PerfMgmtThread(void *arg)
return NULL; return NULL;
} }
tv_local->flags |= THV_INIT_DONE;
while (run) { while (run) {
TmThreadTestThreadUnPaused(tv_local); TmThreadTestThreadUnPaused(tv_local);
@ -183,6 +184,7 @@ void * PerfWakeupThread(void *arg)
printf("PerfWakeupThread: spawned\n"); printf("PerfWakeupThread: spawned\n");
tv_local->flags |= THV_INIT_DONE;
while (run) { while (run) {
TmThreadTestThreadUnPaused(tv_local); TmThreadTestThreadUnPaused(tv_local);

@ -1594,12 +1594,15 @@ int main(int argc, char **argv)
/* Spawn the L7 App Detect thread */ /* Spawn the L7 App Detect thread */
AppLayerDetectProtoThreadSpawn(); AppLayerDetectProtoThreadSpawn();
/* Spawn the perf counter threads */ /* Spawn the perf counter threads. Let these be the last one spawned */
PerfSpawnThreads(); PerfSpawnThreads();
/* Check if the alloted queues have at least 1 reader and writer */ /* Check if the alloted queues have at least 1 reader and writer */
TmValidateQueueState(); TmValidateQueueState();
/* Waits till all the threads have been initialized */
TmThreadWaitOnThreadInit();
/* Un-pause all the paused threads */ /* Un-pause all the paused threads */
TmThreadContinueThreads(); TmThreadContinueThreads();

@ -495,6 +495,7 @@ void *FlowManagerThread(void *td)
printf("%s started...\n", th_v->name); printf("%s started...\n", th_v->name);
th_v->flags |= THV_INIT_DONE;
while (1) while (1)
{ {
TmThreadTestThreadUnPaused(th_v); TmThreadTestThreadUnPaused(th_v);
@ -553,6 +554,7 @@ void *FlowManagerThread(void *td)
} }
if (th_v->flags & THV_KILL) { if (th_v->flags & THV_KILL) {
PerfUpdateCounterArray(th_v->pca, &th_v->pctx, 0);
break; break;
} }

@ -9,10 +9,11 @@
/** Thread flags set and read by threads to control the threads */ /** Thread flags set and read by threads to control the threads */
#define THV_USE 0x01 /** thread is in use */ #define THV_USE 0x01 /** thread is in use */
#define THV_PAUSE 0x02 /** thread has been paused */ #define THV_INIT_DONE 0x02 /** thread initialization done */
#define THV_KILL 0x04 /** thread has been asked to cleanup and exit */ #define THV_PAUSE 0x04 /** thread has been paused */
#define THV_FAILED 0x08 /** thread has encountered an error and failed */ #define THV_KILL 0x08 /** thread has been asked to cleanup and exit */
#define THV_CLOSED 0x10 /** thread done, should be joinable */ #define THV_FAILED 0x10 /** thread has encountered an error and failed */
#define THV_CLOSED 0x20 /** thread done, should be joinable */
/** Thread flags set and read by threads, to control the threads, when they /** Thread flags set and read by threads, to control the threads, when they
encounter certain conditions like failure */ encounter certain conditions like failure */

@ -81,6 +81,7 @@ void *TmThreadsSlot1NoIn(void *td) {
} }
memset(&s->s.slot_pq, 0, sizeof(PacketQueue)); memset(&s->s.slot_pq, 0, sizeof(PacketQueue));
tv->flags |= THV_INIT_DONE;
while(run) { while(run) {
TmThreadTestThreadUnPaused(tv); TmThreadTestThreadUnPaused(tv);
@ -101,9 +102,11 @@ void *TmThreadsSlot1NoIn(void *td) {
tv->tmqh_out(tv, p); tv->tmqh_out(tv, p);
if (tv->flags & THV_KILL) if (tv->flags & THV_KILL) {
PerfUpdateCounterArray(tv->pca, &tv->pctx, 0);
run = 0; run = 0;
} }
}
if (s->s.SlotThreadExitPrintStats != NULL) { if (s->s.SlotThreadExitPrintStats != NULL) {
s->s.SlotThreadExitPrintStats(tv, s->s.slot_data); s->s.SlotThreadExitPrintStats(tv, s->s.slot_data);
@ -142,6 +145,7 @@ void *TmThreadsSlot1NoOut(void *td) {
} }
memset(&s->s.slot_pq, 0, sizeof(PacketQueue)); memset(&s->s.slot_pq, 0, sizeof(PacketQueue));
tv->flags |= THV_INIT_DONE;
while(run) { while(run) {
TmThreadTestThreadUnPaused(tv); TmThreadTestThreadUnPaused(tv);
@ -156,9 +160,11 @@ void *TmThreadsSlot1NoOut(void *td) {
break; break;
} }
if (tv->flags & THV_KILL) if (tv->flags & THV_KILL) {
PerfUpdateCounterArray(tv->pca, &tv->pctx, 0);
run = 0; run = 0;
} }
}
if (s->s.SlotThreadExitPrintStats != NULL) { if (s->s.SlotThreadExitPrintStats != NULL) {
s->s.SlotThreadExitPrintStats(tv, s->s.slot_data); s->s.SlotThreadExitPrintStats(tv, s->s.slot_data);
@ -198,6 +204,7 @@ void *TmThreadsSlot1NoInOut(void *td) {
} }
memset(&s->s.slot_pq, 0, sizeof(PacketQueue)); memset(&s->s.slot_pq, 0, sizeof(PacketQueue));
tv->flags |= THV_INIT_DONE;
while(run) { while(run) {
TmThreadTestThreadUnPaused(tv); TmThreadTestThreadUnPaused(tv);
@ -212,6 +219,7 @@ void *TmThreadsSlot1NoInOut(void *td) {
if (tv->flags & THV_KILL) { if (tv->flags & THV_KILL) {
//printf("%s: TmThreadsSlot1NoInOut: KILL is set\n", tv->name); //printf("%s: TmThreadsSlot1NoInOut: KILL is set\n", tv->name);
PerfUpdateCounterArray(tv->pca, &tv->pctx, 0);
run = 0; run = 0;
} }
} }
@ -256,6 +264,7 @@ void *TmThreadsSlot1(void *td) {
} }
memset(&s->s.slot_pq, 0, sizeof(PacketQueue)); memset(&s->s.slot_pq, 0, sizeof(PacketQueue));
tv->flags |= THV_INIT_DONE;
while(run) { while(run) {
TmThreadTestThreadUnPaused(tv); TmThreadTestThreadUnPaused(tv);
@ -289,6 +298,7 @@ void *TmThreadsSlot1(void *td) {
if (tv->flags & THV_KILL) { if (tv->flags & THV_KILL) {
//printf("%s: TmThreadsSlot1: KILL is set\n", tv->name); //printf("%s: TmThreadsSlot1: KILL is set\n", tv->name);
PerfUpdateCounterArray(tv->pca, &tv->pctx, 0);
run = 0; run = 0;
} }
} }
@ -375,6 +385,7 @@ void *TmThreadsSlotVar(void *td) {
memset(&slot->slot_pq, 0, sizeof(PacketQueue)); memset(&slot->slot_pq, 0, sizeof(PacketQueue));
} }
tv->flags |= THV_INIT_DONE;
while(run) { while(run) {
TmThreadTestThreadUnPaused(tv); TmThreadTestThreadUnPaused(tv);
@ -400,6 +411,7 @@ void *TmThreadsSlotVar(void *td) {
if (tv->flags & THV_KILL) { if (tv->flags & THV_KILL) {
//printf("%s: TmThreadsSlot1: KILL is set\n", tv->name); //printf("%s: TmThreadsSlot1: KILL is set\n", tv->name);
PerfUpdateCounterArray(tv->pca, &tv->pctx, 0);
run = 0; run = 0;
} }
} }
@ -1033,3 +1045,24 @@ void TmThreadCheckThreadState(void)
return; return;
} }
/** \brief Used to check if all threads have finished their initialization. On
* finding an un-initialized thread, it waits till that thread completes
* its initialization, before proceeding to the next thread.
*/
void TmThreadWaitOnThreadInit(void)
{
ThreadVars *tv = NULL;
int i = 0;
for (i = 0; i < TVT_MAX; i++) {
tv = tv_root[i];
while (tv != NULL) {
while (!(tv->flags & THV_INIT_DONE))
;
tv = tv->next;
}
}
return;
}

@ -50,5 +50,7 @@ void TmThreadPauseThreads(void);
void TmThreadCheckThreadState(void); void TmThreadCheckThreadState(void);
void TmThreadWaitOnThreadInit(void);
#endif /* __TM_THREADS_H__ */ #endif /* __TM_THREADS_H__ */

Loading…
Cancel
Save