Go to the documentation of this file.
41 #define MAX_PENDING_RETURN_PACKETS 32
46 static inline PktPool *GetThreadPacketPool(
void)
62 static int PacketPoolIsEmpty(
PktPool *pool)
71 static void UpdateReturnThreshold(
PktPool *pool)
74 uint32_t threshold = (uint32_t)(perc * (
float)max_pending_return_packets);
82 PktPool *my_pool = GetThreadPacketPool();
84 if (PacketPoolIsEmpty(my_pool)) {
91 UpdateReturnThreshold(my_pool);
94 while(PacketPoolIsEmpty(my_pool))
102 static void PacketPoolStorePacket(
Packet *p)
104 p->
pool = GetThreadPacketPool();
109 static void PacketPoolGetReturnedPackets(
PktPool *pool)
129 PktPool *pool = GetThreadPacketPool();
130 #ifdef DEBUG_VALIDATION
131 BUG_ON(pool->initialized == 0);
132 BUG_ON(pool->destroyed == 1);
142 UpdateReturnThreshold(pool);
143 SCLogDebug(
"pp: %0.2f cnt:%u max:%d threshold:%u",
151 PacketPoolGetReturnedPackets(pool);
164 UpdateReturnThreshold(pool);
165 SCLogDebug(
"pp: %0.2f cnt:%u max:%d threshold:%u",
181 PktPool *my_pool = GetThreadPacketPool();
190 #ifdef DEBUG_VALIDATION
191 BUG_ON(pool->initialized == 0);
192 BUG_ON(pool->destroyed == 1);
193 BUG_ON(my_pool->initialized == 0);
194 BUG_ON(my_pool->destroyed == 1);
197 if (pool == my_pool) {
204 if (pending_pool == NULL || pending_pool == pool) {
205 if (pending_pool == NULL) {
212 }
else if (pending_pool == pool) {
248 PktPool *my_pool = GetThreadPacketPool();
250 #ifdef DEBUG_VALIDATION
251 BUG_ON(my_pool->initialized);
252 my_pool->initialized = 1;
253 my_pool->destroyed = 0;
262 SCLogDebug(
"preallocating packets... packet size %" PRIuMAX
"",
268 FatalError(
"Fatal error encountered while allocating a packet. Exiting...");
270 PacketPoolStorePacket(p);
280 PktPool *my_pool = GetThreadPacketPool();
282 #ifdef DEBUG_VALIDATION
283 BUG_ON(my_pool && my_pool->destroyed);
294 #ifdef DEBUG_VALIDATION
306 #ifdef DEBUG_VALIDATION
307 my_pool->initialized = 0;
308 my_pool->destroyed = 1;
324 if (PacketIsTunnel(p)) {
325 SCLogDebug(
"Packet %p is a tunnel packet: %s",
326 p,p->
root ?
"upper layer" :
"tunnel root");
332 if (PacketIsTunnelRoot(p)) {
337 SCLogDebug(
"root pkt: outstanding %u", outstanding);
338 if (outstanding == 0) {
339 SCLogDebug(
"no tunnel packets outstanding, no more tunnel "
340 "packet(s) depending on this root");
346 SCLogDebug(
"tunnel root Packet %p: outstanding > 0, so "
347 "packets are still depending on this root, setting "
348 "SET_TUNNEL_PKT_VERDICTED", p);
353 PacketTunnelSetVerdicted(p);
360 SCLogDebug(
"NOT IS_TUNNEL_ROOT_PKT, so tunnel pkt");
364 SCLogDebug(
"tunnel pkt: outstanding %u", outstanding);
368 if (outstanding == 0 && p->
root && PacketTunnelIsVerdicted(p->
root)) {
369 SCLogDebug(
"root verdicted == true && no outstanding");
372 SCLogDebug(
"setting proot = 1 for root pkt, p->root %p "
373 "(tunnel packet %p)", p->
root, p);
382 SCLogDebug(
"NOT IS_TUNNEL_PKT_VERDICTED (%s) || "
383 "outstanding > 0 (%u)",
384 (p->
root && PacketTunnelIsVerdicted(p->
root)) ?
"true" :
"false",
392 SCLogDebug(
"tunnel stuff done, move on (proot %d)", proot);
399 PacketIsTunnel(p) ? PacketIsTunnelRoot(p) ?
"tunnel::root" :
"tunnel::leaf"
449 #define RESERVED_PACKETS 10
470 "must be at least %d",
477 uint32_t packets = (pending_packets / threads) - 1;
478 if (packets < max_pending_return_packets)
479 max_pending_return_packets = packets;
485 SCLogDebug(
"detect threads %u, max packets %u, max_pending_return_packets %u",
486 threads, packets, max_pending_return_packets);
uint16_t max_pending_packets
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
struct Packet_::@40 persistent
void PacketPoolReturnPacket(Packet *p)
Return packet to Packet pool.
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
#define TM_FLAG_DETECT_TM
simple fifo queue for packets with mutex and cond Calling the mutex or triggering the cond is respons...
void(* OutHandler)(ThreadVars *, Packet *)
void PacketReleaseRefs(Packet *p)
uint32_t TmThreadCountThreadsByTmmFlags(uint8_t flags)
returns a count of all the threads that match the flag
void PacketPoolPostRunmodes(void)
Set the max_pending_return_packets value.
#define MAX_PENDING_RETURN_PACKETS
void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
thread_local PktPool thread_pkt_pool
void TmqhReleasePacketsToPacketPool(PacketQueue *pq)
Release all the packets in the queue back to the packetpool. Mainly used by threads that have failed,...
void PacketPoolInit(void)
Packet *(* InHandler)(ThreadVars *)
#define TUNNEL_PKT_TPR(p)
void PacketReinit(Packet *p)
Recycle a packet structure for reuse.
#define SCMutexUnlock(mut)
void CaptureStatsUpdate(ThreadVars *tv, const Packet *p)
Per thread variable structure.
void PacketFree(Packet *p)
Return a malloced packet.
Packet * TmqhInputPacketpool(ThreadVars *tv)
void PacketPoolWait(void)
#define SCMutexInit(mut, mutattrs)
PktPoolLockedStack return_stack
void TmqhPacketpoolRegister(void)
TmqhPacketpoolRegister \initonly.
void(* ReleasePacket)(struct Packet_ *)
Tmqh tmqh_table[TMQH_SIZE]
Packet * PacketDequeue(PacketQueue *q)
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
#define TUNNEL_PKT_RTV(p)
#define TUNNEL_INCR_PKT_RTV_NOLOCK(p)
#define PACKET_PROFILING_END(p)
Packet * PacketPoolGetPacket(void)
Get a new packet from the packet pool.
struct PktPool_ * pending_pool
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
void PacketPoolDestroy(void)
#define DEBUG_VALIDATE_BUG_ON(exp)