Unified Shared Memory Systems

时间:2015-07-28 16:06:54

标签: c linux ipc shared-memory rtai

I am working with some older real-time control system code written using the RTAI extensions to Linux. I see four different mechanisms in use to create and share memory across process boundaries.

1) RTAI shared memory (rt_shm_alloc & rt_shm_free): This uses an unsigned long globally unique value as a key for accessing the shared memory. Behind the scenes (from user space at least) it uses an ioctl on a character device to generate the memory then mmap to make it available.

2) System V (ftok, shmget, shmat, shmctl, etc): This uses ftok to generate a key that is used, along with an index value, to find and map a block of memory. I've not tried to see how this is actually implemented, but I'm assuming that somewhere behind the curtain it is using mmap.

3) Posix shared memory (shm_open, mmap, shm_unlink, etc): This takes a string (with some restrictions on content) and provides a file handle which can be used to mmap the linked block of memory. This seems to be supported using a virtual filesystem.

4) direct use of mmap and character driver ioctl calls Certain kernel modules provide an interface which directly supports using mmap to create and shared a block of memory.

All of these mechanisms seem to use mmap either explicitly or implicitly to alter the virtual memory subsystem to setup and manage the shared memory.

The question is: If a block of memory is shared using one of these systems, is there any way to setup an alias that will access the same memory in the other systems.

A use case:

I have two I/O subsystems. The first is implemented using linux kernel driver and exports it's current I/O state in one chunk of shared memory created using the RTAI shared memory mechanism. The second is based on the etherlab ethercat master which uses a custom kernel module and directly uses ioctl and mmap to create a shared memory block.

I have 40 or so other systems which need access to certain I/O fields, but don't really need to know which I/O subsystem the data came from.

What I want is a way to open and access the different types of shared memory in a single coherent way, isolating the underlying implementation details from the users. Does such a mechanism exist?

I have altered the ethercat stack to use the RTAI shared memory mechanism to solve this instance, but that's just a temporary solution (Read: hack).

0 个答案:

没有答案