suricata
threads-profile.h File Reference
#include "util-cpu.h"
Include dependency graph for threads-profile.h:

Go to the source code of this file.

Data Structures

struct  ProfilingLock_
 

Macros

#define PROFILING_MAX_LOCKS   64
 
#define SCMutexLock_profile(mut)
 
#define SCMutex   pthread_mutex_t
 
#define SCMutexAttr   pthread_mutexattr_t
 
#define SCMutexInit(mut, mutattr)   pthread_mutex_init(mut, mutattr)
 
#define SCMutexLock(mut)   SCMutexLock_profile(mut)
 
#define SCMutexTrylock(mut)   pthread_mutex_trylock(mut)
 
#define SCMutexUnlock(mut)   pthread_mutex_unlock(mut)
 
#define SCMutexDestroy   pthread_mutex_destroy
 
#define SCMUTEX_INITIALIZER   PTHREAD_MUTEX_INITIALIZER
 
#define SCCondT   pthread_cond_t
 
#define SCCondInit   pthread_cond_init
 
#define SCCondSignal   pthread_cond_signal
 
#define SCCondDestroy   pthread_cond_destroy
 
#define SCCondWait(cond, mut)   pthread_cond_wait(cond, mut)
 
#define SCSpinLock_profile(spin)
 
#define SCSpinlock   pthread_spinlock_t
 
#define SCSpinLock(mut)   SCSpinLock_profile(mut)
 
#define SCSpinTrylock(spin)   pthread_spin_trylock(spin)
 
#define SCSpinUnlock(spin)   pthread_spin_unlock(spin)
 
#define SCSpinInit(spin, spin_attr)   pthread_spin_init(spin, spin_attr)
 
#define SCSpinDestroy(spin)   pthread_spin_destroy(spin)
 
#define SCRWLockWRLock_profile(mut)
 
#define SCRWLockRDLock_profile(mut)
 
#define SCRWLock   pthread_rwlock_t
 
#define SCRWLockInit(rwl, rwlattr)   pthread_rwlock_init(rwl, rwlattr)
 
#define SCRWLockWRLock(mut)   SCRWLockWRLock_profile(mut)
 
#define SCRWLockRDLock(mut)   SCRWLockRDLock_profile(mut)
 
#define SCRWLockTryWRLock(rwl)   pthread_rwlock_trywrlock(rwl)
 
#define SCRWLockTryRDLock(rwl)   pthread_rwlock_tryrdlock(rwl)
 
#define SCRWLockUnlock(rwl)   pthread_rwlock_unlock(rwl)
 
#define SCRWLockDestroy   pthread_rwlock_destroy
 
#define SCCtrlMutex   pthread_mutex_t
 
#define SCCtrlMutexAttr   pthread_mutexattr_t
 
#define SCCtrlMutexInit(mut, mutattr)   pthread_mutex_init(mut, mutattr)
 
#define SCCtrlMutexLock(mut)   pthread_mutex_lock(mut)
 
#define SCCtrlMutexTrylock(mut)   pthread_mutex_trylock(mut)
 
#define SCCtrlMutexUnlock(mut)   pthread_mutex_unlock(mut)
 
#define SCCtrlMutexDestroy   pthread_mutex_destroy
 
#define SCCtrlCondT   pthread_cond_t
 
#define SCCtrlCondInit   pthread_cond_init
 
#define SCCtrlCondSignal   pthread_cond_signal
 
#define SCCtrlCondTimedwait   pthread_cond_timedwait
 
#define SCCtrlCondWait   pthread_cond_wait
 
#define SCCtrlCondDestroy   pthread_cond_destroy
 

Typedefs

typedef struct ProfilingLock_ ProfilingLock
 

Enumerations

enum  { LOCK_MUTEX, LOCK_SPIN, LOCK_RWW, LOCK_RWR }
 

Variables

thread_local ProfilingLock locks [PROFILING_MAX_LOCKS]
 
thread_local int locks_idx
 
thread_local int record_locks
 
thread_local uint64_t mutex_lock_contention
 
thread_local uint64_t mutex_lock_wait_ticks
 
thread_local uint64_t mutex_lock_cnt
 
thread_local uint64_t spin_lock_contention
 
thread_local uint64_t spin_lock_wait_ticks
 
thread_local uint64_t spin_lock_cnt
 
thread_local uint64_t rww_lock_contention
 
thread_local uint64_t rww_lock_wait_ticks
 
thread_local uint64_t rww_lock_cnt
 
thread_local uint64_t rwr_lock_contention
 
thread_local uint64_t rwr_lock_wait_ticks
 
thread_local uint64_t rwr_lock_cnt
 

Detailed Description

Author
Victor Julien victo.nosp@m.r@in.nosp@m.linia.nosp@m.c.ne.nosp@m.t

Lock profiling wrappers

Definition in file threads-profile.h.

Macro Definition Documentation

◆ PROFILING_MAX_LOCKS

#define PROFILING_MAX_LOCKS   64

Definition at line 33 of file threads-profile.h.

◆ SCCondDestroy

#define SCCondDestroy   pthread_cond_destroy

Definition at line 103 of file threads-profile.h.

◆ SCCondInit

#define SCCondInit   pthread_cond_init

Definition at line 101 of file threads-profile.h.

◆ SCCondSignal

#define SCCondSignal   pthread_cond_signal

Definition at line 102 of file threads-profile.h.

◆ SCCondT

#define SCCondT   pthread_cond_t

Definition at line 100 of file threads-profile.h.

◆ SCCondWait

#define SCCondWait (   cond,
  mut 
)    pthread_cond_wait(cond, mut)

Definition at line 104 of file threads-profile.h.

◆ SCCtrlCondDestroy

#define SCCtrlCondDestroy   pthread_cond_destroy

Definition at line 229 of file threads-profile.h.

◆ SCCtrlCondInit

#define SCCtrlCondInit   pthread_cond_init

Definition at line 225 of file threads-profile.h.

◆ SCCtrlCondSignal

#define SCCtrlCondSignal   pthread_cond_signal

Definition at line 226 of file threads-profile.h.

◆ SCCtrlCondT

#define SCCtrlCondT   pthread_cond_t

Definition at line 224 of file threads-profile.h.

◆ SCCtrlCondTimedwait

#define SCCtrlCondTimedwait   pthread_cond_timedwait

Definition at line 227 of file threads-profile.h.

◆ SCCtrlCondWait

#define SCCtrlCondWait   pthread_cond_wait

Definition at line 228 of file threads-profile.h.

◆ SCCtrlMutex

#define SCCtrlMutex   pthread_mutex_t

Definition at line 215 of file threads-profile.h.

◆ SCCtrlMutexAttr

#define SCCtrlMutexAttr   pthread_mutexattr_t

Definition at line 216 of file threads-profile.h.

◆ SCCtrlMutexDestroy

#define SCCtrlMutexDestroy   pthread_mutex_destroy

Definition at line 221 of file threads-profile.h.

◆ SCCtrlMutexInit

#define SCCtrlMutexInit (   mut,
  mutattr 
)    pthread_mutex_init(mut, mutattr)

Definition at line 217 of file threads-profile.h.

◆ SCCtrlMutexLock

#define SCCtrlMutexLock (   mut)    pthread_mutex_lock(mut)

Definition at line 218 of file threads-profile.h.

◆ SCCtrlMutexTrylock

#define SCCtrlMutexTrylock (   mut)    pthread_mutex_trylock(mut)

Definition at line 219 of file threads-profile.h.

◆ SCCtrlMutexUnlock

#define SCCtrlMutexUnlock (   mut)    pthread_mutex_unlock(mut)

Definition at line 220 of file threads-profile.h.

◆ SCMutex

#define SCMutex   pthread_mutex_t

Definition at line 89 of file threads-profile.h.

◆ SCMUTEX_INITIALIZER

#define SCMUTEX_INITIALIZER   PTHREAD_MUTEX_INITIALIZER

Definition at line 96 of file threads-profile.h.

◆ SCMutexAttr

#define SCMutexAttr   pthread_mutexattr_t

Definition at line 90 of file threads-profile.h.

◆ SCMutexDestroy

#define SCMutexDestroy   pthread_mutex_destroy

Definition at line 95 of file threads-profile.h.

◆ SCMutexInit

#define SCMutexInit (   mut,
  mutattr 
)    pthread_mutex_init(mut, mutattr)

Definition at line 91 of file threads-profile.h.

◆ SCMutexLock

#define SCMutexLock (   mut)    SCMutexLock_profile(mut)

Definition at line 92 of file threads-profile.h.

◆ SCMutexLock_profile

#define SCMutexLock_profile (   mut)
Value:
({ \
mutex_lock_cnt++; \
int retl = 0; \
int cont = 0; \
uint64_t mutex_lock_start = UtilCpuGetTicks(); \
if (pthread_mutex_trylock((mut)) != 0) { \
mutex_lock_contention++; \
cont = 1; \
retl = pthread_mutex_lock(mut); \
} \
uint64_t mutex_lock_end = UtilCpuGetTicks(); \
mutex_lock_wait_ticks += (uint64_t)(mutex_lock_end - mutex_lock_start); \
\
locks[locks_idx].file = (char *)__FILE__; \
locks[locks_idx].func = (char *)__func__; \
locks[locks_idx].line = (int)__LINE__; \
locks[locks_idx].type = LOCK_MUTEX; \
locks[locks_idx].cont = cont; \
locks[locks_idx].ticks = (uint64_t)(mutex_lock_end - mutex_lock_start); \
locks_idx++; \
} \
retl; \
})

Definition at line 64 of file threads-profile.h.

◆ SCMutexTrylock

#define SCMutexTrylock (   mut)    pthread_mutex_trylock(mut)

Definition at line 93 of file threads-profile.h.

◆ SCMutexUnlock

#define SCMutexUnlock (   mut)    pthread_mutex_unlock(mut)

Definition at line 94 of file threads-profile.h.

◆ SCRWLock

#define SCRWLock   pthread_rwlock_t

Definition at line 205 of file threads-profile.h.

◆ SCRWLockDestroy

#define SCRWLockDestroy   pthread_rwlock_destroy

Definition at line 212 of file threads-profile.h.

◆ SCRWLockInit

#define SCRWLockInit (   rwl,
  rwlattr 
)    pthread_rwlock_init(rwl, rwlattr)

Definition at line 206 of file threads-profile.h.

◆ SCRWLockRDLock

#define SCRWLockRDLock (   mut)    SCRWLockRDLock_profile(mut)

Definition at line 208 of file threads-profile.h.

◆ SCRWLockRDLock_profile

#define SCRWLockRDLock_profile (   mut)
Value:
({ \
rwr_lock_cnt++; \
int retl = 0; \
int cont = 0; \
uint64_t rwr_lock_start = UtilCpuGetTicks(); \
if (pthread_rwlock_tryrdlock((mut)) != 0) { \
rwr_lock_contention++; \
cont = 1; \
retl = pthread_rwlock_rdlock(mut); \
} \
uint64_t rwr_lock_end = UtilCpuGetTicks(); \
rwr_lock_wait_ticks += (uint64_t)(rwr_lock_end - rwr_lock_start); \
\
locks[locks_idx].file = (char *)__FILE__; \
locks[locks_idx].func = (char *)__func__; \
locks[locks_idx].line = (int)__LINE__; \
locks[locks_idx].type = LOCK_RWR; \
locks[locks_idx].cont = cont; \
locks[locks_idx].ticks = (uint64_t)(rwr_lock_end - rwr_lock_start); \
locks_idx++; \
} \
retl; \
})

Definition at line 180 of file threads-profile.h.

◆ SCRWLockTryRDLock

#define SCRWLockTryRDLock (   rwl)    pthread_rwlock_tryrdlock(rwl)

Definition at line 210 of file threads-profile.h.

◆ SCRWLockTryWRLock

#define SCRWLockTryWRLock (   rwl)    pthread_rwlock_trywrlock(rwl)

Definition at line 209 of file threads-profile.h.

◆ SCRWLockUnlock

#define SCRWLockUnlock (   rwl)    pthread_rwlock_unlock(rwl)

Definition at line 211 of file threads-profile.h.

◆ SCRWLockWRLock

#define SCRWLockWRLock (   mut)    SCRWLockWRLock_profile(mut)

Definition at line 207 of file threads-profile.h.

◆ SCRWLockWRLock_profile

#define SCRWLockWRLock_profile (   mut)
Value:
({ \
rww_lock_cnt++; \
int retl = 0; \
int cont = 0; \
uint64_t rww_lock_start = UtilCpuGetTicks(); \
if (pthread_rwlock_trywrlock((mut)) != 0) { \
rww_lock_contention++; \
cont = 1; \
retl = pthread_rwlock_wrlock(mut); \
} \
uint64_t rww_lock_end = UtilCpuGetTicks(); \
rww_lock_wait_ticks += (uint64_t)(rww_lock_end - rww_lock_start); \
\
locks[locks_idx].file = (char *)__FILE__; \
locks[locks_idx].func = (char *)__func__; \
locks[locks_idx].line = (int)__LINE__; \
locks[locks_idx].type = LOCK_RWW; \
locks[locks_idx].cont = cont; \
locks[locks_idx].ticks = (uint64_t)(rww_lock_end - rww_lock_start); \
locks_idx++; \
} \
retl; \
})

Definition at line 151 of file threads-profile.h.

◆ SCSpinDestroy

#define SCSpinDestroy (   spin)    pthread_spin_destroy(spin)

Definition at line 143 of file threads-profile.h.

◆ SCSpinInit

#define SCSpinInit (   spin,
  spin_attr 
)    pthread_spin_init(spin, spin_attr)

Definition at line 142 of file threads-profile.h.

◆ SCSpinlock

#define SCSpinlock   pthread_spinlock_t

Definition at line 138 of file threads-profile.h.

◆ SCSpinLock

#define SCSpinLock (   mut)    SCSpinLock_profile(mut)

Definition at line 139 of file threads-profile.h.

◆ SCSpinLock_profile

#define SCSpinLock_profile (   spin)
Value:
({ \
spin_lock_cnt++; \
int retl = 0; \
int cont = 0; \
uint64_t spin_lock_start = UtilCpuGetTicks(); \
if (pthread_spin_trylock((spin)) != 0) { \
spin_lock_contention++; \
cont = 1; \
retl = pthread_spin_lock((spin)); \
} \
uint64_t spin_lock_end = UtilCpuGetTicks(); \
spin_lock_wait_ticks += (uint64_t)(spin_lock_end - spin_lock_start); \
\
locks[locks_idx].file = (char *)__FILE__; \
locks[locks_idx].func = (char *)__func__; \
locks[locks_idx].line = (int)__LINE__; \
locks[locks_idx].type = LOCK_SPIN; \
locks[locks_idx].cont = cont; \
locks[locks_idx].ticks = (uint64_t)(spin_lock_end - spin_lock_start); \
locks_idx++; \
} \
retl; \
})

Definition at line 113 of file threads-profile.h.

◆ SCSpinTrylock

#define SCSpinTrylock (   spin)    pthread_spin_trylock(spin)

Definition at line 140 of file threads-profile.h.

◆ SCSpinUnlock

#define SCSpinUnlock (   spin)    pthread_spin_unlock(spin)

Definition at line 141 of file threads-profile.h.

Typedef Documentation

◆ ProfilingLock

typedef struct ProfilingLock_ ProfilingLock

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
LOCK_MUTEX 
LOCK_SPIN 
LOCK_RWW 

rwlock, writer

LOCK_RWR 

rwlock, reader

Definition at line 36 of file threads-profile.h.

Variable Documentation

◆ locks

thread_local ProfilingLock locks[PROFILING_MAX_LOCKS]

◆ locks_idx

thread_local int locks_idx

◆ mutex_lock_cnt

thread_local uint64_t mutex_lock_cnt

◆ mutex_lock_contention

thread_local uint64_t mutex_lock_contention

◆ mutex_lock_wait_ticks

thread_local uint64_t mutex_lock_wait_ticks

◆ record_locks

thread_local int record_locks

◆ rwr_lock_cnt

thread_local uint64_t rwr_lock_cnt

◆ rwr_lock_contention

thread_local uint64_t rwr_lock_contention

◆ rwr_lock_wait_ticks

thread_local uint64_t rwr_lock_wait_ticks

◆ rww_lock_cnt

thread_local uint64_t rww_lock_cnt

◆ rww_lock_contention

thread_local uint64_t rww_lock_contention

◆ rww_lock_wait_ticks

thread_local uint64_t rww_lock_wait_ticks

◆ spin_lock_cnt

thread_local uint64_t spin_lock_cnt

◆ spin_lock_contention

thread_local uint64_t spin_lock_contention

◆ spin_lock_wait_ticks

thread_local uint64_t spin_lock_wait_ticks
record_locks
thread_local int record_locks
LOCK_RWW
@ LOCK_RWW
Definition: threads-profile.h:39
LOCK_SPIN
@ LOCK_SPIN
Definition: threads-profile.h:38
UtilCpuGetTicks
uint64_t UtilCpuGetTicks(void)
Definition: util-cpu.c:161
locks_idx
thread_local int locks_idx
PROFILING_MAX_LOCKS
#define PROFILING_MAX_LOCKS
Definition: threads-profile.h:32
LOCK_MUTEX
@ LOCK_MUTEX
Definition: threads-profile.h:37
LOCK_RWR
@ LOCK_RWR
Definition: threads-profile.h:40