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 #include "util-atomic.h"
30 
31  /* Return stack, onto which other threads free packets. */
32 typedef struct PktPoolLockedStack_{
33  /* linked list of free packets. */
36  SC_ATOMIC_DECLARE(int, sync_now);
38 } __attribute__((aligned(CLS))) PktPoolLockedStack;
39 
40 typedef struct PktPool_ {
41  /* link listed of free packets local to this thread.
42  * No mutex is needed.
43  */
45  /* Packets waiting (pending) to be returned to the given Packet
46  * Pool. Accumulate packets for the same pool until a theshold is
47  * reached, then return them all at once. Keep the head and tail
48  * to fast insertion of the entire list onto a return stack.
49  */
53  uint32_t pending_count;
54 
55 #ifdef DEBUG_VALIDATION
56  int initialized;
57  int destroyed;
58 #endif /* DEBUG_VALIDATION */
59 
60  /* All members above this point are accessed locally by only one thread, so
61  * these should live on their own cache line.
62  */
63 
64  /* Return stack, where other threads put packets that they free that belong
65  * to this thread.
66  */
67  PktPoolLockedStack return_stack;
68 } PktPool;
69 
73 void TmqhPacketpoolRegister(void);
75 void PacketPoolWait(void);
76 void PacketPoolWaitForN(int n);
78 void PacketPoolInit(void);
79 void PacketPoolInitEmpty(void);
80 void PacketPoolDestroy(void);
81 void PacketPoolPostRunmodes(void);
82 
83 #endif /* __TMQH_PACKETPOOL_H__ */
PktPool_::pending_tail
Packet * pending_tail
Definition: tmqh-packetpool.h:52
TmqhPacketpoolRegister
void TmqhPacketpoolRegister(void)
TmqhPacketpoolRegister \initonly.
Definition: tmqh-packetpool.c:132
CLS
#define CLS
Definition: suricata-common.h:45
PktPool_
Definition: tmqh-packetpool.h:40
PacketQueue_
simple fifo queue for packets with mutex and cond Calling the mutex or triggering the cond is respons...
Definition: packet-queue.h:47
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:249
PktPool_::pending_count
uint32_t pending_count
Definition: tmqh-packetpool.h:53
PacketPoolInit
void PacketPoolInit(void)
Definition: tmqh-packetpool.c:370
PktPoolLockedStack_::head
Packet * head
Definition: tmqh-packetpool.h:37
PktPoolLockedStack_
Definition: tmqh-packetpool.h:32
PktPool_::pending_head
Packet * pending_head
Definition: tmqh-packetpool.h:51
PacketPoolDestroy
void PacketPoolDestroy(void)
Definition: tmqh-packetpool.c:407
decode.h
PacketPoolPostRunmodes
void PacketPoolPostRunmodes(void)
Set the max_pending_return_packets value.
Definition: tmqh-packetpool.c:586
PktPoolLockedStack_::cond
SCCondT cond
Definition: tmqh-packetpool.h:35
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
__attribute__
struct PktPoolLockedStack_ __attribute__((aligned(CLS))) PktPoolLockedStack
util-atomic.h
PacketPoolWaitForN
void PacketPoolWaitForN(int n)
Wait until we have the requested amount of packets in the pool.
Definition: tmqh-packetpool.c:177
Packet_
Definition: decode.h:408
PacketPoolWait
void PacketPoolWait(void)
Definition: tmqh-packetpool.c:148
PktPool_::return_stack
PktPoolLockedStack return_stack
Definition: tmqh-packetpool.h:67
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:554
PacketPoolInitEmpty
void PacketPoolInitEmpty(void)
Definition: tmqh-packetpool.c:351
PktPool
struct PktPool_ PktPool
PktPool_::pending_pool
struct PktPool_ * pending_pool
Definition: tmqh-packetpool.h:50
PacketPoolReturnPacket
void PacketPoolReturnPacket(Packet *p)
Return packet to Packet pool.
Definition: tmqh-packetpool.c:289
TmqhOutputPacketpool
void TmqhOutputPacketpool(ThreadVars *, Packet *)
Definition: tmqh-packetpool.c:449
PktPool_::head
Packet * head
Definition: tmqh-packetpool.h:44
SCMutex
#define SCMutex
Definition: threads-debug.h:114
TmqhInputPacketpool
Packet * TmqhInputPacketpool(ThreadVars *)
Definition: tmqh-packetpool.c:444
PktPoolLockedStack_::mutex
SCMutex mutex
Definition: tmqh-packetpool.h:34