Message passing on P2
Seairth
Posts: 2,474
in Propeller 2
I think the best idea would be to run multiple Lua instances, one per cog, and provide a library that allows for message passing between them.
This merits its own thread. Of course, you've mentioned the need for message passing elsewhere. And this is definitely something the P2 should handle well. So the question here is: what options do we have right now?
Hub
Like the P1, we can do Hub slots/mailboxes. Also like the P1, there's a penalty for random access timing. Unlike the P1, we can use SETQ to more efficiently transfer large messages. You can also have a queue, which then provides the ability to asynchronously send messages. Because the Hub is a shared resource, it is possible for multiple cogs to interact with the same message(s), either intentionally or unintentionally.
Locks
Like the P1, we can do locks as flags. Also like the P1, these are slow hub operations. Unlike the P1, there are 16 instead of 8. Also, unlike the P1, cogs can efficiently INT/WAIT/POLL them via selectable events. Unlike Hub, these are limited to flags/events (1-bit messages), and cannot be used asynchronously (for the purpose of "message passing").
Shared LUT
For paired cogs, we can do message passing using the LUT. This can be treated similarly to Hub message passing, but without the overhead cost. Further, if the messages can fit into a single LONG, you can effectively use selectable events to INT/WAIT/POLL for messages. Share LUT also has the added advantage that they are protected from being read or modified by other cogs. However, there is less overall space for messages, as compared to Hub messaging. And, you are limited to communicating with your paired cog.
ATN
The new ATN functionality also provides a simple form of messaging. Since ATN can be detected by INT/WAIT/POLL, this can be effectively used by itself, or in combination with Hub or Shared LUT messaging. On their own, ATN has similar limitations as Locks, but without the overhead cost.
Smart Pins
You can even use the smart pins! In this case, each pin can store a LONG. You can then use INT/WAIT/POLL and read them. The advantage of using these over hub is that they are fast. The advantage of using these over Shared LUT is that you can pass messages to any cog, or even multiple cogs. With 64 smart pins, it will be increasingly likely that you will have some unused smarts that could be repurposed for messaging. However, this is still a limited resource that is not available if the Smart Pin is otherwise in use.
So... is there any other way that I've missed?
Comments
No mention in documentation though...
(note: One minor exception will be the Shared LUT where a shared library specifically makes use of paired cogs.)
They are basically the same as on the P1, except:
* 16 instead of 8.
* You can used SE1-SE4 to INT/WAIT/POLL on them.
In order for this to work effectively, I think you'd want a "standard" messaging scheme. Then, each language would add library support for that scheme. In all likelihood, with the current options, this can only be done using Hub messaging.
(Like I mention above, this will likely reinforce the use of Hub as the de facto messaging resource, leaving the other options underutilized.)
But what killed it was not the non-agreement of how to use it... It was scuttled by those who didn't want it!
RossH (Catalina C for P1) eventually went alone with Catalina and interfaces quite well with both spin and pasm cogs.
I went alone with my Prop OS. It decouples the standard input and standard output, such that the driver cogs can be substituted, even on the fly if you require although I have not done this.
I fear that to get such agreement, and importantly to get everyone to use it, is all but impossible. As we have seen before.
Unless that is, the message passing mechanism were baked into the actual hardware. Like channels are on XMOS devices and the old Transputer before it.
It's far too late now to be thinking of a harware solution.
Perhaps if the idea were baked into the Spin language for the P2 it would set a precedent and get some traction. I would not bank on it though.
https://en.wikipedia.org/wiki/Remote_procedure_call
-Phil
RPC mechanisms and formats like XML, JSON, etc are some levels of abstraction higher up than I was thinking.
At some basic level the first thing we need is a common, reliable and fast way to move bytes between parallel processes.
But, that's a good point. If we had such a channel/pipe mechanism in place very soon everybody would design their own mechanisms and formats on top of it and we would be back to chaos again.
It's hopeless...
Unless, as I said, such channels/pipes were baked into hardware. Then that would be a standard nobody could avoid