How to place global variable in SMP system?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
nbdd0121
Member
Member
Posts: 60
Joined: Thu Jul 25, 2013 8:10 am

How to place global variable in SMP system?

Post 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
Last edited by nbdd0121 on Thu Aug 22, 2013 8:32 pm, edited 1 time in total.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: How to place global variable in SMP system?

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
arseniuss
Member
Member
Posts: 32
Joined: Tue Aug 10, 2010 12:13 am
Location: Latvia
Contact:

Re: How to place global variable in SMP system?

Post 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.
Hobby stuff (suckless libs, compilators, game engines, kernels): github. Work @ zabbix: arseniuss@zabbix
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: How to place global variable in SMP system?

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Geri
Member
Member
Posts: 442
Joined: Sun Jul 14, 2013 6:01 pm

Re: How to place global variable in SMP system?

Post by Geri »

Combuster wrote:int variable_name;
nope

volatile long variable_name;
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: How to place global variable in SMP system?

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply