LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-01-2012, 08:18 PM   #1
joele54
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Rep: Reputation: Disabled
Multiprocessor Programming Example Code?


I am working on an embedded Linux project which has 3 CPU boards running the same software under Linux on each CPU (these are separate CPU boards on a passive backplane). I need for all 3 CPUs to have read/write access to the same block of memory across the backplane, with some sort of protection mechanism (intercpu semaphores ?).

If anyone has any link to programming examples (especially in C) that might help me figure out how to set this up, please post them.

Thanks.
 
Old 02-01-2012, 09:33 PM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Do you have the hardware already set up so they share a memory aperture correctly? Have you already taken care of caching issues (usually, disabled CPU caching for the aperture)?

Last edited by Nominal Animal; 02-01-2012 at 09:33 PM. Reason: Silly me: It's linux, so it has GCC.
 
Old 02-03-2012, 11:09 PM   #3
joele54
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
I have since found out that mmap allows mapping a shared segment at a fixed address. This memory block could be programmed to be in PCI address space so it should be visible to other CPUs over the PCI bus.
 
Old 02-04-2012, 05:23 AM   #4
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Yes. You'd better use a trivial character device driver (that exports open(), close(), and mmap()) for this, though. You only need request_mem_region() to reserve the address range, then io_remap_pfn_range() to remap it to user space. See Linux Device Drivers, 3rd Edition, especially chapter 3 for details.

I'm still a bit intrigued. The PCI bus is a good choice for something like this.

Perhaps you could set up the IOMMU on each CPU so that each has an (separate) address range on the PCI bus mapped to uncached memory on it? In this case, the standard multiprocessor locking primitives (that apply the PCI bus lock (LOCK opcode prefix on x86 architectures) will Just Work for you. Instead of a single shared aperture, you'd have three apertures, each one owned by a specific CPU, but accessible to all three. Even if one of the CPUs drops, the other two can continue working (assuming you have hardware that will make sure one CPU will not hog the CPU bus indefinitely). Your userspace will use your driver to map all three apertures.

The logic on how to keep all three in sync (if you intend to have majority rule, like NASA does for satellite stuff -- any one CPU is overruled by the other two, but consensus is expected) is built on top of the locking primitives; the operations you need depend on the way you intend to utilize the CPU triplet: in parallel, sharing the workload, or with dedicated purpose each.

Last edited by Nominal Animal; 02-04-2012 at 05:28 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with the c programming code? fm_hyudin Programming 5 09-10-2008 08:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration