Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way for interprocessor communication in Linux?

I have two CPUs on the chip and they have a shared memory. This is not a SMP architecture. Just two CPUs on the chip with shared memory.

There is a Unix-like operating system on the first CPU and there is a Linux operating system on the second CPU.

The first CPU does some job and the result of this job is some data. After first CPU finishes its job it should say to another CPU that job is finished and the second CPU have to process this data.

What is the way to handle interprocessor communication? What algorithm should I use to do that?

Any reference to an article about it would be greatly appreciated.

like image 211
Sergey Smelov Avatar asked Feb 28 '23 09:02

Sergey Smelov


2 Answers

It all depends on the hardware. If all you have is shared memory, and no other way of communication, then you have to use a polling of some sort.

Are both of your processor running linux ? How do they handle the shared memory ? A good solution is to use a linked list as a fifo. On this fifo you put data descriptor, like adress and size.

For example, you can have an input and output fifo, and go like this :

  • Processor A does some calculation
  • Processor A push the data descriptoron the output fifo
  • Processor A wait for data descriptor on the input fifo
  • loop

  • Processor B wait for data descriptor on the output fifo

  • Processor B works with data
  • Processor B push used data descriptor on the input fifo
  • loop

Of course, the hard part is in the locking. May be you should reformulate your question to emphasize this is not 'standard' SMP.

If you have no atomic test and set bit operation available on the memory, I guess you have to go with a scheme where some zone of memory is write only for one processor, and read only for the other.

Edit : See Hasturkun answer, for a way of passing messages from one processor to the other, using ordered write instead of atomicity to provide serialized access to some predefined data.

like image 105
shodanex Avatar answered Mar 05 '23 18:03

shodanex


Ok. I understand the question.I have worked on this kind of an issue.

Now first thing that you need to understand is the working of the shared memory that exists between the 2 CPUs. Because these shared memory can be accessed in different ways, u need to figure out which one suits u the best.

Most times hardware semaphores will be provided in the shared memory along with the hardware interrupt to notify the message transfer from one processor to the other processor.

So have a look at this first.

like image 34
Vishal Avatar answered Mar 05 '23 16:03

Vishal