<<

Behavior Research Methods & Instrumentation 1979. Vol. 11 (5).507-511 TECHNOLOGY The design of a real-time for experimental psychology KENNETH J. BURKHARDT DepartmentofElectrical Engineering, RutgersUniversity. Piscataway, New Jersey 08854

This paper describes the structure of the operating system that was utilized in the imple­ mentation of the experimental . PL/E. Although the system was originally designed to support programming of psychological experiments on a specific machine ( General Nova), the operating system can be ported with a minimum of effort to other machines. This paper describes the internal and control structures used in the system and suggests how it can be moved to other .

Given the ever decreasing cost of computer hardware, REQUIREMENTS FOR it is becoming quite clear that the cost of implementing REAL-TIME SYSTEMS any application on a computer is greatly affected by the degree of effort required to develop system software. Software requirements for real-time applications In many small computer environments, system hardware such as experimental psychology must be examined at costs are often negligible when compared with software two levels: the level of the applications software and the costs. Thus, in order to minimize total system cost, level of the operating system software. At the applica­ it is necessary to utilize appropriate design aids for tions level, the problems of real-time programming are efficient software development. Although many such quite complex. The wide disparity between potential tools exist in conventional data processing and scientific applications makes even specification of a typical environments (for example, higher level languages such environment extremely difficult, if not impossible. as and COBOL), there are a limited number Conceptually, real-time programs require little more of tools available for real-time system design. complexity than conventional programs. The only This paper describes the structure of an operating constructs that have to be added to non-real-time system utilized in the implementation of an experi­ languages are capabilities for synchronization and mental language known as PL/E. PL/E is a loosely capabilities for controlling tasks as a function of time. defined higher level language that has been designed . From a practical standpoint, however, there is one to function as an aid in the implementation of real­ potentially large difference between conventional and time systems software. Its primary use has been in real-time programs. In real-time systems the applications applications associated with on-line experimental psy­ must be concerned with operating systems chology. PL/E, however, has also been utilized in several concepts and timing considerations that are transparent commercial data base management systems. in non-real-time applications. This not only makes the This paper has four major sections. The first task of program validation more complex due to timing describes software requirements for real-time systems considerations, but it also makes the task of in general and justifies the development of a special­ programming more complex, in that the applications purpose operating system for psychology. The second programmer must be aware of system operations at a section briefly describes the features of PL/E and the lower level. run-time that supports the language. The At the operating systems level, the problems of third section describes the control structures and real-time software have been extensively investigated. algorithms utilized in the operating system. The final Brinch Hansen (1977), Wirth (1977), and others section describes requirements for moving the operating (Dijkstra, 1968; Hoare, 1974) have proposed and system to other computers. implemented a variety of higher level languages and other facilities for the design and construction of reliable Development of the PL/E system was supported by the and efficient real-time executives for both small and National Institute of Mental Health, Grant MH-21795, Earl large computers. Generally, these software tools include Hunt, principal investigator, and the National Institute of Education, Grant NIE-6-74-0104, Clifford Lunneborg, principal capabilities for controlling concurrent processes, investigator, to the University of Washington. John Palmer, interprocess communication, and general process Zelda Zabinsky, and Barry Yanoff were all instrumental in the synchronization. Unfortunately, many of these facilities implementation of the original system. are inadequately supported by the vendors of mini- and

Copyright 1979 Psychonomic Society, Inc. 507 0005·7878/79/050507-05$00.75/0 508 BURKHARDT

systems. The greatest difficulty either pseudoinstructions (commands) or new data encountered in commercial operating systems is the types to the PL/E language without having to modify uncertainty of execution speed for many operations. existing software. New commands can be added to the This can seriously hinder the capability to control PL/E simply by adding the command name and informa­ psychological experiments, in which there is often a tion about its parameters to a system data me read by desire to control display intervals or measure subject the at run-time. New data types or structures response times to within several milliseconds. Other can also be added to the system with relative ease. For problems often encountered in commercial systems example, structured data records (similar to COBAL or are difficulty in interfacing nonstandard hardware, PL/ 1) have been added to PL/E simply by modifying a limited scheduling capabilities, and lack of support for single systems routine and adding a new data-type appropriate higher level languages. definition command to the compiler. This paper describes a system that was designed to alleviate these problems. The primary emphasis is to The Operating System describe the structure and algorithms utilized in the To a large extent the system can be described as an operating system that supports the experimental operating system without an operating system. The programming language, PL/E. The operating system has only required element of the resident system is a 100 removed the majority of the problems associated with instruction kernel, the scheduler. The scheduler consists real-time programming from the applications program­ of two modules: the service routine and the mer and supports facilities to accurately estimate timing background scheduler, or interpreter. The interrupt requirements associated with various operations. service routine assigns priorities to the various devices and, on detection of , passes control to the The Applications Language appropriate device handlers. If after processing PL/E is an algebraic language designed originally for interrupts, the interrupt service routine determines human experimental psychology. The main features of that the system was previously idle, control is passed the language are the abilities to process a variety of dif­ to the background scheduler. ferent variable types, to control external apparatus (e.g., Before describing the actual operation of the experimental stations, CRTs, response keys, etc.), and to operating system in detail, it is useful to deflne the control a large number of subjects simultaneously. control structures utilized in its realization. Rather than being a language such Control structures. The control structures of a as MODULA (Wirth, 1977) or CONCURRENT PASCAL system are the basic data structures manipulated by (Brinch Hansen, 1977), PL/E is strictly an applications­ the operating system during execution of a program. level language, with virtually all timing control and The control structures define the status of individual other synchronization tasks performed by the under­ subject programs and the status of individual input­ lying operating system (for a more detailed description output (I/O) devices. The four basic structures utilized of the system, see Burkhardt, 1976, 1977; Palmer, in the PL/E system are semaphores, program status McCloud, & Loftus, 1978). vectors (PSV), doubly linked lists, and dope vectors. PL/E is not directly executed. It is an intermediately The flrst three structures are utilized internally by the interpreted language that is compiled before execution operating system and are totally transparent to user takes place interpretively under control of the run-time programs. Dope vectors are generated by the compiler system. The code generated by the compiler is in a and are utilized to pass user program variables to lower three-address prefix format. For example, I =X + Y is level routines. compiled as Semaphores. Semaphores are special integer variables proposed by Dijkstra (1968) as synchronizing flags to ADD be utilized in the allocation of resources. A semaphore @ X is associated with any device that can be simultaneously @ Y accessed by more than a single task (e.g., disk, console @ I TTY). A device is referenced internally by means of two basic operations: allocate (P) and release (V). The where ADD corresponds to an integer constant pointing implementation of the P and V operations is quite to an interpreter , and X, Y, and I are similar to that proposed by Dijkstra (1968). Whenever pointers to descriptors of the appropriate variables. a task requires a device, the appropriate P operation is The calculation of variable addresses is performed by executed and, if the device is free, it is allocated to the a single system (GETARG) that examines task. When finished with a device, the task releases the the descriptor to determine the data address, verifies device and reschedules any suspended tasks by means that the address is valid, and returns the address of the of the V operation. argument. The P and V operations are implemented according This very simple organization makes it easy to add to the following algorithms: OPERATING SYSTEMDESIGN 509

Procedure P (Device) containing forward and backward address together Disable Interrupts with sufficient storage to save a task's PSV. The primary IF (Device-flag.Eq. 0) purpose of the doubly linked list structure is to act as a THEN Device-flag = I scheduling aid for each of the hardware resources in Enable Interrupts the PL/E system. There is a doubly linked list associated Return ELSE Device-flag = Device-flag + I with each I/O device, with the timer and with the CPU Append PSV on Device-list itself. Enable Interrupts By utilizing a series of system , a process Go to Scheduler can insert, delete, append, or remove the first entry from DONE a doubly linked list. Thus, this allows a Procedure V (Device) list to be utilized as a stack, a queue, or an ordered Disable Interrupts queue. The methodology of queue manipulation defines Device-flag =Device-flag - I IF (Device-flag.Eql. 0) the resource-scheduling . For example, the THEN Enable Interrupts schedule assigns a task the right to the CPU by removing Return the first entry from the execution list (XEQ) and ELSE TEMP = POP (Device List) copying the associated status to the active PSV. Append TEMP to XEQ-List Dope vector. The dope vectors are the variable Enable Interrupts Return descriptors that are utilized by command routines to access user program variables. The dope vectors are Note that interrupts are disabled during both P and V. This is to insure mutually exclusive access to the resource scheduler. Without mutual exclusion, the Subject Number system can only process a single subject at a time. Pseudoprogram Counter Program status vector. The PSV (Figure 1) is a Maximum sequence of variables that defines the status of the Minimum Memory Address system at any point in time. Included in this list of I/O Return Address I/O Device in Use variables is the pseudoprogram counter, task identifica­ Format Specification Address tion, high- and low-memory limits (for the implementa­ Expiration Time tion of storage protection), and various other status Response Key Mask information. The PSV is altered primarily by the Response Key Data scheduler during the start-up and suspension of tasks. Temporary Storage Doubly linked lists. A doubly linked list (Figure 2) is a data structure consisting of a list of entries, each Figure 1. The process status vector.

1 ~ ----- ,..--- - V List Head Saved PSV

Figure 2. The doubly linked list data structure. 510 BURKHARDT

set up initially by the compiler to define variable type, Background Monitor storage limits, and mode of addressing. The primary P (Device); Allocate Device; reason for utilizing dope vectors, rather than storage Insert PSV at head of Device List addresses is to be able to support parallel program START I/O WAIT for Response execution (via relative addressing) and complex data V (Device) types, such as arrays and strings. Go to Scheduler Interrupt Driver Gear Interrupt The Schedulers TEMP = POP Device-List Given the basic control structures and assorted Append TEMP to XEQ-List system-level routines for manipulating these structures, INTERRUPT the implementation of the operating system is fairly Note that only a single list is required to keep track straightforward. of the subject that has actually been allocated a device Background scheduler. The basic scheduling and subjects waiting for a device. The P operation algorithm of the system is first come, first served. A moves a subject trying to gain access to an allocated subject retains control of the machine until issuing a device to the end of the device list. The background request for an I/O operation or a delay. The device and interrupt drivers, however, utilize the first list driver then suspends the subject until the I/O operation entry for controlling the subject actually allocated to is complete. the device. The background scheduler is activated either after an Timing control. The device drivers utilized with interrupt has occurred (when the system was previously the real-time clock are handled somewhat differently idle) or after a subject has been suspended. from those of regular I/O devices. Since the real-time The scheduling algorithm is as follows; clock can support more than a single subject simultane­ ously, timer list entries are ordered by time. The frame If (XEQ-list .EQ. EMPTY) Then PSV = IDLE of reference utilized for timing control is time in milli­ ELSE PSV = POP (XEQ-list) seconds from system start-up. When a subject issues a DONE. WAIr (time) command, the background handler .calculates absolute expiration time and then inserts a If a subject is waiting for execution, the first entry list entry at the appropriate position in the timer list. of the execution list will be copied to the PSV, and The interrupt-level driver then checks the first entry control is passed to that subject. If no subject is ready in the list each time the timer generates an interrupt to proceed, the system simply enters an idle mode. (every millisecond). The primary advantage of ordering Interrupt scheduler. The operation of the interrupt entries by time is to minimize system overhead in the scheduler varies depending on the interrupt processing timer . hardware of the associated processor. In the case of the Response key. Response keys are also handled Nova, which has only a single true level of differently from other I/O devices. At start-up time, interrupt priority, the interrupt scheduler has the tasks each subject is allocated a unique keyboard; thus there of saving registers, determining what device caused the is no concern with shared access to a device. A subject interrupt, and then passing control to the appropriate program accesses a keyboard either by waiting for device drivers. In this case the priority of a device is response or by waiting for a response to occur within a determined by the order in which the interrupt certain period of time. In both situations, a mask is scheduler tests for its having caused an interrupt. On set in the response list entry that defines allowable exit from an interrupt, control is returned to either the responses. In the case in which the device may time-out, interrupted program or the background scheduler as a second entry is created for the timer list. When a a function of whether or not the system was previously response key is pressed, the interrupt driver locates the in an idle mode. appropriate entry and, if a valid response has occurred, Device handlers. All hardware resources in the system moves the entry to the XEQ list. have at least two levels of supporting software: the back­ Formatted I/O. The formatted I/O handler is the ground monitor and the interrupt-level . most complex portion of the PL/E run-time system. The background monitor allocates devices, suspends the It requires a second level of interpretation to interface subject program, and physically starts the device. The device drivers to the format specifications outline in interrupt driver responds to device interrupts and, subject programs. The format specifications are treated when appropriate, reschedules the background monitor. as instructions, whereas the normal instruction stream is The background monitor is entered directly from the treated as data. Although a detailed description of the subject program. The following is a sample control formatted I/O handler is beyond the scope of this sequence for a background monitor and an interrupt paper, it is useful to examine its operation at a top level. driver. Consider the following PL/E statement sequence: OPERATING SYSTEM DESIGN 511

WRITE - TT FORM I. RESPONSE PORTABILITY FORMl: FORMAT «X<5> 1<5> X 'MS') Although initially implemented in language This sequence might correspond to printing some on a Data General Nova, the PL/E operating system is preliminary results on a Teletype. The two statements sufficiently flexible to be moved to other machines. would be compiled as follows: Basically, the major requirement is to be able to support the control structures described earlier in this paper. WRITE - TTY These structures can be implemented on almost any FORM I @RESPONSE machine in use today. At Rutgers, a project is presently FORM 1: X<5> ; ASCII string corresponding moving the operating system to an 8080-based 1<5> to I/O format specification hobbyist computer. In this situation the system will X be coded in a higher level language (PL/M) to speed 'M S' system implementation and simplify validation. o Moving the compiler for PL/E is a more complex task. Although it has been written in FORTRAN on Execution of the WRITE·TTY statement causes Nova and PDP.ll/60 computers, many small systems control to be passed to the top-level Teletype monitor, do not support the recursive features required by the where the device is allocated to this subject by means parser section of the compiler. An alternative to of the P(TTY) operation. the compiler is to cross-compile applications programs Control is then passed to the formatted I/O handler, on a timesharing system. which examines the ASCII string stored at FORMI one character at a time. When a format specifier (X,I,') is SUMMARY detected, control is passed to the appropriate lower level routine that performs code conversions based on This paper has described the internal algorithms and in-line format specifications. If data are required to control structures utilized in an operating system for complete this conversion, they are acquired from the computer-controlled psychology. Although the higher normal input stream. level language, PL/E, supported by the operating system Physical I/O is handled by the device drivers and is is fairly powerful, the simplicity of the underlying handled either a format field or a buffer at a time, system has acted to both simplify system implementa­ depending on the device. tion and aid in the validation of experimental programs. Timing considerations. Timing estimates for various operations within the PL/E system have varying degrees REFERENCES of accuracy, depending on the priority of the operation. Timing and response key related operations offer l-msec BRINCH HANSEN, P. The architecture of concurrent programs. accuracy because they are executed at the highest Englewood Cliffs, N.J: Prentice Hall, 1977. BURKHARDT, K. J. EMPP: An extensible multiprogramming priority and have a minimal amount of software over­ system for experimental psychology. Behavior Research head. Display refresh operations can also be accurately Methods & Instrumentation, 1976, 8, 239-244. controlled because external hardware insures a refresh BURKHARDT, K. J. PUE-An extensible higher level language for operation every 10 msec. True execution limits for low­ real-time systems application. Proceedings of the Fifth Inter­ national Symposium on Mini- and , 1977, priority operations such as data formatting and arith­ MIMI 77, 35-40. metic operations are more difficult to obtain due to the DIJKSTRA, E. W. Cooperating sequential processes. In F. Genuys multiprogrammed nature of the system. Theoretical (Ed.}, Programming languages. New York: Academic Press, execution times range from under 50 microsec to 1968. several hundred microseconds. The actual time required, HOARE, . A. Monitors: An operating system structuring concept. Communications ofthe ACM, 1974,10,549-557. however, varies significantly, depending on the number PALMER, J. C., McLEOD, C. M., & LOFTUS, G. . PLE: A high­ of subjects active. In the majority of cases with minimal level multiprogramming language for psychology. Behavior calculations, delays caused by multiple subjects are well ResearchMethods & Instrumentation, 1978, 10, 764-772. within the l-msec accuracy of the system. Some WIRTH, N. Modula: A language for modular multiprogramming. Software Practiceand Experience, 1977,1,3-35. problems have been encountered in attempting to minimize interdisplay intervals (cf. Palmer et al., 1978). This difficulty, however, is due primarily to display (Received for publication June 27,1979; hardware, rather than to a limitation of the software. revision accepted July 24,1979.)