suricata
tmqh-packetpool.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2014 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  */
23 
24 #ifndef SURICATA_TMQH_PACKETPOOL_H
25 #define SURICATA_TMQH_PACKETPOOL_H
26 
27 #include "decode.h"
28 #include "threads.h"
29 
30  /* Return stack, onto which other threads free packets. */
31 typedef struct PktPoolLockedStack_{
32  /* linked list of free packets. */
35  /** number of packets in needed to trigger a sync during
36  * the return to pool logic. Updated by pool owner based
37  * on how full the pool is. */
38  SC_ATOMIC_DECLARE(uint32_t, return_threshold);
39  uint32_t cnt;
41 } __attribute__((aligned(CLS))) PktPoolLockedStack;
42 
43 typedef struct PktPool_ {
44  /* link listed of free packets local to this thread.
45  * No mutex is needed.
46  */
48  uint32_t cnt;
49 
50  /* Packets waiting (pending) to be returned to the given Packet
51  * Pool. Accumulate packets for the same pool until a threshold is
52  * reached, then return them all at once. Keep the head and tail
53  * to fast insertion of the entire list onto a return stack.
54  */
58  uint32_t pending_count;
59 
60 #ifdef DEBUG_VALIDATION
61  int initialized;
62  int destroyed;
63 #endif /* DEBUG_VALIDATION */
64 
65  /* All members above this point are accessed locally by only one thread, so
66  * these should live on their own cache line.
67  */
68 
69  /* Return stack, where other threads put packets that they free that belong
70  * to this thread.
71  */
72  PktPoolLockedStack return_stack;
74 
78 void TmqhPacketpoolRegister(void);
80 void PacketPoolWait(void);
82 void PacketPoolInit(void);
83 void PacketPoolDestroy(void);
84 void PacketPoolPostRunmodes(void);
85 
86 #endif /* SURICATA_TMQH_PACKETPOOL_H */
PktPool_::pending_tail
Packet * pending_tail
Definition: tmqh-packetpool.h:57
TmqhPacketpoolRegister
void TmqhPacketpoolRegister(void)
TmqhPacketpoolRegister \initonly.
Definition: tmqh-packetpool.c:55
PktPool_::cnt
uint32_t cnt
Definition: tmqh-packetpool.h:48
PktPoolLockedStack_::cnt
uint32_t cnt
Definition: tmqh-packetpool.h:39
CLS
#define CLS
Definition: suricata-common.h:56
PktPool_
Definition: tmqh-packetpool.h:43
PacketQueue_
simple fifo queue for packets with mutex and cond Calling the mutex or triggering the cond is respons...
Definition: packet-queue.h:49
threads.h
SCCondT
#define SCCondT
Definition: threads-debug.h:137
PacketPoolGetPacket
Packet * PacketPoolGetPacket(void)
Get a new packet from the packet pool.
Definition: tmqh-packetpool.c:127
PktPoolLockedStack_::SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(uint32_t, return_threshold)
PktPool_::pending_count
uint32_t pending_count
Definition: tmqh-packetpool.h:58
PacketPoolInit
void PacketPoolInit(void)
Definition: tmqh-packetpool.c:246
PktPoolLockedStack_::head
Packet * head
Definition: tmqh-packetpool.h:40
PktPoolLockedStack_
Definition: tmqh-packetpool.h:31
PktPool_::pending_head
Packet * pending_head
Definition: tmqh-packetpool.h:56
PacketPoolDestroy
void PacketPoolDestroy(void)
Definition: tmqh-packetpool.c:277
decode.h
PacketPoolPostRunmodes
void PacketPoolPostRunmodes(void)
Set the max_pending_return_packets value.
Definition: tmqh-packetpool.c:462
PktPoolLockedStack_::cond
SCCondT cond
Definition: tmqh-packetpool.h:34
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
__attribute__
struct PktPoolLockedStack_ __attribute__((aligned(CLS))) PktPoolLockedStack
Packet_
Definition: decode.h:482
PacketPoolWait
void PacketPoolWait(void)
Definition: tmqh-packetpool.c:80
PktPool_::return_stack
PktPoolLockedStack return_stack
Definition: tmqh-packetpool.h:72
TmqhReleasePacketsToPacketPool
void TmqhReleasePacketsToPacketPool(PacketQueue *)
Release all the packets in the queue back to the packetpool. Mainly used by threads that have failed,...
Definition: tmqh-packetpool.c:430
PktPool
struct PktPool_ PktPool
PktPool_::pending_pool
struct PktPool_ * pending_pool
Definition: tmqh-packetpool.h:55
PacketPoolReturnPacket
void PacketPoolReturnPacket(Packet *p)
Return packet to Packet pool.
Definition: tmqh-packetpool.c:179
TmqhOutputPacketpool
void TmqhOutputPacketpool(ThreadVars *, Packet *)
Definition: tmqh-packetpool.c:317
PktPool_::head
Packet * head
Definition: tmqh-packetpool.h:47
SCMutex
#define SCMutex
Definition: threads-debug.h:114
TmqhInputPacketpool
Packet * TmqhInputPacketpool(ThreadVars *)
Definition: tmqh-packetpool.c:312
PktPoolLockedStack_::mutex
SCMutex mutex
Definition: tmqh-packetpool.h:33