1 / 26

Input/Output - III

CS423UG Operating Systems . Input/Output - III. Indranil Gupta Lecture 20 Oct 12, 2005. Content. I/O Software Clock and timer Power management. Review. I/O software Three ways to do I/O Programmed I/O Interrupt-based I/O I/O using DMA

odell
Télécharger la présentation

Input/Output - III

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS423UG Operating Systems Input/Output - III Indranil Gupta Lecture 20 Oct 12, 2005

  2. Content • I/O Software • Clock and timer • Power management CS 423UG - Operating Systems, Indranil Gupta

  3. Review • I/O software • Three ways to do I/O • Programmed I/O • Interrupt-based I/O • I/O using DMA • Device driver • User-space I/O system calls CS 423UG - Operating Systems, Indranil Gupta

  4. I/O Software Layers of the I/O system and the main functions of each layer (typical) CS 423UG - Operating Systems, Indranil Gupta

  5. Device Independent Layer: Error Reporting • Programming I/O Errors • These errors occur when a process asks for something impossible (e.g., write to an input device such as keyboard, or read from output device such as printer). • Actual I/O Errors • Errors occur at the device level (e.g., read disk block that has been damaged, or try to read from video camera which is switched off) • The device-independent I/O software detects such errors and reports them to the user-space I/O layer. CS 423UG - Operating Systems, Indranil Gupta

  6. Allocating and releasing Dedicated Devices • Some devices can be used only by one process at any given time • e.g., CD-ROM recorders, some audio devices • Two approaches: • Perform open() on the special file for devices directly. If device is not available, open() fails and returns error code. • A process requests a device. If it is not available, the process is blocked, waiting until the device become available again (e.g., through a semaphore). CS 423UG - Operating Systems, Indranil Gupta

  7. Device-Independent Block Size • Different disks have different sector sizes. • The device independent IP software should hide this fact and provide one uniform block size to higher layers. May be same as page size on paged VM systems. • E.g., support same page size for all applications while supporting multiple device types • Translate E.g., if page size=10 KB and disk block size is 1 KB, on page fault, use DMA to fetch 10 disk blocks. CS 423UG - Operating Systems, Indranil Gupta

  8. I/O Software Layers of the I/O system and the main functions of each layer (typical) CS 423UG - Operating Systems, Indranil Gupta

  9. User-Space I/O Software Layer • Applications in user space make I/O system calls to access I/O. • I/O system calls are normally made by library procedures. • Steps to perform an I/O system call: • User-space library calls the device-independent I/O software • Device-independent I/O software calls the corresponding device driver • Device driver accesses the device controller and through it the corresponding device. CS 423UG - Operating Systems, Indranil Gupta

  10. More on System Calls • Interface between running application and operating system • Assembly language macros or subroutines • Need to use an SVC instruction (huh?) • Pass parameters through registers, in memory tables, or on stack • Unix has about 32 system calls: • read(), write(), open(), close(), fork(), exec(), ioctl(), CS 423UG - Operating Systems, Indranil Gupta

  11. How System Calls Work 1.SVC Causes a Trap (SVC=supervisor call, an instruction) 2.System Privilege Mode Entered 3.Trap Handler Decodes Which SVC 4.Branch to System Function 5.Access Arguments From the Stack CS 423UG - Operating Systems, Indranil Gupta

  12. Animation User State Program requests system call SVC Arguments Program pushes arguments Program does SVC Process Stack Access arguments System Stack Select which system routine Interrupt Vector Enter Supervisor State CS 423UG - Operating Systems, Indranil Gupta

  13. How System Calls Return 6.Push Results on the Stack 7.Return to Trap Handler 8.Resume Application Privilege Mode 9.Return to Instruction Following SVC CS 423UG - Operating Systems, Indranil Gupta

  14. Animation User State Program returns from system call SVC return Arguments Process Stack OS pushes return arguments Complete system routine System Stack Supervisor State OS does return CS 423UG - Operating Systems, Indranil Gupta

  15. Blocking and Non-blocking I/O • When an application calls a blocking system call, the execution of the application is suspended. • The application waits for the I/O result. • But I/O decide may take very long… • Alternative: Non-blocking I/O system call CS 423UG - Operating Systems, Indranil Gupta

  16. Asynchronous System Calls X • An asynchronous system call returns immediately, without waiting for the I/O to complete. • The application continues to execute its code and the completion of the I/O call is communicated to the application in the future (how? Through an upcall, which is an application defined function but called by the kernel) • Multi-threaded applications benefit from non-blocking system calls CS 423UG - Operating Systems, Indranil Gupta

  17. Spooling • Another way to do I/O is the spooling system. • SPOOL=Simultaneous Peripheral Operation On-Line • Spooling is an approach to deal with I/O devices in a multiprogramming system • Example: printer (spooled device) • Spooling includes a special process, called daemon, and a special directory, called spooling directory. • Example: To print a file, the printing process creates the entire file, puts it in the spooling directory, and the daemon then takes out the file and prints it. CS 423UG - Operating Systems, Indranil Gupta

  18. Performance • Heavy demands on CPU to execute device driver code and to schedule processes fairly and efficiently as they block and unblock. • Several principles to improve the efficiency of I/O: • reduce the number of context switches • reduce the number of times that data must be copied in memory while passing between device and application • reduce frequency of interrupts (user large transfers, smart controllers, polling, etc) • increase concurrency by using DMA controllers • move processing primitives into hardware • balance CPU, memory subsystem, bus and I/O performance • Use caching • Place to implement I/O functionality • device hardware, device driver, kernel, or application? • Device-functionality progression: the lower level implementation, the better performance, efficiency, however also increased development cost, and decreased flexibility. CS 423UG - Operating Systems, Indranil Gupta

  19. Clocks and Timers • Clocks (also called timers) • give the current time • give the elapsed time • set a timer to trigger operation X at time T • Programmable interval timer - hardware to measure elapsed time and trigger operations • Clock is used by the scheduler (for preemptive scheduling), time of day, raising alarms, monitoring CS 423UG - Operating Systems, Indranil Gupta

  20. 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

  21. Programmable Clock • Modes of programmable clocks: • one-shot mode: when the clock starts (started explicitly by the software), it copies the register value into the counter, decrements the counter, causes an interrupt when counter is zero, and stops (so it needs to be restarted by the s/w) • square-wave mode: when the clock starts, it copies the register value into the counter, decrements the counter, causes an interrupt when counter is zero, and then automatically the holding register value is copied into the counter, and the whole process repeats (i.e., there is no explicit start of the clock by the software) • The periodic interrupts are called clock ticks (hey, you know that already!) • Programmable clock chips usually contain two or three independently programmable clocks (why?). CS 423UG - Operating Systems, Indranil Gupta

  22. Clock Issues • Battery-powered backup clocks • Some clocks drift away and need to be resynchronized. • Manually resynchronize the clocks. • Automatically and periodically get the current time from a remote host which carries the UTC (Universal Coordinated Time ), formally known as Greenwich Mean Time). • NTP (Network Time Protocol) is a standard protocol to re-synchronize clocks between two networked systems automatically CS 423UG - Operating Systems, Indranil Gupta

  23. Clock Software • Clock hardware generates interrupts at known intervals. • The clock hardware is served by the (surprise!) clock device driver software • Functions of the clock driver: • Maintaining the time of day • Preventing processes from running longer than they are allowed to • Accounting for CPU usage • Responding to processes that have requested an alarm (through a prior system call) • Providing watchdog timers for parts of the system itself • Profiling, monitoring and statistics gathering CS 423UG - Operating Systems, Indranil Gupta

  24. Clock Overflow (or Y2-what?) • Time of the day(real clock): requires incrementing a counter at each clock tick. • One difficulty is the overflow of the counter (e.g., a 32-bit 10 ms-tick counter overflows in a few weeks!). • Solutions: • Use 64 bit counter (maintaining the counter is more expensive) • Maintain the time of day in seconds, rather than ticks, using a subsidiary counter to counter ticks until a whole second has been accumulated. A 32-bit seconds clock will work for about 46,000 years before overflow • Count ticks, but only relative to the time the system was booted, rather than relative to a fixed external source • Disadvantage? CS 423UG - Operating Systems, Indranil Gupta

  25. 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 accounting CS 423UG - Operating Systems, Indranil Gupta

  26. Reminders • Reading for this lecture: Sections 5.0-5.3, 5.5 • Reading for next lecture: Section 5.4 • Midterm is graded, can be collected from TA office (1115 SC) during TA office hours • Max 45 points • Average : 35.28 (high!) Median : 36 (high!) • Std Dev : 5.13 • Highest : 44.5 Lowest : 24 • Midterm solutions on website. CS 423UG - Operating Systems, Indranil Gupta

More Related