Jump to content

How to use shm(shared_memory) region for TLM memory block(simple memory with DMI, LT)


Recommended Posts

I need use a shared memory region(Posix shared memory) for TLM2's memory block in my ISS model, i.e. the TLM2 memory block will be a mmap-ed shared memory region, is this possible? 

I want an external normal(non-systemc) Linux process to dump the shared memory content, even write to it(with semaphore protection) while running the model.

Link to comment
Share on other sites

5 hours ago, David Black said:

Been there and done it many years ago. Requires deep knowledge of host OS mutexes (std::mutex), std::condition_variable, use of sc_core::async_request() and optionally Linux signals in a custom primitive channel. Used it when modeling a video application. 

Sounds complex indeed, so I will simplify it a bit: the external non-systemc process will just preload some data to shm region, sc_main will assign the shm region ptr to TLM payload's data pointer, when sc_main completes the external process can check what's left in the shared memory, this likely avoids mutex|async_request|condition_variable|etc. In my use case the non-systemc process does not really need peek/poke the shared memory region while sc_main is running, it just preloads some data to the memory block, let sc_main work on it, then dump it after sc_main is done.

Does that make sense?

Link to comment
Share on other sites

In any case you need some way of syncronisation except you run the systemc as a child process of your external process. After attaching to the shared memory using shmat() or mmap() e.g. in the constructor of your memory you can use it like any other character array. The only additional action is to detach/unmap from the shared memory e.g. in the destructor.

Unfortunately the C++ primitives do not help that much for syncronization as they work only for threads not processes. You would need to use POSIX semaphores. A good introduction how this can be done can be found here: https://opensource.com/article/19/4/interprocess-communication-linux-storage#shared-memory

 

Link to comment
Share on other sites

36 minutes ago, Eyck said:

In any case you need some way of syncronisation except you run the systemc as a child process of your external process. After attaching to the shared memory using shmat() or mmap() e.g. in the constructor of your memory you can use it like any other character array. The only additional action is to detach/unmap from the shared memory e.g. in the destructor.

Unfortunately the C++ primitives do not help that much for syncronization as they work only for threads not processes. You would need to use POSIX semaphores. A good introduction how this can be done can be found here: https://opensource.com/article/19/4/interprocess-communication-linux-storage#shared-memory

 

Thanks! Yes I will use posix-semaphore for that.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...