(Insert
about badly designed multi-recipient software message buses here. Please use point-to-point messaging, or implement your event bus using point-to-point message passing. Hardware stuff is completely different matter, of course.)
Do you think you could elaborate on the issues of a general pub/sub event bus for event + object passing?
TL;DR: Publisher-subscriber buses are trivial to DDOS or jam. As an analogue, consider what happens if a chip pulls I2C SDA down "forever".
If your implementation does not cross privilege separation boundaries, and you trust each communicator, there are no issues.
If your implementation crosses privilege separation boundaries, but you trust all senders, and you limit message lifetime (allowing for some recipients sometimes missing messages), there are no issues.
It is when your implementation crosses privilege separation boundaries, and you have untrusted senders and receivers, that you get into very, very careful design and implementation domain. You mentioned userspace application, and this is the part that gives me the heebie-jeebies.
Or is your RTOS okay completely crashing if an userspace program does not check its pending events/messages often enough?
From past implementations, we know that a "supervisor" cannot heuristically detect spamming and jamming from rapid valid messaging and valid CPU stalling due to overload. That is, there is no difference between a buggy or malicious sender sending lots of messages, and a valid situation where lots of messages are generated. There also is no difference between a receiver that leaves messages unread (or worse, partially received) because it wants to stall the bus, or is simply starved of CPU time due to something even more important. Priority inversion has been suggested as a solution for the latter case, but I haven't seen a single acceptable implementation yet; in particular, PI just makes it easier for a buggy or malicious participant to jam or spam the bus.
The known working patterns are implemented on top of point-to-point links. (For example, consider IP multicasting, and POSIX signaling to a process group.) If the typical message size is large, you can reduce memory use by deduplicating and reference-counting the data, so that each recipient basically has a set of message pointers – but unfortunately you'll see that metadata maintenance (especially message expiry due to a stalled recipient) becomes complicated, or your per-recipient-per-message data structures grow larger than typical messages. Instead, copying smallish messages to each recipient's own receive buffer, turns out to be more efficient. Especially if you track resource ownership, the point-to-point approach works best.
I have not yet seen an implementation where the message bus was implemented as a subscriber-publisher model inside the privileged/trusted section (kernel), with a scatter-gather "arbitrator" on the userspace boundary so userspace would only have point-to-point messaging, and only kernel-internal messages use the pub-sub event bus. I
think it might work. This matches IP multicast model, does not require much state per userspace client on the arbitrator, and trivially allows the kernel side to work even when the userspace side is stalled (with userspace only losing messages); it allows you to implement privilege separation properly, without too much state tracking. Unfortunately, it is nontrivial, and I haven't implemented it myself, so at this point, consider it a theoretical possibility.
I am also not convinced that the OSI (or TCP/IP) layer model is the best one for the software implementation itself. That is, that your software needs to implement the layers. You of course need to implement their functionality; I am just saying their structure is only one option.
For example, consider a model where each event or message is split into three separate parts: headers, payload data, and errors/state changes. Headers contain routing information across all OSI layers. Only the application layer and the data link and physical layers are interested in the payload data – data link layer only when headers contain a checksum of the payload data; and the physical layer because the data needs to be transmitted physically. Everything in between is only interested in the headers and errors and state changes, so why pass the payload data at all? Also, for firewalls and routers, the header information needs to be separately
mutable, both adding or removing optional fields. (This is especially important with VLAN support.)
A typical TCP/IPv4 header is 40 bytes (without options), and TCP/IPv6 60 bytes (also without options). Errors are rare, but state changes relatively common, from connection handshaking to closing. While small packets are relatively common, a
typical packet has about 1500 bytes of payload. Splitting the logical "event" into the parts that matter, definitely affects how much data you shuffle around.
As to interchip communication, I have been assuming here that they all have full memory access, because I'm a software person, and only a hobbyist wrt. hardware implementation details. (This is why I wrote "software message buses".) In that case, it becomes a multiprocessing or distributed processing software problem, with some rather "interesting" cache behaviour real-world issues (in that either you consider cache behaviour, or your implementation will be slow). And those I do claim to know about some.
Obviously, others will disagree with what I've written here; that is to be expected. I am only pointing out problems and issues I see repeated time and time again. The CS in me would *love* to see a robust pub-sub message bus implementation that magically didn't have any resource management or privilege separation issues.. but the software engineer side reminds me of the myriad of (security or resource management) problems every one I've seen have thus far had, and that while point-to-point links are "dull" and "uninteresting" and "a chore" to implement, they just have much fewer of those problems, and in a form that is much easier to deal with.