suricata
threadvars.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2013 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 __THREADVARS_H__
25 #define __THREADVARS_H__
26 
27 #include "util-affinity.h"
28 #include "tm-queues.h"
29 #include "counters.h"
30 #include "threads.h"
31 
32 struct TmSlot_;
33 
34 /** Thread flags set and read by threads to control the threads */
35 #define THV_USE 1 /** thread is in use */
36 #define THV_INIT_DONE (1 << 1) /** thread initialization done */
37 #define THV_PAUSE (1 << 2) /** signal thread to pause itself */
38 #define THV_PAUSED (1 << 3) /** the thread is paused atm */
39 #define THV_KILL (1 << 4) /** thread has been asked to cleanup and exit */
40 #define THV_FAILED (1 << 5) /** thread has encountered an error and failed */
41 #define THV_CLOSED (1 << 6) /** thread done, should be joinable */
42 /* used to indicate the thread is going through de-init. Introduced as more
43  * of a hack for solving stream-timeout-shutdown. Is set by the main thread. */
44 #define THV_DEINIT (1 << 7)
45 #define THV_RUNNING_DONE (1 << 8) /** thread has completed running and is entering
46  * the de-init phase */
47 #define THV_KILL_PKTACQ (1 << 9) /**< flag thread to stop packet acq */
48 #define THV_FLOW_LOOP (1 << 10) /**< thread is in flow shutdown loop */
49 
50 /** signal thread's capture method to create a fake packet to force through
51  * the engine. This is to force timely handling of maintenance taks like
52  * rule reloads even if no packets are read by the capture method. */
53 #define THV_CAPTURE_INJECT_PKT (1<<11)
54 #define THV_DEAD (1 << 12) /**< thread has been joined with pthread_join() */
55 
56 /** \brief Per thread variable structure */
57 typedef struct ThreadVars_ {
58  pthread_t t;
59  char name[16];
62 
63  SC_ATOMIC_DECLARE(unsigned int, flags);
64 
65  /** TmModule::flags for each module part of this thread */
66  uint8_t tmm_flags;
67 
68  /** local id */
69  int id;
70 
71  /** queue's */
72  Tmq *inq;
74  void *outctx;
75  const char *outqh_name;
76 
77  /** queue handlers */
78  struct Packet_ * (*tmqh_in)(struct ThreadVars_ *);
79  void (*InShutdownHandler)(struct ThreadVars_ *);
80  void (*tmqh_out)(struct ThreadVars_ *, struct Packet_ *);
81 
82  /** slot functions */
83  void *(*tm_func)(void *);
84  struct TmSlot_ *tm_slots;
85 
86  /** stream packet queue for flow time out injection */
88 
90 
91  /** the type of thread as defined in tm-threads.h (TVT_PPT, TVT_MGMT) */
92  uint8_t type;
93 
94  uint16_t cpu_affinity; /** cpu or core number to set affinity to */
95  uint16_t rank;
96  int thread_priority; /** priority (real time) for this thread. Look at threads.h */
97 
98  /* counters */
99 
100  /** public counter store: counter syncs update this */
102 
103  /** private counter store: counter updates modify this */
105 
108 
109  uint8_t cap_flags; /**< Flags to indicate the capabilities of all the
110  TmModules resgitered under this thread */
111  struct ThreadVars_ *next;
112  struct ThreadVars_ *prev;
113 } ThreadVars;
114 
115 /** Thread setup flags: */
116 #define THREAD_SET_AFFINITY 0x01 /** CPU/Core affinity */
117 #define THREAD_SET_PRIORITY 0x02 /** Real time priority */
118 #define THREAD_SET_AFFTYPE 0x04 /** Priority and affinity */
119 
120 #endif /* __THREADVARS_H__ */
uint16_t flags
uint8_t type
Definition: threadvars.h:92
int thread_priority
Definition: threadvars.h:96
struct ThreadVars_ * prev
Definition: threadvars.h:112
StatsPrivateThreadContext perf_private_ctx
Definition: threadvars.h:104
pthread_t t
Definition: threadvars.h:58
SCCtrlCondT * ctrl_cond
Definition: threadvars.h:107
struct ThreadVars_ ThreadVars
Per thread variable structure.
uint16_t rank
Definition: threadvars.h:95
void(* InShutdownHandler)(struct ThreadVars_ *)
Definition: threadvars.h:79
char * thread_group_name
Definition: threadvars.h:61
SCCtrlMutex * ctrl_mutex
Definition: threadvars.h:106
uint8_t thread_setup_flags
Definition: threadvars.h:89
struct TmSlot_ * tm_slots
Definition: threadvars.h:84
#define SCCtrlCondT
Definition: tm-queues.h:27
struct ThreadVars_ * next
Definition: threadvars.h:111
void(* tmqh_out)(struct ThreadVars_ *, struct Packet_ *)
Definition: threadvars.h:80
#define SCCtrlMutex
Stats Context for a ThreadVars instance.
Definition: counters.h:61
Tmq * outq
Definition: threadvars.h:73
uint8_t tmm_flags
Definition: threadvars.h:66
uint16_t cpu_affinity
Definition: threadvars.h:94
StatsPublicThreadContext perf_public_ctx
Definition: threadvars.h:101
const char * outqh_name
Definition: threadvars.h:75
char * printable_name
Definition: threadvars.h:60
used to hold the private version of the counters registered
Definition: counters.h:96
void * outctx
Definition: threadvars.h:74
char name[16]
Definition: threadvars.h:59
struct PacketQueue_ * stream_pq
Definition: threadvars.h:87
Per thread variable structure.
Definition: threadvars.h:57
Tmq * inq
Definition: threadvars.h:72
uint8_t cap_flags
Definition: threadvars.h:109
SC_ATOMIC_DECLARE(unsigned int, flags)