Input and Output by lbMTmSZR

VIEWS: 19 PAGES: 28

									                    Input and Output

                     CS-3013 & CS502
                     Operating Systems
                       Summer 2006

CS-3013 & CS-502,         Input / Output   1
Summer 2006
                          Review
• Demand paging performance metrics
          • EAT: Effective access time
          • Faster computers require bigger working sets
          • TLB example


• VM Page replacement strategies
          • Name some …
• Swap-in strategies
          • Discuss …
CS-3013 & CS-502,           Input / Output     2
Summer 2006
                    Review (continued)
• Segmentation
          • A program-visible way to increase VM size
• Kernel memory
          • What is so special about this?


• I/O devices
          • Make or break issue for any system
          • Largest portion of code of OS
          • Most likely area for OS engineer to work in
CS-3013 & CS-502,            Input / Output      3
Summer 2006
                    Review (continued)
• Types of devices
     – Character, block, graphical, clocks & other
     – Controlling a device
          • Programmed I/O, Interrupt-driven, DMA




CS-3013 & CS-502,          Input / Output     4
Summer 2006
            Outline for this evening
•   I/O continued: device drivers
•   Network I/O
•   Programming Project #3
•   Disks




CS-3013 & CS-502,    Input / Output   5
Summer 2006
                    Device Drivers
•   Organization
•   Static or dynamic
•   Uniform interfaces to OS
•   Uniform buffering strategies
•   Hide device idiosyncrasies




CS-3013 & CS-502,       Input / Output   6
Summer 2006
                       Device Drivers
• Device Drivers are dependent on both the OS & device
• OS dependence
     – Meet the interface specs of the device independent layer
     – Utilize the facilities supplied by OS – buffers, error codes, etc.
     – Accept and execute OS commands – e.g. read, open, etc.
• Device Dependent
     – Actions during Interrupt Service routine
     – Translate OS commands into device operations
          • E.g read block n becomes a series of setting and clearing and
            interpreting device registers or interfaces
     – Note that some device drivers have layers
          • Strategy or policy part to optimize arm movement or do retries;
            plus a mechanism part the executes the operations

CS-3013 & CS-502,                 Input / Output            7
Summer 2006
       OS Responsibility to Device
                Driver
• Uniform API
          • Open, Close, Read, Write, Seek functions
          • ioctl function as escape mechanism
• Buffering
          • Kernel functions for allocating, freeing, mapping, pinning
            buffers
• Uniform naming
          • /dev/(type)(unit)
               – type defines driver; unit says which device
• Other
          • Assign interrupt level (IRQ)
          • Protection (accessibility by application, user-space routines)
          • Error reporting mechanism

CS-3013 & CS-502,                  Input / Output              8
Summer 2006
Uniform API and Buffering Example
    Memory-mapped Keyboard
• /dev/kb
• Device interrupt routine detects key transitions
• Driver converts sequence of transitions into
  characters in user’s written language
• Characters placed sequentially in buffer
          • Accessible by read()
• Application calls getchar() or get()
          • Library routines implemented with read()
          • Provides uniform input stream semantics


CS-3013 & CS-502,                  Input / Output      9
Summer 2006
                         Buffering
• DMA devices need memory to read from,
  write to
          • Must be contiguous pages
          • (Usually) physical addresses
• Double buffering
          • One being filled (or emptied) by device
          • Other being emptied (or filled) by application

          • Special case of producer-consumer with n = 2

CS-3013 & CS-502,            Input / Output     10
Summer 2006
              Installing Device Drivers
• Classic Unix
          • Create and compile driver to .o file
          • Edit and re-compile device table to add new device
          • Re-link with .o files for OS kernel  new boot file
• Classic MacIntosh
          • Submit to Apple for verification, approval, and inclusion
• MS-DOS and Windows
          •   Dynamic driver loading and installation
          •   Special driver-level debuggers available
          •   Open device environment
          •   Certification program for trademarking
• Linux
          • Originally static; now dynamic
CS-3013 & CS-502,                 Input / Output         11
Summer 2006
    Dynamic Device Configuration
•     At boot time:–
          1. Probe hardware for inventory of devices &
             addresses
          2. Map devices to drivers (using table previously
             created)
          3. Load necessary drivers into kernel space, register
             in interrupt vector (.sys files in Windows)
•     Run time:–
          1. Detect interrupt from newly added device
          2. Search for driver, or ask user; add to table
          3. Load into kernel space, register in interrupt
             vector
CS-3013 & CS-502,            Input / Output      12
Summer 2006
                    Probing for devices
• (Most) bridge and bus standards include
  registration protocol
          • [vendor, device ID]
• OS (recursively) tests every addressable
  connection
          • If device is present, it responds with own ID
• Performed both at
          • Boot time: to associate drivers with addresses
          • Installation time: to build up association table
CS-3013 & CS-502,            Input / Output      13
Summer 2006
      Alternative: Self-registration
• In systems where every module or class
  initializes itself
• At start-up time, each driver module is invoked
     – Checks for presence if device
     – If present, registers with OS its
          •   Name
          •   Interrupt handler
          •   Shutdown action
          •   Hibernate action
          •   Sleep action
          •   …
CS-3013 & CS-502,                 Input / Output   14
Summer 2006
Allocating and Releasing Devices
• Some devices can only be used by one
  application at a time
          • CD-ROM recorders
          • GUI interface
• Allocated at Open() time
• Freed at Close() time



CS-3013 & CS-502,         Input / Output   15
Summer 2006
              User Space I/O Software
              (Daemons and Spoolers)
• Device registers mapped into daemon VM
          • Controlled directly by daemon
• Lower-half service routine
          • Handles interrupts
          • Signals via semaphores or monitors
• Upper-half service routine
          • The daemon itself!
          • Waits for signals or monitors
          • Manages device and requests from outside kernel
CS-3013 & CS-502,           Input / Output       16
Summer 2006
              User Space I/O example
                   Print Spooler
• /dev/lpt is a ―virtual‖ device available to every process &
  user
• Driver causes
     – ―Printing‖ to spool file
     – Control info to spooler daemon
          • Printer selection, options, and parameters
• Spooler selects one print ―job‖ at a time
     – Prints from spool file to physical device
• Types of printing
     –   Simple character strings separated by \n characters
     –   Stream of PCL or inkjet commands
     –   Postscript file
     –   …
CS-3013 & CS-502,                  Input / Output        17
Summer 2006
                    Character Terminal
• Really two devices
          • Keyboard input
          • Character display output
• /dev/tty (Unix) or COM (Windows)
          • The classic input-output terminal
          • RS-232 standard
• Modes
          • raw
          • cooked (aka canonical) – with backspace correction, tab
            expansion, etc.
• Printed output vs. CRT display
CS-3013 & CS-502,               Input / Output        18
Summer 2006
           A special kind of Device
         The Graphical User Interface
• aka, the bitmapped display
          • In IBM language:– ―all points addressable‖
• 300K pixels to 2M pixels
• Each pixel may be separated written
• Collectively, they create
          • Windows
          • Graphics
          • Images
          • Videos
          • Games
CS-3013 & CS-502,           Input / Output     19
Summer 2006
          GUI Device — early days
                               • Bitmap in main memory
                               • All output via library routines to
                                 bitmap
                                         • Entirely (or mostly) in user space
                    CPU        • Controller, an automaton to do:–
                                         • D-A conversion (digital to analog video)
                                         • 60+ Hz refresh rate
                                         • ―clock‖ interrupt at top of each frame



          Main Memory
                                       Digital to
                          Bitmap        Analog

CS-3013 & CS-502,                  Input / Output            20
Summer 2006
   GUI Device — Displaying Text
• Font: an array of bitmaps, one per character
          • Designed to be pleasing to eye
• bitblt: (Bit-oriented Block Transfer)
          • An operation to copy a rectangular array of pixels from one
            bitmap to another



   A B CDE F …                                     Dog
                                                   Bitmap
                         bitblt


CS-3013 & CS-502,                 Input / Output       21
Summer 2006
                    GUI Device – Color
• Monochrome: one bit per pixel
          • foreground vs. background
• Color: 2-32 bits per pixel
• Direct vs. Color palette
          • Direct: (usually) 8 bits each per Red, Green, Blue
          • Palette: a table of length 2p, for p-bit pixels
                 Each entry (usually) 8 bits each for RGB



CS-3013 & CS-502,            Input / Output     22
Summer 2006
                    GUI Device – Cursor
• A small bitmap to overlay main bitmap
• Hardware support
          • Substitute cursor bits during each frame
• Software implementation
          • Bitblt area under cursor to temporary bitmap
          • Bitblt cursor bitmap to main bitmap
          • Restore area under cursor from temporary bitmap
• Very, very tricky!
          • Timing is critical for smooth appearance
          • Best with double-buffered main bitmap
CS-3013 & CS-502,            Input / Output     23
Summer 2006
                 GUI Device – Window
  • A virtual bitmap
            • size, position, clipping boundaries
            • font, foreground and background colors
            • A list of operations needed to redraw contents
  • Operations to window itself:–
            • write(), refresh()

Called by application to                  Called by window manager to
add/change information                    redraw current contents



  CS-3013 & CS-502,                Input / Output          24
  Summer 2006
      GUI Device — Text Window
• Character terminal emulated in a window
          • RS-232 character set and controls
          • /dev/tty
• Operates like a character terminal with
  visible, partially obscured, or completely
  covered



CS-3013 & CS-502,           Input / Output      25
Summer 2006
                    Modern GUI Devices
                                           Main
                                          Memory



           Level                                       AGP Port
                                                                     Graphics    Moni-
             2                CPU          Bridge
                                                                       card       tor
           cache

                    PCI bus                                  ISA          IDE
                                                            bridge        disk


    Ether-
             SCSI       USB
     net
                                                  ISA bus


                              Key-                          Sound
                    Mouse                      Modem                 Printer
                              board                          card

CS-3013 & CS-502,                     Input / Output                 26
Summer 2006
    Modern GUI Devices (continued)
                                                       Graphics     Moni-
         CPU                 Bridge
                                                         card        tor




• Double-buffered bitmap in Graphics card
          • Graphics and information written/drawn in back buffer
          • Monitor refreshes from main buffer (60+ Hz)
• Refresh interrupt at start of every frame
          • Bitblt to substitute cursor
• CPU writes text, etc.
• Graphics engine draws images, vectors, polygons
• Window manager orders redraw when necessary
CS-3013 & CS-502,                     Input / Output        27
Summer 2006
                     Break

                    Next Topic




CS-3013 & CS-502,     Input / Output   28
Summer 2006

								
To top