debug: packet pool init/destroy validation

Validate packet pool handling:
- pools are initialized before use
- pools are not used after destroy
- pools are not double initialized/destroyed
pull/1608/head
Victor Julien 10 years ago
parent e44fd97d72
commit f871c0e1b8

@ -241,7 +241,10 @@ static void PacketPoolGetReturnedPackets(PktPool *pool)
Packet *PacketPoolGetPacket(void)
{
PktPool *pool = GetThreadPacketPool();
#ifdef DEBUG_VALIDATION
BUG_ON(pool->initialized == 0);
BUG_ON(pool->destroyed == 1);
#endif /* DEBUG_VALIDATION */
if (pool->head) {
/* Stack is not empty. */
Packet *p = pool->head;
@ -286,6 +289,12 @@ void PacketPoolReturnPacket(Packet *p)
PacketFree(p);
return;
}
#ifdef DEBUG_VALIDATION
BUG_ON(pool->initialized == 0);
BUG_ON(pool->destroyed == 1);
BUG_ON(my_pool->initialized == 0);
BUG_ON(my_pool->destroyed == 1);
#endif /* DEBUG_VALIDATION */
if (pool == my_pool) {
/* Push back onto this thread's own stack, so no locking. */
@ -338,6 +347,12 @@ void PacketPoolInitEmpty(void)
PktPool *my_pool = GetThreadPacketPool();
#ifdef DEBUG_VALIDATION
BUG_ON(my_pool->initialized);
my_pool->initialized = 1;
my_pool->destroyed = 0;
#endif /* DEBUG_VALIDATION */
SCMutexInit(&my_pool->return_stack.mutex, NULL);
SCCondInit(&my_pool->return_stack.cond, NULL);
SC_ATOMIC_INIT(my_pool->return_stack.sync_now);
@ -353,6 +368,12 @@ void PacketPoolInit(void)
PktPool *my_pool = GetThreadPacketPool();
#ifdef DEBUG_VALIDATION
BUG_ON(my_pool->initialized);
my_pool->initialized = 1;
my_pool->destroyed = 0;
#endif /* DEBUG_VALIDATION */
SCMutexInit(&my_pool->return_stack.mutex, NULL);
SCCondInit(&my_pool->return_stack.cond, NULL);
SC_ATOMIC_INIT(my_pool->return_stack.sync_now);
@ -371,12 +392,18 @@ void PacketPoolInit(void)
}
SCLogInfo("preallocated %"PRIiMAX" packets. Total memory %"PRIuMAX"",
max_pending_packets, (uintmax_t)(max_pending_packets*SIZE_OF_PACKET));
}
void PacketPoolDestroy(void)
{
Packet *p = NULL;
PktPool *my_pool = GetThreadPacketPool();
#ifdef DEBUG_VALIDATION
BUG_ON(my_pool->destroyed);
#endif /* DEBUG_VALIDATION */
if (my_pool && my_pool->pending_pool != NULL) {
p = my_pool->pending_head;
while (p) {
@ -385,7 +412,9 @@ void PacketPoolDestroy(void)
p = next_p;
my_pool->pending_count--;
}
#ifdef DEBUG_VALIDATION
BUG_ON(my_pool->pending_count);
#endif /* DEBUG_VALIDATION */
my_pool->pending_pool = NULL;
my_pool->pending_head = NULL;
my_pool->pending_tail = NULL;
@ -396,6 +425,11 @@ void PacketPoolDestroy(void)
}
SC_ATOMIC_DESTROY(my_pool->return_stack.sync_now);
#ifdef DEBUG_VALIDATION
my_pool->initialized = 0;
my_pool->destroyed = 1;
#endif /* DEBUG_VALIDATION */
}
Packet *TmqhInputPacketpool(ThreadVars *tv)

@ -38,7 +38,7 @@ typedef struct PktPoolLockedStack_{
} __attribute__((aligned(CLS))) PktPoolLockedStack;
typedef struct PktPool_ {
/* link listed of free packets local to this thread.
/* link listed of free packets local to this thread.
* No mutex is needed.
*/
Packet *head;
@ -51,8 +51,13 @@ typedef struct PktPool_ {
Packet *pending_head;
Packet *pending_tail;
uint32_t pending_count;
/* All members above this point are accessed locally by only one thread, so
#ifdef DEBUG_VALIDATION
int initialized;
int destroyed;
#endif /* DEBUG_VALIDATION */
/* All members above this point are accessed locally by only one thread, so
* these should live on their own cache line.
*/
@ -60,7 +65,6 @@ typedef struct PktPool_ {
* to this thread.
*/
PktPoolLockedStack return_stack;
} PktPool;
Packet *TmqhInputPacketpool(ThreadVars *);

Loading…
Cancel
Save