DOC PREVIEW
UNO CSCI 8530 - QNX and POSIX Input/Output

This preview shows page 1-2 out of 7 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

11CSCI 8530Advanced Operating SystemsQNX and POSIX Input/Output2What is POSIX?POSIX: Portable Operating System InterfaceGoal: source code portability of applicationsPOSIX consists of groups working on different parts of the entire set of standardsPOSIX.1 provides most of the basic features (similar to UNIX)POSIX.4 adds real-time functionality3Real-World Input/OutputTypical 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.4ExamplesNewer 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.5Input/OutputI/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.6Examples of I/OData gathering from devices, where a device is some weird piece of hardware associated with the real worldData output to devicesData logging, usually to diskMultimedia playback and recordingDatabase operationsUser I/O (keyboards, mice, etc.)27I/O CharacteristicsSometimes real-time I/O is as simple as normal UNIX I/O: standard readand writesystem calls suffice.Real-time adds other concerns and demands:I/O should not block a task unnecessarilyKnowing when data is actually safely on diskNeed for fast, predictable I/O subsystem performance8Problems with UNIX I/OThe 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)9UNIX 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 real-time systems are designed to perform asynchronous I/O.10UNIX 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.11UNIX I/O Deficiencies (3)Doing “other things” to devices in UNIX uses ioctlwhich 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 providesioctlcalls 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.)(FYI: fcntlis used for individual file control, ioctlis used for device control.)12UNIX Facilities for Real-Time I/Oselect (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 hocsolutions (e.g. accessing the raw disk).313The Select System Callselect(pollin 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.14Typical Application (1)A simple terminal emulator application will have four file descriptors to deal with:KeyboardDisplayModem (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.15Typical Application (2)The problem in this application is which of the input file descriptors to read first.If a readis 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 readis issued for the modem, and the first data comes from the keyboard.16select (ns, *rfds, *wfds, *xfds, *tout);ns= 1 larger than the largest file descriptor in the setsrfds= 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.17File Descriptor SetsFor 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.18File 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? */419struct timevalstruct timeval {long tv_sec; /* seconds */long tv_usec; /* microseconds */};This declaration is actually found in <sys/time.h>, but included in <sys/select.h>Although times can be specified to microsecond granularity, the system does not support arbitrary timing accuracy.20Timeout CharacteristicsA NULL value for tout indicates an infinite timeout interval (no timeout).A pointer to a struct timeval that


View Full Document

UNO CSCI 8530 - QNX and POSIX Input/Output

Download QNX and POSIX Input/Output
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view QNX and POSIX Input/Output and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view QNX and POSIX Input/Output 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?