]>
Commit | Line | Data |
---|---|---|
37ee483b EL |
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 __UTIL_AFFINITY_H__ | |
25 | #define __UTIL_AFFINITY_H__ | |
26 | #include "suricata-common.h" | |
ac5957d4 | 27 | #include "conf.h" |
37ee483b | 28 | |
4e923126 | 29 | #if defined OS_FREEBSD |
a2465ffc VJ |
30 | #include <sched.h> |
31 | #include <sys/param.h> | |
32 | #include <sys/resource.h> | |
33 | #include <sys/cpuset.h> | |
34 | #include <sys/thr.h> | |
35 | #define cpu_set_t cpuset_t | |
4e923126 EL |
36 | #elif defined __OpenBSD__ |
37 | #include <sched.h> | |
38 | #include <sys/param.h> | |
39 | #include <sys/resource.h> | |
40 | #elif defined OS_DARWIN | |
a2465ffc VJ |
41 | #include <mach/mach.h> |
42 | #include <mach/mach_init.h> | |
43 | #include <mach/thread_policy.h> | |
44 | #define cpu_set_t thread_affinity_policy_data_t | |
35c168ab PR |
45 | #define CPU_SET(cpu_id, new_mask) (*(new_mask)).affinity_tag = (cpu_id + 1) |
46 | #define CPU_ISSET(cpu_id, new_mask) ((*(new_mask)).affinity_tag == (cpu_id + 1)) | |
47 | #define CPU_ZERO(new_mask) (*(new_mask)).affinity_tag = THREAD_AFFINITY_TAG_NULL | |
a2465ffc VJ |
48 | #endif |
49 | ||
37ee483b EL |
50 | enum { |
51 | RECEIVE_CPU_SET, | |
5f9de1e7 | 52 | WORKER_CPU_SET, |
37ee483b | 53 | VERDICT_CPU_SET, |
ea566d66 | 54 | MANAGEMENT_CPU_SET, |
37ee483b EL |
55 | MAX_CPU_SET |
56 | }; | |
57 | ||
58 | enum { | |
59 | BALANCED_AFFINITY, | |
60 | EXCLUSIVE_AFFINITY, | |
61 | MAX_AFFINITY | |
62 | }; | |
63 | ||
64 | typedef struct ThreadsAffinityType_ { | |
bdc2c6e9 | 65 | const char *name; |
37ee483b | 66 | uint8_t mode_flag; |
0b5e5b87 | 67 | int prio; |
271e33fb | 68 | uint32_t nb_threads; |
bdc2c6e9 VJ |
69 | SCMutex taf_mutex; |
70 | uint16_t lcpu; /* use by exclusive mode */ | |
71 | ||
120f5938 | 72 | #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun |
bdc2c6e9 | 73 | cpu_set_t cpu_set; |
789d46cc EL |
74 | cpu_set_t lowprio_cpu; |
75 | cpu_set_t medprio_cpu; | |
76 | cpu_set_t hiprio_cpu; | |
4e923126 | 77 | #endif |
37ee483b EL |
78 | } ThreadsAffinityType; |
79 | ||
80 | /** store thread affinity mode for all type of threads */ | |
81 | #ifndef _THREAD_AFFINITY | |
bb8298ff | 82 | extern ThreadsAffinityType thread_affinity[MAX_CPU_SET]; |
37ee483b EL |
83 | #endif |
84 | ||
ab1200fb | 85 | void AffinitySetupLoadFromConfig(void); |
37ee483b EL |
86 | ThreadsAffinityType * GetAffinityTypeFromName(const char *name); |
87 | ||
88 | int AffinityGetNextCPU(ThreadsAffinityType *taf); | |
89 | ||
ac5957d4 EL |
90 | void BuildCpusetWithCallback(const char *name, ConfNode *node, |
91 | void (*Callback)(int i, void * data), | |
92 | void *data); | |
93 | ||
37ee483b | 94 | #endif /* __UTIL_AFFINITY_H__ */ |