Project

General

Profile

Bug #382 » 0001-Flow-use-condition-system-instead-of-short-sleep.patch

Eric Leblond, 11/30/2011 02:34 AM

View differences:

src/flow-hash.c
#include "flow-hash.h"
#include "flow-util.h"
#include "flow-private.h"
#include "flow-manager.h"
#include "app-layer-parser.h"
#include "util-time.h"
......
static Flow *FlowGetNew(Packet *p) {
Flow *f = NULL;
if (FlowCreateCheck(p) == 0) {
return NULL;
}
......
/* flow has been recycled before it went into the spare queue */
/* flow is initialized (recylced) but *unlocked* */
/* Important event for flow system, let's ask for a refresh to flow
manager */
SCCondSignal(&flow_manager_cond);
}
FlowIncrUsecnt(f);
src/flow-manager.c
/* Run mode selected at suricata.c */
extern int run_mode;
#define FLOW_UPDATE_DELAY 2
#define NEW_FLOW_COUNT_COND 10
/**
* \brief Used to kill flow manager thread(s).
*
......
ThreadVars *tv = NULL;
int cnt = 0;
SCCondSignal(&flow_manager_cond);
SCMutexLock(&tv_root_lock);
/* flow manager thread(s) is/are a part of mgmt threads */
......
int emerg = FALSE;
int prev_emerg = FALSE;
uint32_t last_sec = 0;
struct timespec cond_time;
int counter = 0;
uint16_t flow_mgr_closing_cnt = SCPerfTVRegisterCounter("flow_mgr.closed_pruned", th_v,
SC_PERF_TYPE_UINT64,
......
{
TmThreadTestThreadUnPaused(th_v);
if (sleeping >= 100 || flow_flags & FLOW_EMERGENCY)
{
if ((counter > NEW_FLOW_COUNT_COND) || (flow_flags & FLOW_EMERGENCY)) {
counter = 0;
if (flow_flags & FLOW_EMERGENCY) {
emerg = TRUE;
......
SCMutexUnlock(&flow_spare_q.mutex_q);
SCLogDebug("flow_sparse_q.len = %"PRIu32" prealloc: %"PRIu32
"flow_spare_q status: %"PRIu32"%% flows at the queue",
len, flow_config.prealloc, len * 100 / flow_config.prealloc);
"flow_spare_q status: %"PRIu32"%% flows at the queue",
len, flow_config.prealloc, len * 100 / flow_config.prealloc);
/* only if we have pruned this "emergency_recovery" percentage
* of flows, we will unset the emergency bit */
if (len * 100 / flow_config.prealloc > flow_config.emergency_recovery) {
......
emerg = FALSE;
prev_emerg = FALSE;
SCLogInfo("Flow emergency mode over, back to normal... unsetting"
" FLOW_EMERGENCY bit (ts.tv_sec: %"PRIuMAX", "
"ts.tv_usec:%"PRIuMAX") flow_spare_q status(): %"PRIu32
"%% flows at the queue", (uintmax_t)ts.tv_sec,
(uintmax_t)ts.tv_usec, len * 100 / flow_config.prealloc);
" FLOW_EMERGENCY bit (ts.tv_sec: %"PRIuMAX", "
"ts.tv_usec:%"PRIuMAX") flow_spare_q status(): %"PRIu32
"%% flows at the queue", (uintmax_t)ts.tv_sec,
(uintmax_t)ts.tv_usec, len * 100 / flow_config.prealloc);
SCPerfCounterIncr(flow_emerg_mode_over, th_v->sc_perf_pca);
}
......
break;
}
#if 0
if (run_mode != RUNMODE_PCAP_FILE) {
usleep(10);
sleeping += 10;
#endif
cond_time.tv_sec = time(NULL) + FLOW_UPDATE_DELAY;
cond_time.tv_nsec = 0;
SCMutexLock(&flow_manager_mutex);
if (SCCondTimedwait(&flow_manager_cond, &flow_manager_mutex, &cond_time) == ETIMEDOUT) {
counter = NEW_FLOW_COUNT_COND;
}
counter++;
SCMutexUnlock(&flow_manager_mutex);
#if 0
} else {
/* If we are reading a pcap, how long the pcap timestamps
* says that has passed */
......
usleep(1);
}
}
#endif
SCPerfSyncCountersIfSignalled(th_v, 0);
}
......
{
ThreadVars *tv_flowmgr = NULL;
SCCondInit(&flow_manager_cond, &flow_manager_mutex);
tv_flowmgr = TmThreadCreateMgmtThread("FlowManagerThread",
FlowManagerThread, 0);
src/flow-manager.h
#ifndef __FLOW_MANAGER_H__
#define __FLOW_MANAGER_H__
SCCondT flow_manager_cond;
SCMutex flow_manager_mutex;
void FlowManagerThreadSpawn(void);
void FlowKillFlowManagerThread(void);
src/flow-util.c
return FLOW_PROTO_UDP;
case IPPROTO_ICMP:
return FLOW_PROTO_ICMP;
case IPPROTO_SCTP:
case IPPROTO_SCTP:
return FLOW_PROTO_SCTP;
default:
return FLOW_PROTO_DEFAULT;
(2-2/2)