pythonic
pythonic

Reputation: 21655

Most efficient way to share data between cores

What is the most efficient to share data between multiple cores. Sure you can use shared memory but that also comes at a cost. Say one core is continously writing to a variable and the other core has to continuously read from it. With the MESI cache coherence protocol, the writing core will cause the reading core to invalidate its cache every now and then. So in this scenario, what is the most efficient way of sharing data.

Upvotes: 4

Views: 4518

Answers (3)

Mysticial
Mysticial

Reputation: 471379

On a typical shared memory machine, the scenario that you describe is probably already the most efficient method that is possible:

  • Core A writes to memory location. Invalidates Core B's copy.
  • Core B grabs the data from memory or from Core A's cache.

Either way, the data must be sent from Core A to Core B. Cache coherency in modern processors will sometimes support direct cache-to-cache transfer without going all the way to memory.


What you want to avoid (whenever possible) is excessive locking of the shared resource. That will increase cache coherency traffic (and latency) in both directions.

Upvotes: 3

usr
usr

Reputation: 171206

This depends on how much staleness you can tolerate (please tell us).

If you require updates to propagate out as fast as possible, this is already the most efficient solution. If you can tolerate milliseconds or seconds of out-of-date data, you can use a distinct memory location for each core and synchronize using a timer.

Upvotes: 0

Shayan Pooya
Shayan Pooya

Reputation: 1089

One common and general approach is to have per-core data structures when possible.

For example, in a producer-consumer scenario, each of the consumer processors can have a part of the queue and operate on it. They can contact the producer processor only when they run out of work-items.

Of course, this is not always possible, but if the working-items can be architected this way, it reduces the inter-dependence between the cores and lets the application scale up to the number of cores.

This technique has been widely used in Solaris OS. For more info see Multicore Application Programming: for Windows, Linux, and Oracle Solaris.

Upvotes: 0

Related Questions