- Notify OS scheduler that current process have nothing to do.
- Notify OS scheduler that current process waits for data from specific other process.
What are primitives for the fastest user-space IPC?
- kotovalexarian
- Member
- Posts: 38
- Joined: Tue Nov 24, 2020 10:17 am
- Contact:
What are primitives for the fastest user-space IPC?
Hello. Let's say I want to implement the fastest user-space IPC. The obvious solution is to use shared memory. However, we need more primitives because sometimes one process can wait for data from other one. What we want is to:
Re: What are primitives for the fastest user-space IPC?
The Minix kernel solves the second requirement by simply removing the waiting process from the active tasks list, and puts it on the sender process' needs-to-be-awaken list. So when the sender process is finished with the task and wants to send a response message, the waiting process is automatically put back to the active tasks list, but not sooner. No additional API required.
Cheers,
bzt
Cheers,
bzt
Re: What are primitives for the fastest user-space IPC?
A priority inheriting pthread mutex can fulfill both requirements. Note that the second requirement is only really important in real-time contexts.
At the kernel level, all current mainstream OSes use futexes to implement this functionality (but Windows has some other options, too).
Note that in general, there is no "fastest" IPC. It depends a lot on the use case. Also note that using shared memory becomes a lot harder if processes do not trust each other and that it might be useful to have another IPC mechanism to establish the shared memory in the first place.
At the kernel level, all current mainstream OSes use futexes to implement this functionality (but Windows has some other options, too).
Note that in general, there is no "fastest" IPC. It depends a lot on the use case. Also note that using shared memory becomes a lot harder if processes do not trust each other and that it might be useful to have another IPC mechanism to establish the shared memory in the first place.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
- Schol-R-LEA
- Member
- Posts: 1925
- Joined: Fri Oct 27, 2006 9:42 am
- Location: Athens, GA, USA
Re: What are primitives for the fastest user-space IPC?
Is there a specific goal for this, or are you just trying to optimize your IPC time as tightly as possible? As Korona said, IPC timings can depend a lot on the specific use case. 'As fast as possible' isn't going to have a one-size-fits-all answer.
Also, IPC speed is rarely a limiting factor for most purposes; other aspects unrelated to the speed of the IPC mechanism are likely to be bigger concerns in a given instance. I would serious ask myself whether this is premature optimization.
Also, IPC speed is rarely a limiting factor for most purposes; other aspects unrelated to the speed of the IPC mechanism are likely to be bigger concerns in a given instance. I would serious ask myself whether this is premature optimization.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
- kotovalexarian
- Member
- Posts: 38
- Joined: Tue Nov 24, 2020 10:17 am
- Contact:
Re: What are primitives for the fastest user-space IPC?
I develop my own user-space IPC.bzt wrote:The Minix kernel solves the second requirement by simply removing the waiting process from the active tasks list, and puts it on the sender process' needs-to-be-awaken list. No additional API required.
Thank you, I'll take a look.Korona wrote:A priority inheriting pthread mutex can fulfill both requirements.
I think that it can be important, for example, for high-loaded web servers. However, I don't have benchmarks for now.Korona wrote:Note that the second requirement is only really important in real-time contexts.
Korona wrote:Note that in general, there is no "fastest" IPC. It depends a lot on the use case. Also note that using shared memory becomes a lot harder if processes do not trust each other and that it might be useful to have another IPC mechanism to establish the shared memory in the first place.
I also want to minimize syscalls for better portability.Schol-R-LEA wrote:Is there a specific goal for this, or are you just trying to optimize your IPC time as tightly as possible? As Korona said, IPC timings can depend a lot on the specific use case. 'As fast as possible' isn't going to have a one-size-fits-all answer.
Also, IPC speed is rarely a limiting factor for most purposes; other aspects unrelated to the speed of the IPC mechanism are likely to be bigger concerns in a given instance. I would serious ask myself whether this is premature optimization.