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  */
50  struct PktPool_ *pending_pool;
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__ */
#define SCMutex
Packet * PacketPoolGetPacket(void)
Get a new packet from the packet pool.
void PacketPoolReturnPacket(Packet *p)
Return packet to Packet pool.
void TmqhOutputPacketpool(ThreadVars *, Packet *)
Packet * pending_tail
#define CLS
Packet * TmqhInputPacketpool(ThreadVars *)
uint32_t pending_count
SC_ATOMIC_DECLARE(int, sync_now)
void PacketPoolInitEmpty(void)
#define SCCondT
struct PktPoolLockedStack_ __attribute__((aligned(CLS))) PktPoolLockedStack
void TmqhPacketpoolRegister(void)
TmqhPacketpoolRegister .
void PacketPoolWaitForN(int n)
Wait until we have the requested amount of packets in the pool.
void PacketPoolInit(void)
void PacketPoolDestroy(void)
Packet * pending_head
void TmqhReleasePacketsToPacketPool(PacketQueue *)
Release all the packets in the queue back to the packetpool. Mainly used by threads that have failed...
PktPoolLockedStack return_stack
struct PktPool_ PktPool
Packet * head
void PacketPoolWait(void)
Per thread variable structure.
Definition: threadvars.h:57
struct PktPool_ * pending_pool
void PacketPoolPostRunmodes(void)
Set the max_pending_return_packets value.