• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OISF / suricata / 23374838686

21 Mar 2026 07:29AM UTC coverage: 59.341% (-20.0%) from 79.315%
23374838686

Pull #15075

github

web-flow
Merge 90b4e834f into 6587e363a
Pull Request #15075: Stack 8001 v16.4

38 of 70 new or added lines in 10 files covered. (54.29%)

34165 existing lines in 563 files now uncovered.

119621 of 201584 relevant lines covered (59.34%)

650666.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/util-affinity.h
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
#include "threadvars.h"
30

31
#ifdef HAVE_HWLOC
32
#include <hwloc.h>
33
#endif /* HAVE_HWLOC */
34

35
#if defined OS_FREEBSD
36
#include <sched.h>
37
#include <sys/param.h>
38
#include <sys/resource.h>
39
#include <sys/cpuset.h>
40
#include <sys/thr.h>
41
#define cpu_set_t cpuset_t
42
#elif defined __OpenBSD__
43
#include <sched.h>
44
#include <sys/param.h>
45
#include <sys/resource.h>
46
#elif defined OS_DARWIN
47
#include <mach/mach.h>
48
#include <mach/mach_init.h>
49
#include <mach/thread_policy.h>
50
#define cpu_set_t thread_affinity_policy_data_t
51
#define CPU_SET(cpu_id, new_mask) (*(new_mask)).affinity_tag = (cpu_id + 1)
52
#define CPU_ISSET(cpu_id, new_mask) ((*(new_mask)).affinity_tag == (cpu_id + 1))
53
#define CPU_ZERO(new_mask) (*(new_mask)).affinity_tag = THREAD_AFFINITY_TAG_NULL
54
#endif
55

56
enum {
57
    RECEIVE_CPU_SET,
58
    WORKER_CPU_SET,
59
    VERDICT_CPU_SET,
60
    MANAGEMENT_CPU_SET,
61
    MAX_CPU_SET
62
};
63

64
enum {
65
    BALANCED_AFFINITY,
66
    EXCLUSIVE_AFFINITY,
67
    MAX_AFFINITY
68
};
69

UNCOV
70
#define MAX_NUMA_NODES 16
×
71

72
typedef struct ThreadsAffinityType_ {
73
    const char *name;
74
    struct ThreadsAffinityType_ **children;
75
    struct ThreadsAffinityType_ *parent; // e.g. worker-cpu-set for interfaces
76
    SCMutex taf_mutex;
77

78
#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun
79
    cpu_set_t cpu_set;
80
    cpu_set_t lowprio_cpu;
81
    cpu_set_t medprio_cpu;
82
    cpu_set_t hiprio_cpu;
83
#endif
84
    int prio;
85
    uint32_t nb_threads;
86
    uint32_t nb_children;
87
    uint32_t nb_children_capacity;
88
    uint16_t lcpu[MAX_NUMA_NODES]; /* use by exclusive mode */
89
    uint8_t mode_flag;
90
    // a flag to avoid multiple warnings when no CPU is set
91
    bool nocpu_warned;
92
} ThreadsAffinityType;
93

94
/** store thread affinity mode for all type of threads */
95
#ifndef _THREAD_AFFINITY
96
extern ThreadsAffinityType thread_affinity[MAX_CPU_SET];
97
#endif
98

99
char *AffinityGetYamlPath(ThreadsAffinityType *taf);
100
void AffinitySetupLoadFromConfig(void);
101
ThreadsAffinityType *GetOrAllocAffinityTypeForIfaceOfName(
102
        const char *name, const char *interface_name);
103
ThreadsAffinityType *GetAffinityTypeForNameAndIface(const char *name, const char *interface_name);
104
ThreadsAffinityType *FindAffinityByInterface(
105
        ThreadsAffinityType *parent, const char *interface_name);
106

107
void TopologyDestroy(void);
108
uint16_t AffinityGetNextCPU(ThreadVars *tv, ThreadsAffinityType *taf);
109
uint16_t UtilAffinityGetAffinedCPUNum(ThreadsAffinityType *taf);
110
#ifdef HAVE_DPDK
111
uint16_t UtilAffinityCpusOverlap(ThreadsAffinityType *taf1, ThreadsAffinityType *taf2);
112
void UtilAffinityCpusExclude(ThreadsAffinityType *mod_taf, ThreadsAffinityType *static_taf);
113
#endif /* HAVE_DPDK */
114

115
int BuildCpusetWithCallback(
116
        const char *name, SCConfNode *node, void (*Callback)(int i, void *data), void *data);
117

118
#ifdef UNITTESTS
119
void ThreadingAffinityRegisterTests(void);
120
#endif
121

122
#endif /* SURICATA_UTIL_AFFINITY_H */
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc