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.
 
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.
 
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.
 
void AffinitySetupLoadFromConfig (void)
 Extract CPU affinity configuration from current config file.
 
uint16_t AffinityGetNextCPU (ThreadVars *tv, ThreadsAffinityType *taf)
 
uint16_t UtilAffinityGetAffinedCPUNum (ThreadsAffinityType *taf)
 Return the total number of CPUs in a given affinity.
 
void ThreadingAffinityRegisterTests (void)
 Register all threading affinity unit tests.
 

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 27 of file util-affinity.c.

Function Documentation

◆ AffinityGetNextCPU()

uint16_t AffinityGetNextCPU ( ThreadVars tv,
ThreadsAffinityType taf 
)

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

References SCLogDebug, SCLogError, SCLogWarning, SCMutexLock, SCMutexUnlock, ThreadsAffinityType_::taf_mutex, and tv.

Referenced by TmThreadSetupOptions().

Here is the caller graph for this function:

◆ 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.

Referenced by AffinitySetupLoadFromConfig(), and TmThreadSetupOptions().

Here is the caller graph for this function:

◆ AffinitySetupLoadFromConfig()

void AffinitySetupLoadFromConfig ( void  )

Extract CPU affinity configuration from current config file.

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

References AffinityGetYamlPath(), GetOrAllocAffinityTypeForIfaceOfName(), SCConfNode_::name, next, SCConfGetNode(), SCLogConfig, SCLogDebug, SCLogError, SCLogInfo, TAILQ_FOREACH, thread_affinity_init_done, and SCConfNode_::val.

Referenced by RunModeInitializeThreadSettings().

Here is the call graph for this function:
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 
)

◆ 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.

Referenced by AffinitySetupLoadFromConfig().

Here is the call graph for this function:
Here is the caller 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().

Referenced by TmThreadSetupOptions().

Here is the call graph for this function:
Here is the caller 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 },
},
}
@ PRIO_MEDIUM
Definition threads.h:89
@ EXCLUSIVE_AFFINITY
@ BALANCED_AFFINITY

store thread affinity mode for all type of threads

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

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

◆ thread_affinity_init_done

int thread_affinity_init_done = 0

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

Referenced by AffinitySetupLoadFromConfig().