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();
140 UpdateReturnThreshold(pool);
141 SCLogDebug(
"pp: %0.2f cnt:%u max:%d threshold:%u",
149 PacketPoolGetReturnedPackets(pool);
162 UpdateReturnThreshold(pool);
163 SCLogDebug(
"pp: %0.2f cnt:%u max:%d threshold:%u",
179 PktPool *my_pool = GetThreadPacketPool();
188 #ifdef DEBUG_VALIDATION
189 BUG_ON(pool->initialized == 0);
190 BUG_ON(pool->destroyed == 1);
191 BUG_ON(my_pool->initialized == 0);
192 BUG_ON(my_pool->destroyed == 1);
195 if (pool == my_pool) {
202 if (pending_pool == NULL || pending_pool == pool) {
203 if (pending_pool == NULL) {
210 }
else if (pending_pool == pool) {
246 PktPool *my_pool = GetThreadPacketPool();
248 #ifdef DEBUG_VALIDATION
249 BUG_ON(my_pool->initialized);
250 my_pool->initialized = 1;
251 my_pool->destroyed = 0;
260 SCLogDebug(
"preallocating packets... packet size %" PRIuMAX
"",
265 FatalError(
"Fatal error encountered while allocating a packet. Exiting...");
267 PacketPoolStorePacket(p);
277 PktPool *my_pool = GetThreadPacketPool();
279 #ifdef DEBUG_VALIDATION
280 BUG_ON(my_pool && my_pool->destroyed);
291 #ifdef DEBUG_VALIDATION
303 #ifdef DEBUG_VALIDATION
304 my_pool->initialized = 0;
305 my_pool->destroyed = 1;
321 if (PacketIsTunnel(p)) {
322 SCLogDebug(
"Packet %p is a tunnel packet: %s",
323 p,p->
root ?
"upper layer" :
"tunnel root");
329 if (PacketIsTunnelRoot(p)) {
334 SCLogDebug(
"root pkt: outstanding %u", outstanding);
335 if (outstanding == 0) {
336 SCLogDebug(
"no tunnel packets outstanding, no more tunnel "
337 "packet(s) depending on this root");
343 SCLogDebug(
"tunnel root Packet %p: outstanding > 0, so "
344 "packets are still depending on this root, setting "
345 "SET_TUNNEL_PKT_VERDICTED", p);
350 PacketTunnelSetVerdicted(p);
357 SCLogDebug(
"NOT IS_TUNNEL_ROOT_PKT, so tunnel pkt");
361 SCLogDebug(
"tunnel pkt: outstanding %u", outstanding);
365 if (outstanding == 0 && p->
root && PacketTunnelIsVerdicted(p->
root)) {
366 SCLogDebug(
"root verdicted == true && no outstanding");
369 SCLogDebug(
"setting proot = 1 for root pkt, p->root %p "
370 "(tunnel packet %p)", p->
root, p);
379 SCLogDebug(
"NOT IS_TUNNEL_PKT_VERDICTED (%s) || "
380 "outstanding > 0 (%u)",
381 (p->
root && PacketTunnelIsVerdicted(p->
root)) ?
"true" :
"false",
389 SCLogDebug(
"tunnel stuff done, move on (proot %d)", proot);
396 PacketIsTunnel(p) ? PacketIsTunnelRoot(p) ?
"tunnel::root" :
"tunnel::leaf"
444 #define RESERVED_PACKETS 10
465 "must be at least %d",
472 uint32_t packets = (pending_packets / threads) - 1;
473 if (packets < max_pending_return_packets)
474 max_pending_return_packets = packets;
480 SCLogDebug(
"detect threads %u, max packets %u, max_pending_return_packets %u",
481 threads, packets, max_pending_return_packets);
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
void PacketPoolReturnPacket(Packet *p)
Return packet to Packet pool.
struct Packet_::@35 persistent
#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)
uint32_t max_pending_packets
#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)