Page 1 of 1

Mapping memory regio into the address space of every process

Posted: Wed Oct 03, 2012 11:13 am
by hhh83
Dear all,

I am new in this forum, I am looking for answers to my issues.

Actually, I am working in thesis on implementation shared memory programming model under real-time constraints.
My platform consists from multiple cores connects through network on-chip and access to memory off-chip. The memory model divides to private local memory for each core and shared region for all. Each core has own OS and access to memory by using lookup table (LUT), also each core has L1 and L2 caches and didn't has cache coherency between cores. This is description briefly for my platform, and I aim to porting programming model for this system, has real time shared features.

However, There is big issue in this system. It is memory addressing, when core allocated object in shared memory space, should make sort translation to address and send the offset to consumer core. The consumer core also do the same procedure to get the correct address space, since the virtual address is not valid for other cores. So, the access on it can not be accomplished with simply passing the proper pointer.

Therefore, I am looking to ideas or solution to manage this issue.
My questions:
1. I have idea, but I didn't have enough to prepare. If we could mapping the shared memory region as the same virtual address for every processor, we could implement the pointer access approach to shared memory. So, how could implementing this idea? Namely shared virtual mapping and force other cores to remapping this region based on the information memory mapping of one core.

2. Is possible to mapping the stack of processor in shared memory?

I am looking to hearing you.

Thanks in Advance

Re: Mapping memory regio into the address space of every pro

Posted: Wed Oct 03, 2012 3:00 pm
by Combuster
Sounds like an homework question ripped from it's original context. I can't reproduce enough of the actual problem to give hints without making the answer obvious, if there even is one.

Re: Mapping memory regio into the address space of every pro

Posted: Wed Oct 03, 2012 3:11 pm
by hhh83
This is not homework, just, I tried to explain the problem. I will appreciate any help.
Thanks

Re: Mapping memory regio into the address space of every pro

Posted: Wed Oct 03, 2012 8:26 pm
by gerryg400
However, There is big issue in this system. It is memory addressing, when core allocated object in shared memory space, should make sort translation to address and send the offset to consumer core. The consumer core also do the same procedure to get the correct address space, since the virtual address is not valid for other cores. So, the access on it can not be accomplished with simply passing the proper pointer.
The normal method is to create a kernel-managed 'named' object and return whatever pointer or handle is appropriate to the processes. Copying/sharing etc. can be done using the global 'name'. The kernel takes care of the details.
1. I have idea, but I didn't have enough to prepare. If we could mapping the shared memory region as the same virtual address for every processor, we could implement the pointer access approach to shared memory. So, how could implementing this idea? Namely shared virtual mapping and force other cores to remapping this region based on the information memory mapping of one core.
That's generally a poor and rather restrictive solution. I would advise against it.
2. Is possible to mapping the stack of processor in shared memory?
Yes, but again I would advise against it. Stacks are not supposed to be managed by processes. They are under control of the compiler/language environment.

Re: Mapping memory regio into the address space of every pro

Posted: Thu Oct 04, 2012 1:21 am
by hhh83
Thanks for response.

The normal method is to create a kernel-managed 'named' object and return whatever pointer or handle is appropriate to the processes. Copying/sharing etc. can be done using the global 'name'. The kernel takes care of the details.

This is looking like a nice idea, How could I do it ? Could you give me more details to implement it?

Yes, but again I would advise against it. Stacks are not supposed to be managed by processes. They are under control of the compiler/language environment

I know this option under control of the compiler. Namely, one core as the master mapping his stack in shared array. Consequently, all local and global variables of master are shareable and by implementing the idea of fixed virtual address, every core could access this variables.

Re: Mapping memory regio into the address space of every pro

Posted: Thu Oct 04, 2012 2:26 am
by gerryg400
I know this option under control of the compiler. Namely, one core as the master mapping his stack in shared array. Consequently, all local and global variables of master are shareable and by implementing the idea of fixed virtual address, every core could access this variables.
No, you can't do that. Global variables are not on the stack. Furtheremore, while compilers generally use the stack for local variables, many local variables are register based or are optimised away. There is no way to portably and consistently predict where a local variable (on another core) might be at a particular time.

Re: Mapping memory regio into the address space of every pro

Posted: Thu Oct 04, 2012 2:35 am
by bluemoon
hhh83 wrote:Could you give me more details to implement it?
It can be done by abstracting the global object and provide functions to work on that:

Code: Select all

typedef struct {
   uint32_t handle;
   uint32_t attr;
   uintptr_t phy_addr; // physical address
   size_t size;
   uint32_t ref; // reference count (or a more complex user/process list for bookkeeping)
   ...
} GLOBAL_OBJECT;

uint32_t global_allocate(size_t size) {
   GLOBAL_OBJECT* obj = ....; // allocate a new slot
   obj->phy_addr = allocate_physical_memory(size);
   ...
   return obj->handle;
}

void* global_retain(uint32_t handle, void* addr, size_t size) {
   GLOBAL_OBJECT* obj = lock_object(handle);
   mmap(addr, obj->phy_addr, size, flags);
   ...
   unlock_object(handle);
}
The owner process allocate the global object, and all shared process retain that object and map it into local address space.

Re: Mapping memory regio into the address space of every pro

Posted: Thu Oct 04, 2012 11:34 pm
by dozniak
Make SAS OS, lose mapping problems at once.