Mutex or futex delay measurement

How can I measure the delay of a mutex, semaphore or futex? I mean the delay between two events: unlock a previously locked mutex and lock this mutex. There are two cases: when all threads / processes are on the same processor (how long will it take to redistribute the thread), and when the first thread is on the first CPU, and the second on the second.

Thread1: Lock(Mutex) Critical1 Unlock(Mutex)|<------->| Thread2: while{trylock} |Lock(Mutex) Critical2 Unlock(Mutex)| 

Or even

 Thread1: work..work..very hard..work... sem_post()|<----->| Thread2: sem_wait(semaphore)...............................|sem_wait unlocks here work2.. 

This time is very short (~ 1 k cycles), so I cannot use gettimeofday()

+4
source share
1 answer

You can use high resolution timers. clock_gettime with CLOCK_MONOTONIC_HR (I know this is more than a year, but still someone might have the same question)

+3
source

Source: https://habr.com/ru/post/1305230/


All Articles