News for hackers. Stuff that matters.
Re:On Cache Invalidation: Why Is It Hard? (2018) by stcredzero on Monday April 05, 2021 @12:10AM (#26695270)
On the multi-core systems of today, why are we using memory and the cache as a communication device between threads running on different cores? Don't we have the spare transistors and space on the die to implement purpose-built communication hardware between cpu cores which does not fall victim to false sharing, and the like? Isn't the current setup a bit hacky?
Re:On Cache Invalidation: Why Is It Hard? (2018) by toast0 on Monday April 05, 2021 @02:01AM (#26695778)
Almost all communications between devices is memory mapped i/o these days. x86 has i/o ports, but that's mostly used for devices that were specified long ago (although some things are still relevant).

If there was a core to core bulk messaging system, it would be memory mapped as well, and you'd need to store the messages in some sort of memory, so why add a specialized message queue, when you can just use memory?

You can do things like add a message to a mailbox in memory, and then send an interrupt to the other processor to indicate it's ready.

Re:On Cache Invalidation: Why Is It Hard? (2018) by stcredzero on Monday April 05, 2021 @11:04AM (#26699972)
If there was a core to core bulk messaging system, it would be memory mapped as well, and you'd need to store the messages in some sort of memory, so why add a specialized message queue, when you can just use memory?

So one could code inter-thread communication without having to think about inducing large numbers of cache misses and degrading performance.

Re:On Cache Invalidation: Why Is It Hard? (2018) by ironman1478 on Monday April 05, 2021 @12:55AM (#26695489)
I think there are some embedded platforms that used message passing as a primary form of communication. However those are really out there and not at all mainstream. I think what you're talking about is coming. For example, for ARM there is a network on chip architecture that I could see being used as a back bone for this type of system. However, you need software support for it. It's not enough to just build the hardware.
Re:On Cache Invalidation: Why Is It Hard? (2018) by YZF on Monday April 05, 2021 @12:26AM (#26695353)
I think this is primarily about backwards compatibility. New CPUs, especially from Intel, were about running existing software faster. The shared memory paradigm goes back to single core (and mainframes) and is pervasive, in code, in languages, in libraries. It's really hard to rewrite all the software on this planet to use some channel mechanism between cores and that also makes it tricky when the OS needs to schedule threads. I think there were some historical examples of this sort of architecture (Transputers?) and generally they didn't fare that well...

If you made a new CPU where there's no shared memory between cores I'm not quite sure who would use it. It's also not that clear how much simpler it makes things on the chip and for the developers.

Re:On Cache Invalidation: Why Is It Hard? (2018) by jandrese on Monday April 05, 2021 @01:19AM (#26695595)
I think you have to choose between easy and fast in this case. A separate dedicated memory controller that all of the cores are connected to that handles all of the cache would make this problem a lot easier, but would defeat the purpose of the L1 cache.
Re:On Cache Invalidation: Why Is It Hard? (2018) by gizmo686 on Monday April 05, 2021 @01:35AM (#26695658)
The question is, why are we dealing with cross-core cache invalidation at all. When core A writes to memory location X, then core B reads from memory location X, why do we insist that core B reads what core A wrote? Almost by definition, the only reason to make such a requirement is that we want to use main memory as a mechanism to communicate between cores.

An alternative architecture would be to say that different cores should not be using the same region of memory. If they attempt to do so, it is an error and exactly what happens is undefined. We only need to worry about cache invalidation when we transfer ownership of a region of memory between cores.

If we had a non memory method of cross core communication, we would need to pass memory between cores far less often, which would greatly simplyfy the problem of memory cache invaldiation.

Re:On Cache Invalidation: Why Is It Hard? (2018) by pjc50 on Monday April 05, 2021 @05:27AM (#26696926)
> When core A writes to memory location X, then core B reads from memory location X, why do we insist that core B reads what core A wrote?

Because that's what the Intel programmer's model of memory specifies. This is not necessarily true on ARM: https://community.arm.com/developer/ip-products/processors/b...

> different cores should not be using the same region of memory

Generally known as "NUMA"; this is a viable programmer's model, but it's different from what people are used to, and requires either software changes or a lot of performance-impacting compatibility layers when software accesses pre-existing global variables.

(You could certainly get NUMA multiprocessing systems back in the day - to make effective use you had to pin processes to cores, because the cost of migrating memory about was considerable otherwise)

Re:On Cache Invalidation: Why Is It Hard? (2018) by yuliyp on Monday April 05, 2021 @03:47AM (#26696337)
> the only reason to make such a requirement is that we want to use main memory as a mechanism to communicate between cores.

For a very liberal definition of "communicate" that statement is true. The only reason for multiple threads to be sharing an address space is if they mutually depend on how the others are interacting with the data in there.

The reason for cross-core cache invalidation is that otherwise it becomes impossible to reason about behavior of any data structures written and read by different threads. Imagine trying to build multiple consumer queue without any cache coherence protocols.

Re:On Cache Invalidation: Why Is It Hard? (2018) by saagarjha on Monday April 05, 2021 @04:59AM (#26696764)
> When core A writes to memory location X, then core B reads from memory location X, why do we insist that core B reads what core A wrote?

Well, on many platforms we don't necessarily require this to be true immediately.

Re:On Cache Invalidation: Why Is It Hard? (2018) by throwaway3699 on Monday April 05, 2021 @12:37AM (#26695399)
I'd argue the classic memory model is much easier to model in a developer's mind than the alternative.
Re:On Cache Invalidation: Why Is It Hard? (2018) by layoutIfNeeded on Monday April 05, 2021 @06:58AM (#26697451)
The Cell Broadband Engine in PlayStation 3 had this kind of message-passing communication between the main PPC core and the SPE cores.
Re:On Cache Invalidation: Why Is It Hard? (2018) by dTal on Monday April 05, 2021 @06:45AM (#26697358)
Is this not exactly what AMD's "infinity fabric' does?
Re:On Cache Invalidation: Why Is It Hard? (2018) by LogicUpgrade on Monday April 05, 2021 @08:19AM (#26698033)
The current system is a bit hacky, but we just have no languages that crystalize the use case clearly enough for this to happen at the hardware level.

Were we all programming in Erlang, Rust and Go, maybe we'd see hardware follow.