From: Victor Julien Date: Tue, 12 Nov 2019 13:54:55 +0000 (+0100) Subject: packet-queue: introduce a non-locked version X-Git-Tag: suricata-6.0.0-beta1~786 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8c2b66d333c0816ec4f7e2bc1b38a44019fedbf;p=thirdparty%2Fsuricata.git packet-queue: introduce a non-locked version Works exactly like PacketQueue, just does not contain a mutex and cond var, leading to much reduced memory size. --- diff --git a/src/decode.h b/src/decode.h index c31b83792a..a15c193c86 100644 --- a/src/decode.h +++ b/src/decode.h @@ -618,6 +618,26 @@ extern int g_default_mtu; uint32_t default_packet_size; #define SIZE_OF_PACKET (default_packet_size + sizeof(Packet)) +/** \brief simple fifo queue for packets + * + * \note PacketQueueNoLock and PacketQueue need to keep identical + * layouts except for the mutex_q and cond_q fields. + */ +typedef struct PacketQueueNoLock_ { + Packet *top; + Packet *bot; + uint32_t len; +#ifdef DBG_PERF + uint32_t dbg_maxlen; +#endif /* DBG_PERF */ +} PacketQueueNoLock; + +/** \brief simple fifo queue for packets with mutex and cond + * Calling the mutex or triggering the cond is responsibility of the caller + * + * \note PacketQueueNoLock and PacketQueue need to keep identical + * layouts except for the mutex_q and cond_q fields. + */ typedef struct PacketQueue_ { Packet *top; Packet *bot; diff --git a/src/packet-queue.c b/src/packet-queue.c index 9f5bf43090..ef4e434cad 100644 --- a/src/packet-queue.c +++ b/src/packet-queue.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2010 Open Information Security Foundation +/* Copyright (C) 2007-2019 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -136,7 +136,7 @@ void PacketQueueValidate(PacketQueue *q) } #endif /* DEBUG */ -void PacketEnqueue (PacketQueue *q, Packet *p) +static inline void PacketEnqueueDo(PacketQueue *q, Packet *p) { //PacketQueueValidateDebug(q); @@ -164,25 +164,28 @@ void PacketEnqueue (PacketQueue *q, Packet *p) //PacketQueueValidateDebug(q); } -Packet *PacketDequeue (PacketQueue *q) +void PacketEnqueueNoLock(PacketQueueNoLock *qnl, Packet *p) +{ + PacketQueue *q = (PacketQueue *)qnl; + PacketEnqueueDo(q, p); +} + +void PacketEnqueue (PacketQueue *q, Packet *p) { - Packet *p = NULL; + PacketEnqueueDo(q, p); +} +static inline Packet *PacketDequeueDo (PacketQueue *q) +{ //PacketQueueValidateDebug(q); /* if the queue is empty there are no packets left. */ if (q->len == 0) { return NULL; } - q->len--; /* pull the bottom packet from the queue */ - p = q->bot; - - /* Weird issue: sometimes it looks that two thread arrive - * here at the same time so the bot ptr is NULL (only on OS X?) - */ - BUG_ON (p == NULL); + Packet *p = q->bot; /* more packets in queue */ if (q->bot->prev != NULL) { @@ -200,3 +203,13 @@ Packet *PacketDequeue (PacketQueue *q) return p; } +Packet *PacketDequeueNoLock (PacketQueueNoLock *qnl) +{ + PacketQueue *q = (PacketQueue *)qnl; + return PacketDequeueDo(q); +} + +Packet *PacketDequeue (PacketQueue *q) +{ + return PacketDequeueDo(q); +} diff --git a/src/packet-queue.h b/src/packet-queue.h index b93a942b6a..77a0d87ef2 100644 --- a/src/packet-queue.h +++ b/src/packet-queue.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2010 Open Information Security Foundation +/* Copyright (C) 2007-2019 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -27,7 +27,10 @@ #include "threads.h" #include "decode.h" +void PacketEnqueueNoLock(PacketQueueNoLock *qnl, Packet *p); void PacketEnqueue (PacketQueue *, Packet *); + +Packet *PacketDequeueNoLock (PacketQueueNoLock *qnl); Packet *PacketDequeue (PacketQueue *); #endif /* __PACKET_QUEUE_H__ */