suricata
util-affinity.h File Reference
#include "suricata-common.h"
#include "conf.h"
#include "threads.h"
#include "threadvars.h"
Include dependency graph for util-affinity.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ThreadsAffinityType_
 

Macros

#define MAX_NUMA_NODES   16
 

Typedefs

typedef struct ThreadsAffinityType_ ThreadsAffinityType
 

Enumerations

enum  {
  RECEIVE_CPU_SET, WORKER_CPU_SET, VERDICT_CPU_SET, MANAGEMENT_CPU_SET,
  MAX_CPU_SET
}
 
enum  { BALANCED_AFFINITY, EXCLUSIVE_AFFINITY, MAX_AFFINITY }
 

Functions

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...
 
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...
 
ThreadsAffinityTypeGetAffinityTypeForNameAndIface (const char *name, const char *interface_name)
 Find affinity by name (*-cpu-set name) and an interface name. More...
 
ThreadsAffinityTypeFindAffinityByInterface (ThreadsAffinityType *parent, const char *interface_name)
 
void TopologyDestroy (void)
 
uint16_t AffinityGetNextCPU (ThreadVars *tv, ThreadsAffinityType *taf)
 
uint16_t UtilAffinityGetAffinedCPUNum (ThreadsAffinityType *taf)
 Return the total number of CPUs in a given affinity. More...
 
int BuildCpusetWithCallback (const char *name, SCConfNode *node, void(*Callback)(int i, void *data), void *data)
 
void ThreadingAffinityRegisterTests (void)
 Register all threading affinity unit tests. More...
 

Variables

ThreadsAffinityType thread_affinity [MAX_CPU_SET]
 

Detailed Description

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

Definition in file util-affinity.h.

Macro Definition Documentation

◆ MAX_NUMA_NODES

#define MAX_NUMA_NODES   16

Definition at line 71 of file util-affinity.h.

Typedef Documentation

◆ ThreadsAffinityType

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
RECEIVE_CPU_SET 
WORKER_CPU_SET 
VERDICT_CPU_SET 
MANAGEMENT_CPU_SET 
MAX_CPU_SET 

Definition at line 56 of file util-affinity.h.

◆ anonymous enum

anonymous enum
Enumerator
BALANCED_AFFINITY 
EXCLUSIVE_AFFINITY 
MAX_AFFINITY 

Definition at line 64 of file util-affinity.h.

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:

◆ TopologyDestroy()

void TopologyDestroy ( void  )

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

store thread affinity mode for all type of threads

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

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