suricata
util-affinity.h
Go to the documentation of this file.
1 /* Copyright (C) 2010 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 Eric Leblond <eric@regit.org>
22  */
23 
24 #ifndef SURICATA_UTIL_AFFINITY_H
25 #define SURICATA_UTIL_AFFINITY_H
26 #include "suricata-common.h"
27 #include "conf.h"
28 #include "threads.h"
29 
30 #if defined OS_FREEBSD
31 #include <sched.h>
32 #include <sys/param.h>
33 #include <sys/resource.h>
34 #include <sys/cpuset.h>
35 #include <sys/thr.h>
36 #define cpu_set_t cpuset_t
37 #elif defined __OpenBSD__
38 #include <sched.h>
39 #include <sys/param.h>
40 #include <sys/resource.h>
41 #elif defined OS_DARWIN
42 #include <mach/mach.h>
43 #include <mach/mach_init.h>
44 #include <mach/thread_policy.h>
45 #define cpu_set_t thread_affinity_policy_data_t
46 #define CPU_SET(cpu_id, new_mask) (*(new_mask)).affinity_tag = (cpu_id + 1)
47 #define CPU_ISSET(cpu_id, new_mask) ((*(new_mask)).affinity_tag == (cpu_id + 1))
48 #define CPU_ZERO(new_mask) (*(new_mask)).affinity_tag = THREAD_AFFINITY_TAG_NULL
49 #endif
50 
51 enum {
57 };
58 
59 enum {
63 };
64 
65 typedef struct ThreadsAffinityType_ {
66  const char *name;
67  uint8_t mode_flag;
68  uint16_t lcpu; /* use by exclusive mode */
69  int prio;
70  uint32_t nb_threads;
72 
73 #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun
74  cpu_set_t cpu_set;
75  cpu_set_t lowprio_cpu;
76  cpu_set_t medprio_cpu;
77  cpu_set_t hiprio_cpu;
78 #endif
80 
81 /** store thread affinity mode for all type of threads */
82 #ifndef _THREAD_AFFINITY
84 #endif
85 
88 
91 #ifdef HAVE_DPDK
92 uint16_t UtilAffinityCpusOverlap(ThreadsAffinityType *taf1, ThreadsAffinityType *taf2);
93 void UtilAffinityCpusExclude(ThreadsAffinityType *mod_taf, ThreadsAffinityType *static_taf);
94 #endif /* HAVE_DPDK */
95 
96 void BuildCpusetWithCallback(const char *name, ConfNode *node,
97  void (*Callback)(int i, void * data),
98  void *data);
99 
100 #endif /* SURICATA_UTIL_AFFINITY_H */
ThreadsAffinityType_::medprio_cpu
cpu_set_t medprio_cpu
Definition: util-affinity.h:76
ThreadsAffinityType_::nb_threads
uint32_t nb_threads
Definition: util-affinity.h:70
ThreadsAffinityType_::lcpu
uint16_t lcpu
Definition: util-affinity.h:68
UtilAffinityGetAffinedCPUNum
uint16_t UtilAffinityGetAffinedCPUNum(ThreadsAffinityType *taf)
Definition: util-affinity.c:309
EXCLUSIVE_AFFINITY
@ EXCLUSIVE_AFFINITY
Definition: util-affinity.h:61
RECEIVE_CPU_SET
@ RECEIVE_CPU_SET
Definition: util-affinity.h:52
MANAGEMENT_CPU_SET
@ MANAGEMENT_CPU_SET
Definition: util-affinity.h:55
MAX_CPU_SET
@ MAX_CPU_SET
Definition: util-affinity.h:56
AffinityGetNextCPU
uint16_t AffinityGetNextCPU(ThreadsAffinityType *taf)
Return next cpu to use for a given thread family.
Definition: util-affinity.c:282
MAX_AFFINITY
@ MAX_AFFINITY
Definition: util-affinity.h:62
ThreadsAffinityType_::lowprio_cpu
cpu_set_t lowprio_cpu
Definition: util-affinity.h:75
threads.h
ThreadsAffinityType
struct ThreadsAffinityType_ ThreadsAffinityType
VERDICT_CPU_SET
@ VERDICT_CPU_SET
Definition: util-affinity.h:54
BALANCED_AFFINITY
@ BALANCED_AFFINITY
Definition: util-affinity.h:60
ThreadsAffinityType_::hiprio_cpu
cpu_set_t hiprio_cpu
Definition: util-affinity.h:77
thread_affinity
ThreadsAffinityType thread_affinity[MAX_CPU_SET]
Definition: util-affinity.c:34
GetAffinityTypeFromName
ThreadsAffinityType * GetAffinityTypeFromName(const char *name)
find affinity by its name
Definition: util-affinity.c:68
conf.h
ThreadsAffinityType_::cpu_set
cpu_set_t cpu_set
Definition: util-affinity.h:74
ThreadsAffinityType_::mode_flag
uint8_t mode_flag
Definition: util-affinity.h:67
ThreadsAffinityType_::name
const char * name
Definition: util-affinity.h:66
suricata-common.h
ThreadsAffinityType_
Definition: util-affinity.h:65
BuildCpusetWithCallback
void BuildCpusetWithCallback(const char *name, ConfNode *node, void(*Callback)(int i, void *data), void *data)
Definition: util-affinity.c:97
ConfNode_
Definition: conf.h:32
AffinitySetupLoadFromConfig
void AffinitySetupLoadFromConfig(void)
Extract cpu affinity configuration from current config file.
Definition: util-affinity.c:164
ThreadsAffinityType_::taf_mutex
SCMutex taf_mutex
Definition: util-affinity.h:71
WORKER_CPU_SET
@ WORKER_CPU_SET
Definition: util-affinity.h:53
ThreadsAffinityType_::prio
int prio
Definition: util-affinity.h:69
SCMutex
#define SCMutex
Definition: threads-debug.h:114