suricata
util-affinity.c File Reference
#include "suricata-common.h"
#include "suricata.h"
#include "util-affinity.h"
#include "conf.h"
#include "conf-yaml-loader.h"
#include "runmodes.h"
#include "util-cpu.h"
#include "util-byte.h"
#include "util-debug.h"
#include "util-dpdk.h"
#include "util-unittest.h"
Include dependency graph for util-affinity.c:

Go to the source code of this file.

Macros

#define _THREAD_AFFINITY
 

Functions

ThreadsAffinityTypeFindAffinityByInterface (ThreadsAffinityType *parent, const char *interface_name)
 
ThreadsAffinityTypeGetAffinityTypeForNameAndIface (const char *name, const char *interface_name)
 Find affinity by name (*-cpu-set name) and an interface name. More...
 
ThreadsAffinityTypeGetOrAllocAffinityTypeForIfaceOfName (const char *name, const char *interface_name)
 Finds affinity by its name and interface name. Interfaces are children of cpu-set names. If the queried interface is not found, then it is allocated, initialized and assigned to the queried cpu-set. More...
 
int BuildCpusetWithCallback (const char *name, SCConfNode *node, void(*Callback)(int i, void *data), void *data)
 
char * AffinityGetYamlPath (ThreadsAffinityType *taf)
 Get the YAML path for the given affinity type. The path is built using the parent name (if available) and the affinity name. Do not free the returned string. More...
 
void AffinitySetupLoadFromConfig (void)
 Extract CPU affinity configuration from current config file. More...
 
uint16_t AffinityGetNextCPU (ThreadVars *tv, ThreadsAffinityType *taf)
 
uint16_t UtilAffinityGetAffinedCPUNum (ThreadsAffinityType *taf)
 Return the total number of CPUs in a given affinity. More...
 
void ThreadingAffinityRegisterTests (void)
 Register all threading affinity unit tests. More...
 

Variables

ThreadsAffinityType thread_affinity [MAX_CPU_SET]
 
int thread_affinity_init_done = 0
 

Detailed Description

Author
Eric Leblond eric@.nosp@m.regi.nosp@m.t.org

CPU affinity related code and helper.

Definition in file util-affinity.c.

Macro Definition Documentation

◆ _THREAD_AFFINITY

#define _THREAD_AFFINITY

Definition at line 28 of file util-affinity.c.

Function Documentation

◆ AffinityGetNextCPU()

uint16_t AffinityGetNextCPU ( ThreadVars tv,
ThreadsAffinityType taf 
)

Definition at line 1006 of file util-affinity.c.

◆ AffinityGetYamlPath()

char* AffinityGetYamlPath ( ThreadsAffinityType taf)

Get the YAML path for the given affinity type. The path is built using the parent name (if available) and the affinity name. Do not free the returned string.

Parameters
tafthe affinity type - if NULL, the path is built for the root node
Returns
a string containing the YAML path, or NULL if the path is too long

Definition at line 429 of file util-affinity.c.

References ThreadsAffinityType_::name, ThreadsAffinityType_::parent, and SCLogError.

◆ AffinitySetupLoadFromConfig()

void AffinitySetupLoadFromConfig ( void  )

Extract CPU affinity configuration from current config file.

Definition at line 588 of file util-affinity.c.

References thread_affinity_init_done.

Referenced by RunModeInitializeThreadSettings().

Here is the caller graph for this function:

◆ BuildCpusetWithCallback()

int BuildCpusetWithCallback ( const char *  name,
SCConfNode node,
void(*)(int i, void *data)  Callback,
void *  data 
)

Definition at line 227 of file util-affinity.c.

References name, next, SCLogError, StringParseUint32(), TAILQ_FOREACH, UtilCpuGetNumProcessorsOnline(), and SCConfNode_::val.

Here is the call graph for this function:

◆ FindAffinityByInterface()

ThreadsAffinityType* FindAffinityByInterface ( ThreadsAffinityType parent,
const char *  interface_name 
)

Definition at line 113 of file util-affinity.c.

References ThreadsAffinityType_::children, ThreadsAffinityType_::name, and ThreadsAffinityType_::nb_children.

Referenced by GetAffinityTypeForNameAndIface(), and GetOrAllocAffinityTypeForIfaceOfName().

Here is the caller graph for this function:

◆ GetAffinityTypeForNameAndIface()

ThreadsAffinityType* GetAffinityTypeForNameAndIface ( const char *  name,
const char *  interface_name 
)

Find affinity by name (*-cpu-set name) and an interface name.

Parameters
namethe name of the affinity (e.g. worker-cpu-set, receive-cpu-set). The name is required and cannot be NULL.
interface_namethe name of the interface. If NULL, the affinity is looked up by name only.
Return values
apointer to the affinity or NULL if not found

Definition at line 138 of file util-affinity.c.

References FindAffinityByInterface(), MAX_CPU_SET, name, SCLogError, and thread_affinity.

Referenced by LiveGetDeviceCountWithoutAssignedThreading().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetOrAllocAffinityTypeForIfaceOfName()

ThreadsAffinityType* GetOrAllocAffinityTypeForIfaceOfName ( const char *  name,
const char *  interface_name 
)

Finds affinity by its name and interface name. Interfaces are children of cpu-set names. If the queried interface is not found, then it is allocated, initialized and assigned to the queried cpu-set.

Parameters
namethe name of the affinity (e.g. worker-cpu-set, receive-cpu-set). The name is required and cannot be NULL.
interface_namethe name of the interface. If NULL, the affinity is looked up by name only.
Return values
apointer to the affinity or NULL if not found

Definition at line 177 of file util-affinity.c.

References FindAffinityByInterface(), MAX_CPU_SET, name, SCLogError, and thread_affinity.

Here is the call graph for this function:

◆ ThreadingAffinityRegisterTests()

void ThreadingAffinityRegisterTests ( void  )

Register all threading affinity unit tests.

Definition at line 1992 of file util-affinity.c.

References UtRegisterTest().

Here is the call graph for this function:

◆ UtilAffinityGetAffinedCPUNum()

uint16_t UtilAffinityGetAffinedCPUNum ( ThreadsAffinityType taf)

Return the total number of CPUs in a given affinity.

Return values
thenumber of affined CPUs

Definition at line 1043 of file util-affinity.c.

References ThreadsAffinityType_::cpu_set, SCMutexLock, SCMutexUnlock, ThreadsAffinityType_::taf_mutex, and UtilCpuGetNumProcessorsOnline().

Here is the call graph for this function:

Variable Documentation

◆ thread_affinity

ThreadsAffinityType thread_affinity[MAX_CPU_SET]
Initial value:
= {
{
.name = "receive-cpu-set",
.mode_flag = EXCLUSIVE_AFFINITY,
.prio = PRIO_MEDIUM,
.lcpu = { 0 },
},
{
.name = "worker-cpu-set",
.mode_flag = EXCLUSIVE_AFFINITY,
.prio = PRIO_MEDIUM,
.lcpu = { 0 },
},
{
.name = "verdict-cpu-set",
.mode_flag = BALANCED_AFFINITY,
.prio = PRIO_MEDIUM,
.lcpu = { 0 },
},
{
.name = "management-cpu-set",
.mode_flag = BALANCED_AFFINITY,
.prio = PRIO_MEDIUM,
.lcpu = { 0 },
},
}

store thread affinity mode for all type of threads

Definition at line 38 of file util-affinity.c.

Referenced by GetAffinityTypeForNameAndIface(), GetOrAllocAffinityTypeForIfaceOfName(), and TmThreadGetNbThreads().

◆ thread_affinity_init_done

int thread_affinity_init_done = 0

Definition at line 66 of file util-affinity.c.

Referenced by AffinitySetupLoadFromConfig().

BALANCED_AFFINITY
@ BALANCED_AFFINITY
Definition: util-affinity.h:65
PRIO_MEDIUM
@ PRIO_MEDIUM
Definition: threads.h:89
EXCLUSIVE_AFFINITY
@ EXCLUSIVE_AFFINITY
Definition: util-affinity.h:66