4

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()

hlovdal
  • 26,565
  • 10
  • 94
  • 165
osgx
  • 90,338
  • 53
  • 357
  • 513

1 Answers1

4

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

user209051
  • 309
  • 2
  • 8