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 __TMQH_PACKETPOOL_H__
25 #define __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  SC_ATOMIC_DECLARE(int, sync_now);
37 } __attribute__((aligned(CLS))) PktPoolLockedStack;
38 
39 typedef struct PktPool_ {
40  /* link listed of free packets local to this thread.
41  * No mutex is needed.
42  */
44  /* Packets waiting (pending) to be returned to the given Packet
45  * Pool. Accumulate packets for the same pool until a threshold is
46  * reached, then return them all at once. Keep the head and tail
47  * to fast insertion of the entire list onto a return stack.
48  */
52  uint32_t pending_count;
53 
54 #ifdef DEBUG_VALIDATION
55  int initialized;
56  int destroyed;
57 #endif /* DEBUG_VALIDATION */
58 
59  /* All members above this point are accessed locally by only one thread, so
60  * these should live on their own cache line.
61  */
62 
63  /* Return stack, where other threads put packets that they free that belong
64  * to this thread.
65  */
66  PktPoolLockedStack return_stack;
68 
72 void TmqhPacketpoolRegister(void);
74 void PacketPoolWait(void);
75 void PacketPoolWaitForN(int n);
77 void PacketPoolInit(void);
78 void PacketPoolInitEmpty(void);
79 void PacketPoolDestroy(void);
80 void PacketPoolPostRunmodes(void);
81 
82 #endif /* __TMQH_PACKETPOOL_H__ */
PktPool_::pending_tail
Packet * pending_tail
Definition: tmqh-packetpool.h:51
TmqhPacketpoolRegister
void TmqhPacketpoolRegister(void)
TmqhPacketpoolRegister \initonly.
Definition: tmqh-packetpool.c:53
CLS
#define CLS
Definition: suricata-common.h:59
PktPool_
Definition: tmqh-packetpool.h:39
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:167
PktPool_::pending_count
uint32_t pending_count
Definition: tmqh-packetpool.h:52
PacketPoolInit
void PacketPoolInit(void)
Definition: tmqh-packetpool.c:284
PktPoolLockedStack_::head
Packet * head
Definition: tmqh-packetpool.h:36
PktPoolLockedStack_
Definition: tmqh-packetpool.h:31
PktPool_::pending_head
Packet * pending_head
Definition: tmqh-packetpool.h:50
PacketPoolDestroy
void PacketPoolDestroy(void)
Definition: tmqh-packetpool.c:316
decode.h
PacketPoolPostRunmodes
void PacketPoolPostRunmodes(void)
Set the max_pending_return_packets value.
Definition: tmqh-packetpool.c:500
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
PacketPoolWaitForN
void PacketPoolWaitForN(int n)
Wait until we have the requested amount of packets in the pool.
Definition: tmqh-packetpool.c:98
Packet_
Definition: decode.h:429
PacketPoolWait
void PacketPoolWait(void)
Definition: tmqh-packetpool.c:69
PktPool_::return_stack
PktPoolLockedStack return_stack
Definition: tmqh-packetpool.h:66
PktPoolLockedStack_::SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(int, sync_now)
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:466
PacketPoolInitEmpty
void PacketPoolInitEmpty(void)
Definition: tmqh-packetpool.c:269
PktPool
struct PktPool_ PktPool
PktPool_::pending_pool
struct PktPool_ * pending_pool
Definition: tmqh-packetpool.h:49
PacketPoolReturnPacket
void PacketPoolReturnPacket(Packet *p)
Return packet to Packet pool.
Definition: tmqh-packetpool.c:207
TmqhOutputPacketpool
void TmqhOutputPacketpool(ThreadVars *, Packet *)
Definition: tmqh-packetpool.c:356
PktPool_::head
Packet * head
Definition: tmqh-packetpool.h:43
SCMutex
#define SCMutex
Definition: threads-debug.h:114
TmqhInputPacketpool
Packet * TmqhInputPacketpool(ThreadVars *)
Definition: tmqh-packetpool.c:351
PktPoolLockedStack_::mutex
SCMutex mutex
Definition: tmqh-packetpool.h:33