From: Victor Julien Date: Wed, 18 Mar 2015 10:24:26 +0000 (+0100) Subject: flow queue handler: use int16_t X-Git-Tag: suricata-3.1RC1~172 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be714a2f0218ad501a86f0a3b7dd029cccd9bc39;p=thirdparty%2Fsuricata.git flow queue handler: use int16_t Use int16_t instead of int to store the autofp queue id. We should not easily get to 32k threads so 2 bytes per flow is sufficient. --- diff --git a/src/stream-tcp.c b/src/stream-tcp.c index 875a9d6f3e..b83d45c336 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -4907,7 +4907,7 @@ static void TcpSessionReuseHandle(Packet *p) { /* get some settings that we move over to the new flow */ FlowThreadId thread_id = old_f->thread_id; - int autofp_tmqh_flow_qid = SC_ATOMIC_GET(old_f->autofp_tmqh_flow_qid); + int16_t autofp_tmqh_flow_qid = SC_ATOMIC_GET(old_f->autofp_tmqh_flow_qid); /* disconnect the packet from the old flow */ FlowHandlePacketUpdateRemove(p->flow, p); diff --git a/src/tmqh-flow.c b/src/tmqh-flow.c index 29b8a6ad98..5a6b40c9f5 100644 --- a/src/tmqh-flow.c +++ b/src/tmqh-flow.c @@ -289,13 +289,12 @@ void TmqhOutputFlowActivePackets(ThreadVars *tv, Packet *p) TmqhFlowCtx *ctx = (TmqhFlowCtx *)tv->outctx; - /* if no flow we use the first queue, - * should be rare */ + /* if no flow we round robin the packets over the queues */ if (p->flow != NULL) { qid = SC_ATOMIC_GET(p->flow->autofp_tmqh_flow_qid); if (qid == -1) { - uint16_t i = 0; - int lowest_id = 0; + int16_t i = 0; + int16_t lowest_id = 0; TmqhFlowMode *queues = ctx->queues; uint32_t lowest = queues[i].q->len; for (i = 1; i < ctx->size; i++) { @@ -350,7 +349,7 @@ void TmqhOutputFlowHash(ThreadVars *tv, Packet *p) addr >>= 7; /* we don't have to worry about possible overflow, since - * ctx->size will be lesser than 2 ** 31 for sure */ + * ctx->size will be less than 2 ** 15 for sure */ qid = addr % ctx->size; (void) SC_ATOMIC_SET(p->flow->autofp_tmqh_flow_qid, qid); (void) SC_ATOMIC_ADD(ctx->queues[qid].total_flows, 1); diff --git a/src/tmqh-flow.h b/src/tmqh-flow.h index 1206a05c13..e710ffeca4 100644 --- a/src/tmqh-flow.h +++ b/src/tmqh-flow.h @@ -39,7 +39,7 @@ typedef struct TmqhFlowCtx_ { TmqhFlowMode *queues; - SC_ATOMIC_DECLARE(uint16_t, round_robin_idx); + SC_ATOMIC_DECLARE(int16_t, round_robin_idx); } TmqhFlowCtx; void TmqhFlowRegister (void);