LaoShaw Posted February 26, 2022 Report Share Posted February 26, 2022 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. Quote Link to comment Share on other sites More sharing options...
David Black Posted February 26, 2022 Report Share Posted February 26, 2022 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. Quote Link to comment Share on other sites More sharing options...
LaoShaw Posted February 27, 2022 Author Report Share Posted February 27, 2022 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? Quote Link to comment Share on other sites More sharing options...
Eyck Posted February 27, 2022 Report Share Posted February 27, 2022 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 Quote Link to comment Share on other sites More sharing options...
LaoShaw Posted February 27, 2022 Author Report Share Posted February 27, 2022 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.