The riddle of atomic data transfer from process A to process B

The riddle of atomic data transfer from process A to process B

Omer Zak w1 at zak.co.il
Wed Apr 13 16:07:42 IDT 2011


I have a riddle for you.

Given a system with real time processes.

One process (process M) monitors some quantity (say, temperature) and
makes measured values of the quantity available for another process
(process A).
Process A retrieves the measured temperature once in a while and takes
some action accordingly.

The circumstances are such that it is OK for process A's action to take
place few seconds after the temperature has reached the corresponding
threshold value.  However, process A is activated more frequently than
that.

It is desirable to allow the system to occasionally skip an invocation
of process M and/or process A if it is overloaded with other processing
needs.  So the design should not force process A to be activated after
each activation of process M or to activate process M before each
invocation of process A.

The system has several such processes, so it is desirable to have an
inter-process mechanism having the absolute minimum overhead for
unidirectional data transfers from measuring processes (like process M)
to action taking processes (such as process A).

One approach is to exploit the fact that information transfer from M to
A is in one direction only, and that no harm occurs if process A reads
the same value more than once.  In this case, it is possible to use a
shared memory area.
Process M will write to the shared memory area at its pleasure and
process A will read from it, without coordination with process M.

There is one problem, however.  If the value in question is multi-byte
one, then we need to assure that writes and reads to the shared memory
area are atomic, so that it'll never happen that process A reads a
partially-modified value.

If the value being transferred is a single-byte value, then there is no
problem.  In systems with 32-bit memory subsystems and 32-bit data
paths, aligned 4-byte word writes are atomic as well.

However, if one desires to pass, say, an 8-byte value (such as a
timestamp), then one needs to have some locking mechanism.

In systems based upon one single-core processor, it is possible to solve
the problem by turning off interrupts before each write/read to the
shared memory area, and restoring their previous state afterwards.

The riddle:
1. If the operating system being used is Linux, what other mechanisms
(besides turning off interrupts) are available to single-processor
systems to accomplish this?
2. If the system has a multi-core processor or several processors, which
low overhead synchronization method can be used to accomplish this?

--- Omer


-- 
If verbal consent is not obtained in triplicate, it is date rape.
Asking permission constitutes harassment.

My opinions, as expressed in this E-mail message, are mine alone.
They do not represent the official policy of any organization with which
I may be affiliated in any way.
WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.htmlDelay is the deadliest form of denial.    C. Northcote Parkinson
My own blog is at http://www.zak.co.il/tddpirate/

My opinions, as expressed in this E-mail message, are mine alone.
They do not represent the official policy of any organization with which
I may be affiliated in any way.
WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.html




More information about the Linux-il mailing list