EE382C Embedded Software Systems - Introduction to Process Networks
Turing Machines
The Turing machine was proposed by British Mathematician Alan Turing
about nine years before computers were invented.
Given a finite-length program that runs on a Turing machine, it is
undecidable to decide always in finite time whether or not the program
will terminate.
This is known as the Halting Problem.
From page 638 of Robert Sedgewick's Algorithms in C++ book:
"The universal Turing machine is a simple model of a computer.
It can read inputs, perform certain operations, and write outputs.
A Turing machine can perform any computation that any other
general-purpose computer can perform, using the same amount of time
(to within a polynomial factor), and it has the additional advantage
that it can be concisely described mathematically."
We have previously mentioned that Boolean Dataflow is Turing equivalent.
That is, we can implement a universal Turing machine in Boolean dataflow
by using Switch, Select, Addition, Subtract, and Integer Comparison actors.
Switch and Select are Boolean dataflow operations, whereas Addition,
Subtraction, and Integer Comparison are Synchronous Dataflow operations.
Kahn Process Networks
A Kahn Process Network program is a set of processes that communicate through
a network of unidirectional communication channels.
Each communication channel has one writer and one reader.
Each communication channel is an infinite, first-in first-out (FIFO) queue
of tokens.
A token may be any data structure.
The tokens are not timed; i.e., no time stamps are maintained.
That says, Kahn explicitly allows for latency in the communication channels.
His only requirement is that the communication delay be finite. [Kahn, 1974]
When a process reads from a queue, the read is blocking.
If the queue is empty, then the process will suspend until there is
enough data in the queue.
When a process blocks, the scheduler will not unblock the process until enough
data becomes available on the blocking input port.
Writes to the queues are non-blocking because the queue size is infinite.
A Kahn Process Network is Turing complete - questions of termination and
bounded buffering are undecidable.
That is, no finite time algorithm can decide these questions for all
Kahn Process Network programs.
Another view of a Kahn Process Network is a set of Turing machines connected
by one-way tapes, in which each machine has its own working tape.
Hence, for a Kahn Process Networks program, it will be undecidable (i.e.,
not decidable in finite time) whether or not a Process Network terminates.
It is also undecidable whether or not a Process Network will require
bounded memory.
But, since we are interested in Process Networks that run in infinite time,
we could decide to let the scheduler find a bounded memory solution using
infinite time.
Properties of Kahn Process Networks
Kahn Process Network programs are determinate; i.e., the history
of tokens produced on the communication channels do not depend on the
execution order.
They may be executed sequentially or in parallel with the same outcome.
These systems support recurrence and recursion.
Processes are functions that map streams into streams.
Additional properties:
- Termination - does not depend on the execution order, only on the program.
- Boundedness - does in fact depend on the execution order.
Termination occurs upon global deadlock, i.e., when all processes are
blocked on reads.
Upon termination, it is possible that some of the channels are not empty.
One can transform a Kahn Process Network into one that is strictly bounded.
[Parks, 1995]
If the original Kahn Process Network has a bounded implementation, then
the bounded transformation does not destroy the determinate property.
However, if the original Kahn Process Network does not have a bounded
implementation, then the bounded transformation may destroy the determinate
property.
Scheduling Process Networks
A process is either enabled, or blocked waiting for
data on at least one of its input channels.
For sequential processes, a process can only block on at most one
channel at a time.
This is not true for the more general case of continuous processes.
[Parks, April 5, 2004, personal correspondence].
Kahn gives a brief example of a continuous (but not sequential) process near
the end of his 1974 paper. [Kahn, 1974]
Scheduling requirements include the following:
- Complete execution - if the program is non-terminating, then the
scheduler should execute it forever without terminating.
- Bounded execution - if possible, only a bounded number of tokens
should ever accumulate on any of the communication channels.
Requirement 1 takes priority over Requirement 2.
For unbounded programs that require unbounded buffering of tokens,
we prefer a complete unbounded execution to a partial, bounded one.
Dynamic Scheduling
- Data driven - activate a process as soon as sufficient data is
available - this approach satisfies Requirement 1 above
- Demand driven - delay activation of a process until its data
is needed by another process - the scheduler selects a
single process to drive the entire network
- Hybrid - e.g., alternate between the two approaches - use
data driven when there is a token deficit (such as at the
beginning of execution) until there is a token surplus -
at which point, switch to demand-driven execution.
Updated 04/19/04.