Page 1 of 1

How to place global variable in SMP system?

Posted: Thu Aug 22, 2013 7:14 am
by nbdd0121
How to place global variable for each CPU in SMP system?
I currently let each CPU map a certain location to different physical memory:
CPU0 0xC0007000 - > 0x400000
CPU1 0xC0007000 - > 0x401000
and I read/write these variable from 0xC0007000

Re: How to place global variable in SMP system?

Posted: Thu Aug 22, 2013 7:40 am
by Combuster
int variable_name;




Seriously, if you have to ask this question in this fashion you will probably need to learn a lot about mutual exclusion first.

Re: How to place global variable in SMP system?

Posted: Thu Aug 22, 2013 11:54 am
by arseniuss
As Combuster I also think that you could specify your question.

There can be examples which way answer may go:
1. Variable which is shared between processes in SMP system (but in one CPU)
2. Variable which is shared between CPU
-- Problem: need locks for writing/reading
3. etc.

Re: How to place global variable in SMP system?

Posted: Thu Aug 22, 2013 9:26 pm
by Brendan
Hi,
nbdd0121 wrote:How to place global variable for each CPU in SMP system?
I currently let each CPU map a certain location to different physical memory:
CPU0 0xC0007000 - > 0x400000
CPU1 0xC0007000 - > 0x401000
and I read/write these variable from 0xC0007000
By mapping physical memory this way, no CPU can access the same RAM which makes it impossible for different CPUs to access the same global variable/s.

One (extremely common) solution would be to have one or more physical pages that are mapped at the same virtual address for all CPUs. For example, for most OSs, all of "kernel space" is the same for all CPUs.


Cheers,

Brendan

Re: How to place global variable in SMP system?

Posted: Sat Aug 24, 2013 7:58 am
by Geri
Combuster wrote:int variable_name;
nope

volatile long variable_name;

Re: How to place global variable in SMP system?

Posted: Sat Aug 24, 2013 8:17 am
by Combuster
Geri wrote:
Combuster wrote:int variable_name;
nope

volatile long variable_name;
It was the correct answer to the original (ridiculous) form of the question, and it could still be depending on the solution.