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
- on os,
- the cpu
- is thread or different process
- the load of machine
- is switch same core last ran on
- what working set size
- 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:
- save last process context 70-400 cycles,
- load new context 100-400 cycles
- 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.
- os overhead, nice statistics, example add 1 context switch counter.
- scheduling overhead, task run next
- 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
Post a Comment