® 10-2 Exceptions, Interrupts, and Timers 10.1Exception Handling and Signals Interrupt Service Routines Timers.

Slides:



Advertisements
Similar presentations
1 Exceptions, Interrupts & Traps Operating System Hebrew University Spring 2007.
Advertisements

Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
Architectural Support for Operating Systems. Announcements Most office hours are finalized Assignments up every Wednesday, due next week CS 415 section.
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
04/16/2010CSCI 315 Operating Systems Design1 I/O Systems Notice: The slides for this lecture have been largely based on those accompanying an earlier edition.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Threads and Scheduling 6.
I/O Systems CS 3100 I/O Hardware1. I/O Hardware Incredible variety of I/O devices Common concepts ◦Port ◦Bus (daisy chain or shared direct access) ◦Controller.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Process Description and Control A process is sometimes called a task, it is a program in execution.
Exceptions, Interrupts & Traps
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
1 Computer System Overview Chapter 1 Review of basic hardware concepts.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
MICROPROCESSOR INPUT/OUTPUT
Hardware Definitions –Port: Point of connection –Bus: Interface Daisy Chain (A=>B=>…=>X) Shared Direct Device Access –Controller: Device Electronics –Registers:
I/O Systems I/O Hardware Application I/O Interface
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Tami Meredith, Ph.D. CSCI  Devices need CPU access  E.g., NIC has a full buffer it needs to empty  These device needs are often asynchronous.
Interrupts, Buses Chapter 6.2.5, Introduction to Interrupts Interrupts are a mechanism by which other modules (e.g. I/O) may interrupt normal.
Chapter 13: I/O Systems. 13.2/34 Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware.
NT Kernel CS Spring Overview Interrupts and Exceptions: Trap Handler Interrupt Request Levels and IRT DPC’s, and APC’s System Service Dispatching.
Time Management.  Time management is concerned with OS facilities and services which measure real time, and is essential to the operation of timesharing.
Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
1 CSE451 Architectural Supports for Operating Systems Autumn 2002 Gary Kimura Lecture #2 October 2, 2002.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
UNIX Signals * POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm * Interval Timers * POSIX.1b Timers *
Operating Systems Recitation 4, April th, 2002 Signals.
1 VxWorks 5.4 Group A3: Wafa’ Jaffal Kathryn Bean.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
1 Lecture 1: Computer System Structures We go over the aspects of computer architecture relevant to OS design  overview  input and output (I/O) organization.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 13: I/O Systems Overview I/O Hardware Application.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
1 Process Description and Control Chapter 3. 2 Process A program in execution An instance of a program running on a computer The entity that can be assigned.
Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 12: I/O Systems I/O hardwared Application I/O Interface Kernel I/O.
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
Operating System Concepts
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Lecture 8 Task Utilization. Theoretical Analysis.
Of Privilege, Traps, Interrupts & Exceptions Prof. Sirer CS 316 Cornell University.
UNIX signals.
Exceptional Control Flow
Module 12: I/O Systems I/O hardware Application I/O Interface
Interrupts and signals
Topics Covered What is Real Time Operating System (RTOS)
Exceptional Control Flow
Exceptional Control Flow: System Calls, Page Faults etc.
Structure of Processes
Processor Fundamentals
I/O Systems I/O Hardware Application I/O Interface
Operating System Concepts
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Module 12: I/O Systems I/O hardwared Application I/O Interface
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

® 10-2 Exceptions, Interrupts, and Timers 10.1Exception Handling and Signals Interrupt Service Routines Timers

® 10-3 Exception Handling Overview An exception is an unplanned event generated by the CPU. Examples include: trap or breakpoint instruction, divide by zero, floating point or integer overflow, illegal instruction, or address error. An exception will generate an “internal” interrupt. VxWorks installs exception handlers at system startup. These handlers will run on an exception and will try to invoke a user-defined exception handler. A VxWorks exception handler communicates with a user tasks by sending a signal. The user-installed handler will then run.

® 10-4 Signals

® 10-5 UNIX: UNIX vs. VxWorks Signals Signal is ignored if no handler is installed. “Automatic function restarting” Can install a handler to catch SIGKILL. No SIGCHLD, SIGPIPE, or SIGURG. EINTRERROR taskDelay( ) sets errno = EINTR and returns ERROR if interrupted by a signal.

® 10-6 Caveats not Signals are not recommended for general intertask communication. A signal: –May be handled at too high a priority if it arrives during a priority inheritance. –Disrupts a task’s normal execution order. (It is better to create two tasks than to multiplex processing in one task via signals.) –Can cause reentrancy problems between a task running its signal handler and the same task running its normal code. –Can be used to tell a task to shut itself down. sigLib sigLib contains both POSIX and BSD UNIX interfaces. Do not mix them.

® 10-7 Registering a Signal Handler To register a signal handler: signal (signo, handler) signoSignal number. handlerRoutine to invoke when signal arrives (or SIG_IGN to ignore signal). Returns the previously installed signal handler, or SIG_ERR. The signal handler should be declared as: void sigHandler (int sig); /* signal number */

® 10-8 Signals and Exceptions Hardware exceptions include bus error, address error, divide by zero, floating point overflow, etc.. Some signals correspond to exceptions (e.g., SIGSEGV corresponds to a bus error on a 68k; SIGFPE corresponds to various arithmetical exceptions).

® 10-9 The Signal Handler If an exception signal handler returns: –The offending task will be suspended. –A message will be logged to the console. Exception signal handlers typically call: –exit( ) to terminate the task, or –taskRestart( ) to restart the task, or –longjmp( ) to resume execution at location saved by setjmp(

® Exceptions, Interrupts, and Timers Exception Handling and Signals 10.2Interrupt Service Routines Timers

® Interrupts Interrupts allow devices to notify the CPU that some event has occurred. A user-defined routine can be installed to execute when an interrupt arrives. not This routine runs at interrupt time. It is not a task. On-board timers are a common source of interrupts. Using them requires understanding interrupts.

® Device Drivers Use interrupts for asynchronous I/O. Are beyond the scope of this course. For more information: intArchLib intArchLibTo install user defined ISR’s. Board Support Package Board Support PackageBoard-specific interrupt handling. Programmers Guide Programmers GuideArchitecture specific interrupt info. Tornado User’s Guide Tornado User’s GuideSystem mode debugging info. BSP Porting Kit BSP Porting Kit Optional product for writing BSP’s. VxWorks Device Driver Workshop VxWorks DeviceWrite VMEbus and VxWorks Driver Workshopstandard device drivers. Tornado BSP Training Workshop Tornado BSP BSP-specific interrupt issues, such Training Workshop as interrupt controllers and busses.

® Interrupt Handling Example (68k)

® Interrupt Handling Example (PowerPC)

® Displaying the Interrupt Vector Table To show the interrupt vector table from the Browser, choose Vector Table in the selector box (Windows), or click on the Interrupt button (UNIX).

® Interrupts and Priorities

® Interrupt Stack Most architectures use a single dedicated interrupt stack. Interrupt stack is allocated at system start-up. The interrupt stack size is controlled by the macro INT_STACK_SIZE; default value defined in configAll.h. Must be large enough for worst-case nesting. Interrupt Stack

® ISR Restrictions No tasks can run until ISR has completed. ISR’s are restricted from using some VxWorks facilities. In particular, they can’t block: –Can’t call semTake( ). –Can’t call malloc( ) (uses semaphores). –Can’t call I/O system routines (e.g., printf( )). are The Programmer’s Guide gives a list of routines which are callable at interrupt time.

® ISR Guidelines Keep ISR’s short, because ISR’s: –Delay lower and equal priority interrupts. –Delay all tasks. –Can be hard to debug. Avoid using floating-point operations in an ISR. –They may be slow. –User must call fppSave( ) and fppRestore( ). Try to off-load as much work as possible to some task: –Work which is longer in duration. –Work which is less critical.

® Typical ISR Reads and writes memory-mapped I/O registers. Communicates information to a task by: –Writing to memory. –Making non-blocking writes to a message queue. –Giving a binary semaphore.

® Debugging ISR’s To log diagnostic information to the console at interrupt time: logMsg (“foo = %d\n”, foo, 0, 0, 0, 0, 0); Sends a request to tLogTask to do a printf( ) for us. Similar to printf( ), with the following caveats: –Arguments must be 4 bytes. –Format string plus 6 additional arguments. Use a debugging strategy which provides system-level debugging: –WDB agent. –Emulator.

® Exceptions at Interrupt Time Cause a trap to the boot ROM’s. Logged messages will not be printed. Boot ROM program will display an exception description on reboot. An exception occurring in an ISR will generate a warm reboot. Can use sprintf( ) to print diagnostic information to memory not overwritten on reboot, if necessary.

® Exceptions, Interrupts, and Timers Exception Handling and Signals Interrupt Service Routines 10.3Timers

® Timers On-board timers interrupt the CPU periodically. Timers allow user-defined routines to be executed at periodic intervals, which is useful for: –Polling hardware. –Checking for system errors. –Aborting an untimely operation. VxWorks supplies a generic interface to manipulate two timers: –System clock. –Auxiliary clock (if available).

® System Clock System clock ISR performs book-keeping: –Increments the tick count (use tickGet( ) to examine the count). –Updates delays and timeouts. –Checks for round-robin rescheduling. These operations may cause a reschedule. Default clock rate is 60hz. sysClkRateSet (freq)Sets the clock rate. int sysClkRateGet( )Returns the clock rate. sysClkRateSet( ) should only be called at system start-up.

® Watchdog Timers Watchdog Timers User interface to the system clock. Allows a C routine to execute after a specified time delay. Upon expiration of delay, connected routine runs. –As part of system clock ISR. –Subject to ISR restrictions.

® Creating Watchdog Timers To create a watchdog timer: WDOG_ID wdCreate () NULL Returns watchdog id, or NULL on error. To start (or restart) a watchdog timer: STATUS wdStart (wdId, delay, pRoutine, parameter) wdIdWatchdog id, returned from wdCreate( ). delayNumber of ticks to delay. pRoutineRoutine to call when delay has expired. parameterArgument to pass to routine.

® Using Watchdogs To use watchdogs for periodic code execution: The doit( ) routine might: –Poll some hardware device. –Unblock some task. –Check if system errors are present. wdId = wdCreate(); wdStart (wdId, DELAY_PERIOD, myWdIsr, 0); void myWdIsr(int param) { doit (param); wdStart (wdId, DELAY_PERIOD, myWdIsr, param); }

® Missed Deadlines To recover from a missed deadline: WDOG_ID wdId; void foo(void) { wdId = wdCreate( ); /* Must finish each cycle in under 10 seconds */ FOREVER { wdStart (wdId, DELAY_10_SEC, fooISR, 0); fooDoWork( ); } void fooISR (int param) { /* Handle missed deadline */... }

® Stopping Watchdogs To cancel a previously started watchdog: STATUS wdCancel (wdId) To deallocate a watchdog timer (and cancel any previous start): STATUS wdDelete (wdId)

® Watchdog Browser After creating, but prior to activating the watchdog, the Browser provides minimal information: After activating the watchdog, more useful information is provided:

® Polling Issues Can poll at task time or interrupt time. –Interrupt time polling is more reliable. –Task time polling has a smaller impact on the rest of the system. To poll at task time, there are two options: –taskDelay( ) : faster, but may “drift”. –wdStart( ) + semGive( ) : more robust.

® Polling Caveats The following code is accurate only if the system clock rate is a multiple of 15hz: Do not set the system clock rate too high, because there is OS overhead in each clock tick. Use auxiliary clock to poll at high speeds. void myWdISR ( ) { wdStart (myWdId, sysClkRateGet()/15, myWdISR, 0); pollMyDevice(); }

® Auxiliary Clock For high speed polling, use the auxiliary clock. Precludes using spy, which also uses the auxiliary clock. Some routines to manipulate auxiliary clock: sysAuxClkConnect( )Connect ISR to Aux clock. sysAuxClkRateSet( )Set Aux clock rate. sysAuxClkEnable( )Start Aux clock. sysAuxClkDisable( )Stop Aux clock.

® Summary Using signals for exception handling: –signal( ) –exit( ) –taskRestart( ) –longjmp( ) Interrupt Service Routines have a limited context: –No Blocking –No I/O system calls

® Summary Polling with timers: Interrupt time task time wd timer aux clock taskDelay, or wd timer + semGive low speed high speed