| Page: | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|
A queue will always contain a put procedure and may also contain an associated service procedure. Having both a put and service procedure in a queue enables STREAMS to provide the rapid response and the queuing required in multiuser systems.
The service and put routines pointed at by a queue, and the queues themselves, are not associated with any process. These routines may not sleep if they cannot continue processing, but must instead return. Any information about the current status of the queue must be saved by the routine before returning.
| Home |
|---|
The put procedure allows rapid response to certain data and events, such as echoing of input characters. It has higher priority than any scheduled service procedure and is associated with immediate, as opposed to deferred, processing of a message.
The put procedure executes before the service procedure for any given message.
| Under no circumstances may a driver or module directly call other driver or module routines, including put and service routines. All calls are indirect. |
For example, consider that modA, modB, and modC are three consecutive components in a Stream, with modC connected to the Stream head. If modA receives a message to be sent upstream, modA processes that message and calls modB's read put procedure, which processes it and calls modC's read put procedure, which in turn processes it and calls the Stream head's read put procedure. Thus, the message is passed along the Stream in one continuous processing sequence. This sequence completes the entire processing in a short time with low overhead (subroutine calls). On the other hand, if this sequence is lengthy and the processing is implemented on a multiuser system, then this way of processing may be good for this Stream but may be harmful for others. Streams may have to wait too long to get their turn, because each put procedure is called from the preceding one, and the kernel stack (or interrupt stack) grows with each function call. The possibility of running off the stack exists, causing a system panic or producing indeterminate results.
| Because STREAMS modules in general do not know which modules they are connected to, put routines cannot depend on a message being handled solely by put routines at the stream head or in the driver. Any modules along the Stream may choose to queue the message and process it with a service routine. |
| Home |
|---|
The STREAMS scheduler is separate and distinct from the UNIX system process scheduler. The scheduler calls each service procedure of the scheduled queues one at a time in a FIFO manner.
The scheduling of queue service routines is machine-dependent.
Terminal output and input erase and kill processing, for example, it is typically performed in a service procedure because this type of processing does not have to be as timely as echoing. A service procedure also allows processing time to be more evenly spread among multiple STREAMS. As with the put procedure, there can be a separate service procedure for each queue in a STREAMS component or a single procedure used by both the read and write queues.
| Home |
|---|
Communications software support for these terminals is provided using a STREAMS-based asynchronous protocol. The protocol includes a variety of options that are set when a user dials in to log on. The options are determined by a STREAMS user process, getstrm, which analyzes data sent to it through a series of dialogs (prompts and responses) between the process and the terminal user.
The process sets the terminal options for the duration of the connection by pushing modules onto the Stream or by sending control messages to cause changes in modules (or in the device driver) already on the Stream. The options supported include
| CHARPROC | Provides input character processing functions, including dynamically settable (using control messages passed to the module) character echo and parity checking. The module's default settings are to echo characters and not check character parity. |
| CANONPROC | Performs canonical processing on ASCII characters upstream and downstream (note that this performs some processing in a different way from the standard UNIX system character I/O tty subsystem). |
| ASCEBC | Translates EBCDIC code to ASCII upstream and ASCII to EBCDIC downstream. |
The initial idle Stream, shown in Figure 4-1, contains only one pushable module, CHARPROC. The device driver is a limited function raw tty driver connected to a limited-function communication port. The driverand port transparently transmit and receive one unbuffered character at a time.

After receiving initial input from a tty port, getstrm establishes a connection with the terminal, analyzes the option requests, verifies them, and issues STREAMS system calls to set the options. After setting up the options, getstrm creates a user application process. Later, when the user terminates that application, getstrm restores the Stream to its idle state by similar system calls.

| Home |
|---|
As mentioned previously, the upstream queue is also referred to as the read queue reflecting the message flow direction. Correspondingly, downstream is referred to as the write queue.
| Home |
|---|

When the driver calls CHARPROC's read queue put procedure, the procedure checks private data flags in the queue. In this example, the flags indicate that echoing is to be performed.
| Echoing is optional for this example and the port hardware cannot automatically echo. |
CHARPROC causes the echo to be transmitted back to the terminal by first copying the message with a STREAMS utility routine. Then, CHARPROC uses another utility routine to obtain the address of its own write queue. Finally, the CHARPROC read put procedure uses another utility routine to call its write put procedure and pass it the message copy. The write procedure sends the message to the driver to effect the echo and then returns to the read procedure.
This part of read-side processing is implemented with put procedures so that the entire processing sequence occurs as an extension of the driver input character interrupt.
After returning from echo processing, the CHARPROC read put procedure checks another of its private data flags and determines that parity checking should be performed on the input character. Parity should most reasonably be checked as part of echo processing. However, for this example, parity is checked only when the characters are sent upstream. This relaxes the timing in which the checking must occur, that is, it can be deferred along with the canonical processing. CHARPROC uses putq to schedule the (original) message for parity check processing by its read service procedure. When the CHARPROC read service procedure is complete, it forwards the message to the read put procedure of CHARPROC . Note that if parity checking was not required, the CHARPROC put procedure would call the CHARPROC put procedure through the putnext routine.
| Home |
|---|
ioctl messages are sent downstream as a result of an ioctl(2) system call. When CHARPROC receives an ioctl message type, it processes the message contents to change internal flags and then uses a utility routine to send an acknowledgment message upstream to the Stream head. The Stream head acts on the acknowledgment message by unblocking the user from the ioctl.
For terminal output, it is presumed that M_DATA messages, sent by write(2) system calls, contain multiple characters. In general, STREAMS returns to the user process immediately after processing the write call so that the process may send additional messages. Flow control eventually blocks the sending process. The messages can queue on the write-side of the driver because of character transmission timing. When a message is received by the driver's write put procedure, the procedure uses putq to place the message on its write-side service message queue if the driver is currently transmitting a previous message buffer. However, there is generally no write queue service procedure in a device driver. Driver output interrupt processing takes the place of scheduling and performs the service procedure functions, removing messages from the queue.
| Home |
|---|
| Contents | Previous Chapter | Next Chapter | Index | Glossary |