cs Lecture Introduction

Document Sample
cs Lecture Introduction Powered By Docstoc
					CS423UG Operating Systems

     Input/Output – IV

               Indranil Gupta
               Lecture 21
               Oct 14, 2005

   Clocks
   Power Management
   Disk Management

               CS 423UG - Operating Systems, Indranil
                             Gupta                      2
Clock Hardware
   Older/simpler clocks
       tied to the 110 or 220 volt power line and cause
        interrupt on every voltage cycle at 50-60 Hz.
   Current clocks consist of three components:
       a crystal oscillator
       a counter
       a holding register
       Feature:
           The quartz crystal generates a periodic signal of very
            high accuracy (several GHz). This signal is fed into the
            counter which counts down to zero. When the counter is
            zero, it causes a CPU interrupt. The holding register is
            used to load the counter.
                          CS 423UG - Operating Systems, Indranil
                                        Gupta                          3
Other Functions
   Preventing processes from running too long
     Whenever a process is started, the scheduler initializes a counter
      to the value of that process' quantum in clock ticks. As the clock
      ticks, the counter is decremented, and when counter is zero, the
      clock driver calls the scheduler to set up another process
   CPU accounting
     The system should start a second timer (different from the main
      timer). Whenever a process starts, the second timer starts
      counting. When a process stops, the timer can be read out to tell
      how long the process has run. When a process is interrupted, the
      timer value should be stored (where?) and when the process
      restarts, the timer value should be restored.
   Simpler way to do CPU accounting
     Currently running process keeps a field in the PCB. At every
      clock tick, this field in the current process is incremented, i.e.,
      every clock tick is ``charged'' to the process running at the time
   Disadvantages: other IO interrupts could skew this
                          CS 423UG - Operating Systems, Indranil
                                        Gupta                           4
Timer for Individual Process
   Providing timers (alarm) to requests from processes in order to
    give a warning after a certain time interval
     Process makes an alarm() system call specifying a time after
       which it should be sent a signal SIGALRM. When signal is
       received, the corresponding SIGALRM handler function specified
       by that process is run by the system
     If the clock driver had enough clocks, it could set a separate clock
       for each request. This is of course not the case.
   Simulate virtual clocks with a single physical clock.
     Maintain (a) table in which the signal time for all pending times is
       kept, and (b) a variable giving the time of the next one. When
       clock is updated, the driver checks for the closest signal to occur.
       When that has been signaled, the table is searched for the next
       one to occur.

                          CS 423UG - Operating Systems, Indranil
                                        Gupta                             5
Watchdog Timer and Profiling

   A timer is set, and when the timer goes off,
    instead of system executing a signal (as is
    the case for user signals), instead, the clock
    driver calls a procedure supplied by the caller
   Use it for profiling
       Build histogram of the program counter and see
        where it is spending its time.
       Accounting
       Debugging

                      CS 423UG - Operating Systems, Indranil
                                    Gupta                      6
Soft Timers
   Software-based timer, called soft timer, is a timer
       can be set to the requested frequency as needed
       is checked by the kernel when entries are made for other
        reasons such as system calls, TLB misses, page faults, I/O
        interrupts, CPU going idle
       if the soft timer has expired (find by polling the clock), the
        scheduled event is performed (e.g., packet transmission)
        with no need to switch to kernel mode
           the kernel resets the soft timer again to go off; the kernel
            copies the current clock value to the timer and adds the
            timeout interval to it
   Soft timer can avoid interrupts
       if kernel entries are written frequently, so is the soft timer
        checked more frequently
       frequency of soft timer could be as high as frequency of
        interrupts itself (without the cost of the interrupts)!
                            CS 423UG - Operating Systems, Indranil
                                          Gupta                            7
Power Management
   ENIAC - first general purpose electronic computer
    had 18,000 vacuum tubes and consumed 140,000
    watts of power.
   Invention of transistors dropped the power usage
    dramatically, and computer industry stopped
    considering power requirements for some time.
   Currently big change: mobile environments, mobile
    devices which run only on batteries (e.g., battery-
    powered computers laptops - IBM Think-pads,
    palmtops - Palm VII, HP Journadas, Webpads)
   Battery/Energy performance results do not follow the
    Moore's law (Moore's law = double performance of
    hardware such as processors, memory every 18
                    CS 423UG - Operating Systems, Indranil
                                  Gupta                      8
Approaches to reduce energy
   OS turns off parts of the computer when it is
    not in use (mostly I/O devices such as
   Have CPU connected to multiple voltage
    levels – select the right one (at run-time),
    under the current circumstances
       Application program uses less energy, possibly
        degrading quality of the user experience, but
        degrading it gracefully

                      CS 423UG - Operating Systems, Indranil
                                    Gupta                      9
File Systems

               CS 423UG - Operating Systems, Indranil
                             Gupta                      10
Disks First, Then File Systems

Form factor:       Form factor:                              Form factor:
 .5-1” 4” 5.7”    .4-.7”  2.7”  3.9”                      .2-.4”  2.1”  3.4”
Storage:           Storage:                                  Storage:
 18-73GB            4-27GB                                    170MB-1GB
                    CS 423UG - Operating Systems, Indranil
                                  Gupta                                         11
Magnetic Disk Capacity

 100,000                                                                3.5”

  10,000                                                                2.5”

     1,000                                                              1.8”


             80      84          88               92               96   00
                          CS 423UG - Operating Systems, Indranil
                                        Gupta                                  12
Disk Technology Trends
   Disks – the Mechanical Component
   Disks are getting smaller for similar capacity
       Spin faster, less rotational delay, higher bandwidth
       Less distance for disk head to travel (faster seeks)
       Lighter weight (for portables)
       Disk head getting closer to surface
   Disk data is getting denser
       More bits/square inch
       Tracks are closer together
       Doubles density every 12 months
   Disks are getting cheaper ($/MB)
       Factor of ~2 per year since 1991

                        CS 423UG - Operating Systems, Indranil
                                      Gupta                      13
Disk Organization
   Disk surface
       Circular disk coated with
        magnetic material
   Tracks
       Concentric rings around disk
        surface, bits laid out serially
        along each track
   Sectors
       Each track is split into arc of
        track (min unit of transfer)

                           CS 423UG - Operating Systems, Indranil
                                         Gupta                               14
Disk Organization (2)

   Fixed arc implies
       short inner sectors, long
        outer sectors (not true)
   Reality
       More sectors on outer

                       CS 423UG - Operating Systems, Indranil
                                     Gupta                               15
More on Disks
   CD’s and floppies come
    individually, but magnetic
    disks come organized in a
    disk pack
   Cylinder
       Certain track of the platter
   Most often – one disk
    arm+head per platter
   Disk arm
       Seek the right cylinder
       Disk rotates: disk arm moves
        horizontally and vertically
                                                       seek a cylinder
   Disk Head
       Read the data from surface

                            CS 423UG - Operating Systems, Indranil
                                          Gupta                          16
Disk Examples (Summarized Specs)

                                                  Seagate Barracuda IBM Ultrastar 72ZX
Capacity, Interface & Configuration
                        Formatted Gbytes                      28             73.4
                                   Interface            Ultra ATA/66    Ultra160 SCSI
                           Platters / Heads                  4/8             11/22
                          Bytes per sector                   512            512-528
   Max Internal transfer rate (Mbytes/sec)                      40           53
  Max external transfer rate (Mbytes/sec)                     66.6          160
          Avg Transfer rate( Mbytes/sec)                      > 15        22.1-37.4
         Multisegmented cache (Kbytes)                         512         16,384
         Average seek, read/write (msec)                        8            5.3
        Average rotational latency (msec)                     4.16          2.99
                     Spindle speed (RPM)                      7,200        10,000

                               CS 423UG - Operating Systems, Indranil
                                             Gupta                                      17
Disk Performance
   Seek
       Position heads over right cylinder, typically O(few ms), e.g.,
        5.3 ms. Slow (mechanical movement).
   Rotational delay
       Wait for a sector to rotate underneath the heads
       Typically 8.3  6.0 ms (7,200 – 10,000RPM) or ½ rotation
        takes 4.15-3ms. Slow (mechanical movement).
   Transfer bytes
       Average transfer bandwidth (15-37 Mbytes/sec). Fast(-er).
   Performance of transfer 1 KB
       Seek (5.3 ms) + half rotational delay (3ms) + transfer (0.04
       Total time is 8.34ms or 120 KB/sec!
   What block size can get 90% of the disk transfer
                          CS 423UG - Operating Systems, Indranil
                                        Gupta                        18
    Disk Behavior

   There are more sectors on
                                                        % of Disk Transfer
    outer tracks than on inner                   Size      Bandwidth
    tracks                                     (Kbytes)
     Read outer tracks: 37.4
       MB/sec                                       1KB           0.5%
     Read inner tracks: 22 MB/sec

   Seek time and rotational                        8KB           3.7%
    latency dominate the cost of
    small reads                                  256KB            55%
     A lot of disk transfer
       bandwidth is wasted for                     1MB            83%
       random lookups
     Need algorithms to reduce                    2MB            90%
       seek time
                         CS 423UG - Operating Systems, Indranil
                                       Gupta                             19

   Getting first byte from disk read is slow
       high latency due to seek time + rotational delay
   Peak bandwidth high, but is never achieved
   Improving performance
       Move some disk data into main memory – file
        system caching
       Reduce waster time by doing intelligent Disk

                      CS 423UG - Operating Systems, Indranil
                                    Gupta                      20
Disk Scheduling

   Multiple requests might be waiting for disk I/O
   Can’t do much about rotational latency
    (why?), but can try to minimize seek time
   Which disk request is serviced first?
       FCFS
       Shortest seek time first
       Elevator (SCAN)
       C-SCAN (Circular SCAN)
   Any look familiar?

                     CS 423UG - Operating Systems, Indranil
                                   Gupta                      21
    FIFO (FCFS) order
                                                                   Cylinder Numbers

   Method
     First come first served                       0              53                 199
   Pros
     Fairness among requests

     Works well with spatial locality

      of applications
   Cons
     Arrival may be on random

      spots on the disk (long seeks)
     Bad performance

                                                    98, 183, 37, 122, 14, 124, 65, 67

                          CS 423UG - Operating Systems, Indranil
                                        Gupta                                           22
SSTF (Shortest Seek Time First)

   Method
     Pick the one closest on disk                 0              53              199
      and service it

   Pros
     Minimizes seek time

     Cuts seek time by ½
      compared to FCFS
   Cons
     Starvation

   Question:                                      98, 183, 37, 122, 14, 124, 65, 67
     Can we avoid starvation?                     (65, 67, 37, 14, 98, 122, 124, 183)

                         CS 423UG - Operating Systems, Indranil
                                       Gupta                                         23
Elevator (SCAN)
   Method
     Go to the next closest request
                                                  0              53              199
      in the direction of travel
     Real implementations do not
      go to the end (called LOOK)
   Pros
     Bounded time for each request

   Cons
     Request at the other end will
      take a while – worst case
      could be bad
     A process could jump in with a
      request close to where the
      head is and in the “right”                 98, 183, 37, 122, 14, 124, 65, 67
      direction                                  (37, 14, 65, 67, 98, 122, 124, 183)
                        CS 423UG - Operating Systems, Indranil
                                      Gupta                                            24
C-SCAN (Circular SCAN)

   Method
       Like SCAN but in addition,                 0              53              199
        wrap around
       Real implementation
        doesn’t go to the end (C-
   Pros
       More uniform service time
   Cons
       Do nothing on the return trip
                                                   98, 183, 37, 122, 14, 124, 65, 67
                                                   (65, 67, 98, 122, 124, 183, 14, 37)
                         CS 423UG - Operating Systems, Indranil
                                       Gupta                                         25
History of Disk-related Concerns

   When memory was expensive
       Do as little book-keeping as possible
   When disks were expensive
       Get every last sector of usable space
   When disks became more common
       Make them much more reliable
   When processor got much faster
       Make the disk appear faster

                      CS 423UG - Operating Systems, Indranil
                                    Gupta                      26
Disk Versus Memory

Memory                                Disk
 Latency in 10’s of                   Latency in milliseconds

  processor cycles                     Transfer rate 5-50MB/s

 Transfer rate 300+MB/s               Contiguous allocation

 Contiguous allocation                 gains ~1000x
  gains ~10x

                 CS 423UG - Operating Systems, Indranil
                               Gupta                          27
On-Disk Caching
   Method
       Put a RAM chip on disk controller to cache blocks
           Seagate ATA disk has .5MB cache, IBM Ultra160 SCSI
            has 16MB cache
           Some of the RAM space stores “firmware” (a separate
       Blocks are replaced usually in LRU order
   Pros
       Good for reads if you have locality
   Cons
       Expensive
       Need to deal with reliable writes
                        CS 423UG - Operating Systems, Indranil
                                      Gupta                      28
   Compact Disk – Read Only Memory, Optical Disk
       1980 – Philips and Sony developed CD
   CD is prepared (WRITE OPERATION)
       Using a high-power infrared laser to burn 0.8 micron diameter holes in a
        coated glass master disk;
       From the master disk, mold is created, processed and reflective layer is
        deposited on polycarbonate;
       Data is written into a spiral track (22,188 revs, ~600 per mm)
       Depressions on the polycarbonate substrate are called pits, the unburned
        areas between pits are called lands
   CD is read (READ OPERATION)
       Low-power laser diode shines infrared light with a wavelength of 0.78 micron
        on pits and lands as they stream by.
       Laser is on the opposite side, so pits stick out as bumps in the flat surface.
       Pits and lands return different light to the player’s photodetector (pit and land
        reflect light with a phase difference), hence the player tells pit from land. Pit
        length is 0.6 micrometers.
       Pit/land and land/pit transitions represent 1, absence of transition is 0.
   CD-Recordable, CD-Rewritables, DVD, single or dual-sided

                               CS 423UG - Operating Systems, Indranil
                                             Gupta                                     29
RAID Architectures
   Use parallel processing to speed up CPU
   Use parallel I/O to improve disk performance,
    reliability (1988, Patterson)
   Design new class of I/O devices called RAID
    – Redundant Array of Inexpensive Disks
    (also Redundant Array of Independent Disks)
   Use the RAID in OS as a SLED (Single Large
    Expensive Disk), but with better performance
    and reliability
                  CS 423UG - Operating Systems, Indranil
                                Gupta                      30
RAID (cont.)
    RAID consists of RAID SCSI controller plus a box
     of SCSI disks
    Data are divided into stripes and distributed over
     disks for parallel operation
    RAID 0 …RAID 5 : different types of RAID systems
1.   RAID 0 organization writes consecutive stripes
     over the drives in round-robin fashion – operation
     is called striping
2.   RAID 1 organization uses striping and duplicates
     all disks
3.   RAID 2 uses words, even bytes and stripes across
     multiple disks. Also uses error codes, hence very
     robust scheme.
4.   RAID 3, 4, 5 are alterations of the previous ones
                    CS 423UG - Operating Systems, Indranil
                                  Gupta                      31
   Done with I/O!
   File systems next

   Reading for this lecture: Section 5.4
   Reading for next lecture: Chapter 6

   Reminder: MP2 due next Monday at 10 am!

                   CS 423UG - Operating Systems, Indranil
                                 Gupta                      32