25#ifndef SURICATA_TM_THREADS_H
26#define SURICATA_TM_THREADS_H
34static inline void SleepUsec(uint64_t usec)
42#define SleepMsec(msec) Sleep((msec))
44#define SleepUsec(usec) usleep((usec))
45#define SleepMsec(msec) usleep((msec) * 1000)
48#define TM_QUEUE_NAME_MAX 16
49#define TM_THREAD_NAME_MAX 16
88 void *(fn_p)(
void *),
int);
126 const uint16_t set,
const uint16_t check,
const uint8_t module_flags);
166static inline bool TmThreadsHandleInjectedPackets(
ThreadVars *
tv)
169 if (pq && pq->
len > 0) {
176#ifdef DEBUG_VALIDATION
181 TmThreadsSlotProcessPktFail(
tv, extra_p);
204 TmThreadsSlotProcessPktFail(
tv, p);
210 TmThreadsHandleInjectedPackets(
tv);
245 TmThreadsCaptureInjectPacket(
tv, p);
249 if (!TmThreadsHandleInjectedPackets(
tv)) {
252 TmThreadsCaptureInjectPacket(
tv, p);
264static inline void TmThreadsCaptureBreakLoop(
ThreadVars *
tv)
#define PKT_PSEUDO_STREAM_END
#define PKT_SET_SRC(p, src_val)
@ PKT_SRC_CAPTURE_TIMEOUT
Packet * PacketGetFromQueueOrAlloc(void)
Get a packet. We try to get a packet from the packetpool first, but if that is empty we alloc a packe...
Packet * PacketDequeue(PacketQueue *q)
Packet * PacketDequeueNoLock(PacketQueueNoLock *qnl)
simple fifo queue for packets
simple fifo queue for packets with mutex and cond Calling the mutex or triggering the cond is respons...
Per thread variable structure.
struct PacketQueue_ * stream_pq_local
struct TmSlot_ * tm_slots
void(* tmqh_out)(struct ThreadVars_ *, struct Packet_ *)
PacketQueueNoLock decode_pq
struct TmSlot_ * tm_flowworker
struct FlowQueue_ * flow_queue
TmEcode(* PktAcqBreakLoop)(ThreadVars *, void *)
TmEcode(* PktAcqLoop)(ThreadVars *, void *, void *)
SC_ATOMIC_DECLARE(void *, slot_data)
const void * slot_initdata
TmEcode(* PktAcqLoop)(ThreadVars *, void *, void *)
TmEcode(* SlotThreadDeinit)(ThreadVars *, void *)
struct TmSlot_ * slot_next
TmEcode(* Management)(ThreadVars *, void *)
TmEcode(* SlotThreadInit)(ThreadVars *, const void *, void **)
void(* SlotThreadExitPrintStats)(ThreadVars *, void *)
#define SCMutexUnlock(mut)
#define THV_CAPTURE_INJECT_PKT
TmModule * TmModuleGetById(int id)
Returns a TM Module by its id.
#define TM_FLAG_RECEIVE_TM
void TmThreadKillThreads(void)
TmEcode TmThreadSetupOptions(ThreadVars *)
Set the thread options (cpu affinitythread). Priority should be already set by pthread_create.
void TmThreadClearThreadsFamily(int family)
void TmSlotSetFuncAppend(ThreadVars *, TmModule *, const void *)
Appends a new entry to the slots.
SCTime_t TmThreadsGetThreadTime(const int idx)
void TmThreadInitMC(ThreadVars *)
Initializes the mutex and condition variables for this TV.
bool SCTmThreadsSlotPacketLoopFinish(ThreadVars *tv)
TmEcode TmThreadWaitOnThreadInit(void)
Used to check if all threads have finished their initialization. On finding an un-initialized thread,...
void TmThreadAppend(ThreadVars *, int)
Appends this TV to tv_root based on its type.
TmEcode TmThreadsSlotVarRun(ThreadVars *tv, Packet *p, TmSlot *slot)
Separate run function so we can call it recursively.
ThreadVars * TmThreadCreate(const char *, const char *, const char *, const char *, const char *, const char *, void *(fn_p)(void *), int)
ThreadVars * TmThreadCreateCmdThreadByName(const char *name, const char *module, int mucond)
Creates and returns the TV instance for a Command thread (CMD). This function supports only custom sl...
ThreadVars * TmThreadCreateMgmtThreadByName(const char *name, const char *module, int mucond)
Creates and returns the TV instance for a Management thread(MGMT). This function supports only custom...
int TmThreadGetNbThreads(uint8_t type)
void TmThreadsUnsealThreads(void)
void TmThreadsSetFlag(ThreadVars *, uint32_t)
Set a thread flag.
TmEcode TmThreadSpawn(ThreadVars *)
Spawns a thread associated with the ThreadVars instance tv.
void TmThreadSetGroupName(ThreadVars *tv, const char *name)
int TmThreadsRegisterThread(ThreadVars *tv, const int type)
uint16_t TmThreadsGetWorkerThreadMax(void)
void TmThreadsUnsetFlag(ThreadVars *, uint32_t)
Unset a thread flag.
TmEcode(* TmSlotFunc)(ThreadVars *, Packet *, void *)
void TmThreadContinue(ThreadVars *)
Unpauses a thread.
TmEcode TmThreadSetThreadPriority(ThreadVars *, int)
Set the thread options (thread priority).
void TmThreadsInjectFlowById(Flow *f, const int id)
inject a flow into a threads flow queue
TmEcode TmThreadSetCPU(ThreadVars *, uint8_t)
void TmThreadsListThreads(void)
ThreadVars * tv_root[TVT_MAX]
TmEcode TmThreadLibSpawn(ThreadVars *)
Spawns a "fake" lib thread associated with the ThreadVars instance tv.
void TmThreadDisableReceiveThreads(void)
Disable all threads having the specified TMs.
ThreadVars * TmThreadCreatePacketHandler(const char *, const char *, const char *, const char *, const char *, const char *)
Creates and returns a TV instance for a Packet Processing Thread. This function doesn't support custo...
void TmThreadsInitThreadsTimestamp(const SCTime_t ts)
void TmThreadsUnregisterThread(const int id)
int TmThreadTimeoutLoop(ThreadVars *tv, TmSlot *s)
uint32_t TmThreadCountThreadsByTmmFlags(uint8_t flags)
returns a count of all the threads that match the flag
void TmThreadKillThreadsFamily(int family)
int TmThreadsCheckFlag(ThreadVars *, uint32_t)
Check if a thread flag is set.
void TmThreadContinueThreads(void)
Unpauses all threads present in tv_root.
void TmThreadSetPrio(ThreadVars *)
Adjusting nice value for threads.
bool TmThreadsWaitForUnpause(ThreadVars *tv)
Wait for a thread to become unpaused.
void TmThreadCheckThreadState(void)
Used to check the thread for certain conditions of failure.
void TmThreadDisablePacketThreads(const uint16_t set, const uint16_t check, const uint8_t module_flags)
Disable all packet threads.
void TmThreadWaitForFlag(ThreadVars *, uint32_t)
Waits till the specified flag(s) is(are) set. We don't bother if the kill flag has been set or not on...
TmEcode TmThreadSetCPUAffinity(ThreadVars *, uint16_t)
Set the thread options (cpu affinity).
ThreadVars * TmThreadCreateMgmtThread(const char *name, void *(fn_p)(void *), int)
Creates and returns the TV instance for a Management thread(MGMT). This function supports only custom...
bool TmThreadsTimeSubsysIsReady(void)
void TmThreadsSetThreadTimestamp(const int id, const SCTime_t ts)
void TmThreadsSealThreads(void)
void TmThreadsGetMinimalTimestamp(struct timeval *ts)
TmEcode TmThreadWaitOnThreadRunning(void)
Waits for all threads to be in a running state.
TmEcode TmThreadsProcessDecodePseudoPackets(ThreadVars *tv, PacketQueueNoLock *decode_pq, TmSlot *slot)
void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
void TmqhReleasePacketsToPacketPool(PacketQueue *pq)
Release all the packets in the queue back to the packetpool. Mainly used by threads that have failed,...
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.