tags:

views:

68

answers:

0

Hello

How could I measure a latency of mutex, semaphore or futex? I mean the latency between two events: unlock previously locked mutex and the locking that mutex. There are two cases: when all threads/processes are on the same CPU (how long will it take to reschedule thread) and when first thread is on the first CPU and second is on 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 can't use gettimeofday()