|
|
STREAMS/UX for the HP 9000 Reference Manual > Chapter 3 Differences Between STREAMS/UX and
System V Release 4 STREAMSSTREAMS/UX Uniprocessor Synchronization |
|
This section describes STREAMS/UX synchronization on a uniprocessor system. Chapter 4 discusses multiprocessor synchronization. Also, Chapter 4 describes how modules and drivers running on a uniprocessor system can use multiprocessor synchronization mechanisms to protect against interrupts. STREAMS/UX programmers must follow the guidelines listed below as well as those in the SVR4.2 STREAMS manual. STREAMS/UX provides the following types of synchronization on a uniprocessor system:
STREAMS/UX protects its internal data structures, such as message queues, against interrupts. STREAMS/UX programmers must use the following guidelines.
Drivers and modules must protect their private data structures against interrupts. This can be done in four ways. One way would occur if software that is running on the interrupt control stack (ICS) modifies driver and module data structures. In this case, the driver and module service and put routines must raise the spl level before accessing their data structures. Drivers and modules can call the STREAMS/UX utility splstr to raise the spl level to spl5. Interrupts are masked while the spl level is raised. The second way to protect data structures against interrupts is for software running on the ICS to send a message to a stream. If this is done, drivers and modules do not need to raise the spl level to protect their data. The software running on the ICS does a putq on the driver's read queue. The STREAMS scheduler will run the service routine off the ICS. When ICS software calls putq for a priority band, the driver open function must allocate the band by calling strqget. This prevents putq from dynamically allocating memory for the band on the ICS. ICS software can call putnext or put instead of putq to send a message to a stream. If one of these utilities is called, STREAMS/UX will attempt to run the put routine on the ICS. Drivers and modules will need to use spl calls to protect data structures that they share with other drivers and modules, with other instances of the same driver or module, or with non-STREAMS/UX software. The third way to protect data structures against interrupts is for interrupt software to call the qenable utility to schedule a service routine. The STREAMS/UX scheduler will run the service routine off the ICS. The fourth method for protecting data structures against interrupts is to call the new streams_put utility. The code running on the ICS passes streams_put a function and a queue. STREAMS/UX runs the function as if it were the queue's put routine. The function can access the same data structures as the queue's put routine. See "HP-UX Modifications to STREAMS/UX Utilities" in this chapter for more information about streams_put. STREAMS/UX synchronizes multiple processes that are accessing the same stream. Three scenarios will allow more than one process to operate on a stream:
For synchronization, STREAMS/UX will queue some open and ioctl system calls issued by different processes, and will execute them one at a time. STREAMS/UX queues re-opening an already open stream, and queues the following ioctls: I_PUSH, I_POP, I_LINK, I_PLINK, I_UNLINK, I_PUNLINK, I_FLUSH, I_FLUSHBAND, I_GETCLTIME, I_SETCLTIME, I_GETSIG, I_SETSIG, I_LIST, I_LOOK, and I_STR. STREAMS/UX does not process a close call until the last file descriptor for a stream is closed. No other system calls will be executing when STREAMS/UX begins to dismantle the stream. For remaining system calls, STREAMS/UX ensures that consistent results are returned, but the calls are not executed one at a time. For example, if two processes are reading from the same stream, one process could read the first and third messages on the stream to satisfy a read request while the second process reads the second and fourth messages. The STREAMS/UX scheduler runs service routines that are scheduled by STREAMS/UX utilities such as putq . The scheduler will run all scheduled service routines before returning to user level. The scheduler is a real time daemon that runs at priority 100. (A low priority number denotes a high priority. For example, a priority number of 50 would be of higher priority than the number 100.) STREAMS/UX applications need to run at a lower priority (higher priority number) than the STREAMS/UX scheduler; otherwise service routines will not run before the scheduler returns to user level from the kernel. |
|