c++ - How much time it takes for a thread waiting with pthread_cond_wait to wake after being signaled? how can I estimate this time? -


i'm writing c++ threadpool implantation , using pthread_cond_wait in worker's main function. wondering how time pass signaling condition variable until thread/threads waiting on wake up. have idea of how can estimate/calculate time?

thank much.

it depends, on cost of context switch

  1. on os,
  2. the cpu
  3. is thread or different process
  4. the load of machine
  5. is switch same core last ran on
  6. what working set size
  7. time since last ran

linux best case, i7, 1100ns, thread in same process, same core ran in last, ran last thread, no load, working set 1 byte.

bad case, flushed cache, different core, different process, expect 30µs of cpu overhead.

where cost go:

  1. save last process context 70-400 cycles,
  2. load new context 100-400 cycles
  3. if different process, flush tlb, reload 3 5 page walks, potentially memory taking ~300 cycles each. plus few page walks if more 1 page touched, including instructions , data.
  4. os overhead, nice statistics, example add 1 context switch counter.
  5. scheduling overhead, task run next
  6. potential cache misses on new core ~12 cycles per cache line on own l2 cache, , downhill there farther away data , more there of it.

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -