What is the best way for interprocess communication on Linux?

I have two processors on a chip and they have shared memory. This is not an SMP architecture. Only two processors on a chip with shared memory.

The first processor has a Unix-like operating system, and the second processor has a Linux operating system.

The first processor does some work, and the result of this task is some data. After the first processor completes its work, it must tell the other processor that the task is completed, and the second processor should process this data.

What is the way to handle interprocess communication? What algorithm should I use for this?

Any reference to an article about this is welcome.

+3
source share
7 answers

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

Both processors work under Linux? How do they handle shared memory? A good solution is to use a linked list like fifo. On this fifo, you put a data descriptor, such as address and size.

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

  • Processor A performs some calculations
  • Processor A pushes data descriptor output fifo
  • Processor Waiting for fifo input data descriptor
  • cycle

  • Processor B waits for fifo output data descriptor

  • Processor B works with data
  • Processor B pushes the used data descriptor to the input fifo
  • cycle

, . , , , "" SMP.

, , , , .

: . Hasturkun , .

+3

Ok. . .

, , , . -, , .

, .

, .

+2

- IP- ( ). , - , , .

+1

os, IPC , . , .

+1

:

  • Done flag

INIT:

init()
{
    ready = 0;
    done = 1;
}

:

send()
{
    while (!done)
        sleep();

    /* copy data in */
    done = 0;
    ready = 1;
}

:

poll()
{
    while (1)
    {
        if (ready)
        {
            recv();
        }
        sleep();
    }
}

recv()
{
    /* copy data out */
    ready = 0;
    done = 1;
}

mem ( , , flush/invalidate).

( ) :

  • ( , )

, , : (, send/recv )

poll()
{
    /* you're better off using interrupts instead, if you have them */
    while(1)
    {
        if (current_owner == me)
        {
            if (active)
            {
                recv();
            }
            else if (!request[me] && request[other])
            {
                request[other] = 0;
                current_owner = other;
            }
        }
        sleep();
    }
}

recv()
{
    /* copy data... */
    active = 0;
    /* check if we still want it */
    if (!request[me] && request[other])
    {
        request[other] = 0;
        current_owner = other;
    }
}

send()
{
    request[me] = 1;
    while (current_owner != me || active)
    {
        sleep();
    }

    request[me] = 0;

    /* copy data in... */

    /* pass to other side */
    active = 1;
    current_owner = other;
}
+1

mem?

, google IPC + shared mem, , :)

0

Are you sure you need to do this? In my experience, you'd better let your compiler and operating system control how your process uses multiple processors.

0
source

Source: https://habr.com/ru/post/1715865/


All Articles