Go to the documentation of this file.
41 #define MAX_PENDING_RETURN_PACKETS 32
46 static inline PktPool *GetThreadPacketPool(
void)
62 static void UpdateReturnThreshold(
PktPool *pool)
65 uint32_t threshold = (uint32_t)(perc * (
float)max_pending_return_packets);
73 PktPool *my_pool = GetThreadPacketPool();
75 if (my_pool->
head == NULL) {
85 UpdateReturnThreshold(my_pool);
93 static void PacketPoolStorePacket(
Packet *p)
95 p->
pool = GetThreadPacketPool();
100 static void PacketPoolGetReturnedPackets(
PktPool *pool)
120 PktPool *pool = GetThreadPacketPool();
131 UpdateReturnThreshold(pool);
132 SCLogDebug(
"pp: %0.2f cnt:%u max:%d threshold:%u",
140 PacketPoolGetReturnedPackets(pool);
153 UpdateReturnThreshold(pool);
154 SCLogDebug(
"pp: %0.2f cnt:%u max:%d threshold:%u",
170 PktPool *my_pool = GetThreadPacketPool();
179 #ifdef DEBUG_VALIDATION
180 BUG_ON(pool->initialized == 0);
181 BUG_ON(pool->destroyed == 1);
182 BUG_ON(my_pool->initialized == 0);
183 BUG_ON(my_pool->destroyed == 1);
186 if (pool == my_pool) {
193 if (pending_pool == NULL || pending_pool == pool) {
194 if (pending_pool == NULL) {
201 }
else if (pending_pool == pool) {
237 PktPool *my_pool = GetThreadPacketPool();
239 #ifdef DEBUG_VALIDATION
240 BUG_ON(my_pool->initialized);
241 my_pool->initialized = 1;
242 my_pool->destroyed = 0;
251 SCLogDebug(
"preallocating packets... packet size %" PRIuMAX
"",
256 FatalError(
"Fatal error encountered while allocating a packet. Exiting...");
258 PacketPoolStorePacket(p);
268 PktPool *my_pool = GetThreadPacketPool();
270 #ifdef DEBUG_VALIDATION
271 BUG_ON(my_pool && my_pool->destroyed);
282 #ifdef DEBUG_VALIDATION
294 #ifdef DEBUG_VALIDATION
295 my_pool->initialized = 0;
296 my_pool->destroyed = 1;
312 if (PacketIsTunnel(p)) {
313 SCLogDebug(
"Packet %p is a tunnel packet: %s",
314 p,p->
root ?
"upper layer" :
"tunnel root");
320 if (PacketIsTunnelRoot(p)) {
325 SCLogDebug(
"root pkt: outstanding %u", outstanding);
326 if (outstanding == 0) {
327 SCLogDebug(
"no tunnel packets outstanding, no more tunnel "
328 "packet(s) depending on this root");
334 SCLogDebug(
"tunnel root Packet %p: outstanding > 0, so "
335 "packets are still depending on this root, setting "
336 "SET_TUNNEL_PKT_VERDICTED", p);
341 PacketTunnelSetVerdicted(p);
348 SCLogDebug(
"NOT IS_TUNNEL_ROOT_PKT, so tunnel pkt");
352 SCLogDebug(
"tunnel pkt: outstanding %u", outstanding);
356 if (outstanding == 0 && p->
root && PacketTunnelIsVerdicted(p->
root)) {
357 SCLogDebug(
"root verdicted == true && no outstanding");
360 SCLogDebug(
"setting proot = 1 for root pkt, p->root %p "
361 "(tunnel packet %p)", p->
root, p);
370 SCLogDebug(
"NOT IS_TUNNEL_PKT_VERDICTED (%s) || "
371 "outstanding > 0 (%u)",
372 (p->
root && PacketTunnelIsVerdicted(p->
root)) ?
"true" :
"false",
380 SCLogDebug(
"tunnel stuff done, move on (proot %d)", proot);
387 PacketIsTunnel(p) ? PacketIsTunnelRoot(p) ?
"tunnel::root" :
"tunnel::leaf"
435 #define RESERVED_PACKETS 10
456 "must be at least %d",
463 uint32_t packets = (pending_packets / threads) - 1;
464 if (packets < max_pending_return_packets)
465 max_pending_return_packets = packets;
471 SCLogDebug(
"detect threads %u, max packets %u, max_pending_return_packets %u",
472 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.
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
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
struct Packet_::@39 persistent
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)
#define TM_FLAG_FLOWWORKER_TM