What is POSIX CSCI 8530 Advanced Operating Systems QNX and POSIX Input Output Real World Input Output Typical university courses deal with input output that s concerned with building software tools that interface with other software But there s almost certainly more real world input output going on than general tools programming Input Output I O is inherently messy If a program doesn t have to deal with the real world then it s generally easier to understand and less liable to break Unfortunately this also means the program is much less likely to be useful In real time applications I O is everything Without the real world there is no real time POSIX Portable Operating System Interface Goal source code portability of applications POSIX consists of groups working on different parts of the entire set of standards POSIX 1 provides most of the basic features similar to UNIX POSIX 4 adds real time functionality Examples Newer vehicles are full of microprocessors with some sort of operating system running everything from the ignition to the brakes VCRs CD DVD players stereo and television receivers and the like all are microprocessor controlled ATMs are obviously controlled by computers Examples of I O Data gathering from devices where a device is some weird piece of hardware associated with the real world Data output to devices Data logging usually to disk Multimedia playback and recording Database operations User I O keyboards mice etc 1 I O Characteristics Sometimes real time I O is as simple as normal UNIX I O standard read and write system calls suffice Real time adds other concerns and demands I O should not block a task unnecessarily Knowing when data is actually safely on disk Need for fast predictable I O subsystem performance UNIX I O Deficiencies 1 UNIX I O is not synchronized While it is synchronous you really don t know when data is actually written to disk for example Q Why is this true UNIX I O is synchronous You wait until the I O completes A read for example will block a process until the requested data is in the buffer or an error occurs Many realtime systems are designed to perform asynchronous I O UNIX I O Deficiencies 3 Doing other things to devices in UNIX uses ioctl which has potential problems for real time use It s not standard for real world devices although it usually is pretty standard for typical devices It only allows you to do what the driver provides ioctl calls the OS kernel incurring the significant overhead associated with a kernel call Mapping device registers into application memory might work but might require supervisor permission and interrupt handlers Problems with UNIX I O The UNIX I O model is simple and this is one of its most power features After you issue a write you know that data is delivered to the destination but you don t know or usually care how that happened You don t know how long your process is blocked if at all You don t have control of the shape of the underlying file e g block addresses UNIX I O Deficiencies 2 File geometry is hard or impossible to control In UNIX a file is just an unstructured stream of bytes you don t know how it s laid out on disk While UNIX tries to optimize performance there are no guarantees about block placement Real time applications must be able to control geometry to guarantee speed of access e g contiguous blocks and speed of allocation e g preallocation of disk blocks neither of which can be guaranteed with UNIX UNIX Facilities for Real Time I O select BSD and poll System V can be used to avoid unnecessary blocking sync and fsync can be used to cause synchronous writing of data to a disk Controlling file geometry can be done with ad hoc solutions e g accessing the raw disk FYI fcntl is used for individual file control ioctl is used for device control 2 The Select System Call select poll in System V allows a process to wait for any of a set of I O related actions to occur not in POSIX but in QNX This is useful when dealing with pipes network sockets or special devices like terminals I O to or from these devices depends on when someone puts data into them Typical Application 2 The problem in this application is which of the input file descriptors to read first If a read is issued for the keyboard and data arrives first at the modem then the incoming modem data can t be displayed until a key is pressed because the application is blocked on the first read The inverse problem occurs if the first read is issued for the modem and the first data comes from the keyboard File Descriptor Sets For select sets of file descriptors in which we re interested must be created The type used for each of these sets is fd set found in the header file sys select h Prior to using select each of the sets is established using macros also in select h On return the sets are changed to indicate interesting file descriptors Any of the pointers to sets may be NULL Typical Application 1 A simple terminal emulator application will have four file descriptors to deal with Keyboard Display Modem input Modem output The basic algorithm is to copy data from the keyboard to the modem output and to copy data from modem input to the display select ns rfds wfds xfds tout ns 1 larger than the largest file descriptor in the sets rfds set of descriptors to test for reading or NULL rfds set of descriptors to test for writing or NULL xfds set of descriptor to test for exceptions or NULL tout struct timeval with timeout interval or NULL On return the sets are replaced with those indicating which descriptors are ready The call returns the number of ready descriptors File Descriptor Set Manipulation include sys select h FD SETSIZE largest fd number allowed fd set fds declare a set FD ZERO fds clear a set FD SET fd fds add fd to fds FD CLR fd fds remove fd FD ISSET fd fds is fd in fds 3 struct timeval struct timeval long tv sec long tv usec Timeout Characteristics A NULL value for tout indicates an infinite timeout interval no timeout A pointer to a struct timeval that has a 0 value is used to perform a polling operation that is sample all the file descriptors of interest and return a result immediately there is no blocking Finally a non zero struct timeval value is used to specify a finite timeout interval QNX modifies the struct timeval object to indicate the time remaining before timeout would occur This is not done by all UNIX like systems seconds microseconds This declaration is actually found in sys time h but included in sys select h Although
View Full Document
Unlocking...