user3883699
user3883699

Reputation: 13

setting the affinity causes increase in execution time

I am running a multi-threaded program (contains large number of atomic operations) with 16 threads on a 16 core machine. When I set the affinity of the threads such that each thread runs on a unique cpu, the execution time of the program increases compared to the non-affined version of the program. Using perf I can see that when the thread-core affinity is used, the cache misses increases from 10% to 30% which is probably the reason for increase in execution time. Can you please shed some light on how using the affinity can cause more cache misses?

Upvotes: 1

Views: 312

Answers (1)

UmNyobe
UmNyobe

Reputation: 22890

Can you please shed some light on how using the affinity can cause more cache misses?

Because these are CPU caches ie a set of caches of individual to each processor. For instance two thread read the same data :

  • if they are on the same core P1, T1 miss all level of cache of P1 and read in memory. Data is in the cache. T2 read and hit the cache of P1. hurray!
  • if they are on different cores P1 and P2, T1 miss all levels of cache of P1 and read in memory. Data is in the cache of P1. T2 miss all levels of cache of P2 and read in memory.

Please look at What is a cache miss

Upvotes: 2

Related Questions