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 __UTIL_AFFINITY_H__
25 #define __UTIL_AFFINITY_H__
26 #include "suricata-common.h"
27 #include "conf.h"
28 
29 #if defined OS_FREEBSD
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
36 #elif defined __OpenBSD__
37 #include <sched.h>
38 #include <sys/param.h>
39 #include <sys/resource.h>
40 #elif defined OS_DARWIN
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
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
48 #endif
49 
50 enum {
56 };
57 
58 enum {
62 };
63 
64 typedef struct ThreadsAffinityType_ {
65  const char *name;
66  uint8_t mode_flag;
67  int prio;
70  uint16_t lcpu; /* use by exclusive mode */
71 
72 #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun
73  cpu_set_t cpu_set;
74  cpu_set_t lowprio_cpu;
75  cpu_set_t medprio_cpu;
76  cpu_set_t hiprio_cpu;
77 #endif
79 
80 /** store thread affinity mode for all type of threads */
81 #ifndef _THREAD_AFFINITY
83 #endif
84 
87 
89 
90 void BuildCpusetWithCallback(const char *name, ConfNode *node,
91  void (*Callback)(int i, void * data),
92  void *data);
93 
94 #endif /* __UTIL_AFFINITY_H__ */
int AffinityGetNextCPU(ThreadsAffinityType *taf)
Return next cpu to use for a given thread family.
ThreadsAffinityType * GetAffinityTypeFromName(const char *name)
find affinity by its name
Definition: util-affinity.c:68
struct ThreadsAffinityType_ ThreadsAffinityType
ThreadsAffinityType thread_affinity[MAX_CPU_SET]
Definition: util-affinity.c:34
Definition: conf.h:32
void AffinitySetupLoadFromConfig(void)
Extract cpu affinity configuration from current config file.
#define SCMutex
void BuildCpusetWithCallback(const char *name, ConfNode *node, void(*Callback)(int i, void *data), void *data)
Definition: util-affinity.c:98