Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.

Slides:



Advertisements
Similar presentations
Computer-System Structures Er.Harsimran Singh
Advertisements

More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Chap 2 System Structures.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage.
OS2-1 Chapter 2 Computer System Structures. OS2-2 Outlines Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
1/21/2008CSCI 315 Operating Systems Design1 Operating System Structures Notice: The slides for this lecture have been largely based on those accompanying.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage.
Module 1: Introduction What is an operating system?
OS Spring’03 Introduction Operating Systems Spring 2003.
Abhinav Kamra Computer Science, Columbia University 2.1 Operating System Concepts Silberschatz, Galvin and Gagne  2002 Chapter 2: Computer-System Structures.
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.
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
A. Frank - P. Weisberg Operating Systems Functional View of Operating System.
Chapter 2: Computer-System Structures
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
General System Architecture and I/O.  I/O devices and the CPU can execute concurrently.  Each device controller is in charge of a particular device.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 2: Operating-System Structures.
System Calls 1.
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
Chapter 1. Introduction What is an Operating System? Mainframe Systems
OS provide a user-friendly environment and manage resources of the computer system. Operating systems manage: –Processes –Memory –Storage –I/O subsystem.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 2: Operating-System Structures.
2.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Chapter 2: Computer-System Structures Computer System Operation I/O Structure.
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 2: Computer-System Structures Computer System Operation I/O Structure.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage.
Chapter 2: Computer-System Structures
Thanks to Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2 Computer-System Structures n Computer System Operation n I/O Structure.
1 CSE Department MAITSandeep Tayal Computer-System Structures Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection.
2: Computer-System Structures
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 2: Operating-System Structures Operating.
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.
Chapter 2: Computer-System Structures 2.1 Computer System Operation 2.5 Hardware Protection 2.6 Network Structure.
1 Chapter 2: Computer-System Structures  Computer System Operation  I/O Structure  Storage Structure  Storage Hierarchy  Hardware Protection  General.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 2: Operating-System Structures.
Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection Network Structure.
Operating Systems Lecture November 2015© Copyright Virtual University of Pakistan 2 Agenda for Today Review of previous lecture Hardware (I/O, memory,
Operating System Structure A key concept of operating systems is multiprogramming. –Goal of multiprogramming is to efficiently utilize all of the computing.
University of Pennsylvania 9/12/00CSE 3801 Processes, Interrupts, and System Calls CSE 380 Lecture Note 2 Insup Lee.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
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.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 2 Computer-System Structures Slide 1 Chapter 2 Computer-System Structures.
Silberschatz, Galvin and Gagne  Applied Operating System Concepts Chapter 2: Computer-System Structures Computer System Architecture and Operation.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 2: Operating-System Structures.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage.
Chapter 2: Computer-System Structures(Hardware) or Architecture or Organization Computer System Operation I/O Structure Storage Structure Storage Hierarchy.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage.
Chapter 2: Operating-System Structures
Chapter 2: Computer-System Structures(Hardware)
Chapter 2: Computer-System Structures
Protection of System Resources
Lecture 4: Operating System Structures
CS 3305 System Calls Lecture 7.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage.
Computer-System Architecture
Module 2: Computer-System Structures
Operating Systems Lecture 3.
Module 2: Computer-System Structures
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Chapter 2: Computer-System Structures
Chapter 2: Computer-System Structures
Module 2: Computer-System Structures
Module 2: Computer-System Structures
Presentation transcript:

Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls

Operating Systems 2 K. Salah Dual-Mode Operation Sharing system resources requires operating system to ensure that an incorrect program cannot cause other programs to execute incorrectly. Provide hardware support to differentiate between at least two modes of operations. 1.User mode – execution done on behalf of a user. 2.Monitor mode (also supervisor mode or system mode) – execution done on behalf of operating system.

Operating Systems 3 K. Salah Dual-Mode Operation (Cont.) Mode bit added to computer hardware to indicate the current mode: monitor (0) or user (1). –Part of EFLAG in x86 architecture –Part of PSW in Motorola architecture When an interrupt or fault occurs hardware switches to monitor mode. Privileged instructions can be issued only in monitor mode. All I/O instructions are privileged instructions. Must ensure that a user program could never gain control of the computer in monitor mode (I.e., a user program that, as part of its execution, traps if it executes a privileged instruction). monitoruser Interrupt/fault set user mode

Operating Systems 4 K. Salah Interrupts (fundamental concept) An interruption of the normal processing of processor. Interrupts are a mechanism for causing the CPU to suspend its current computation and take up some new task. Control may be returned to the original task at some time later. Reasons for interrupts (or traps): –control of asynchronous I/O devices –CPU scheduling –exceptional conditions (e.g., div. by zero, page fault, illegal instruction) arising during execution –user process requests for OS services Interrupts are essentially what drives an OS. We can view the OS as an event-driven system, where an interrupt is an event. By their very nature, interrupts need to be serviced carefully and quickly by the OS.

Operating Systems 5 K. Salah Interrupt Handling The servicing of an interrupt is known as interrupt handling. An integer is associated with each type of interrupt. When an interrupt occurs, the corresponding integer is supplied to the OS usually by the hardware (in a register). The OS maintains a table, known as the interrupt vector, that associates each interrupt's id with the starting address of its service routine. Example interrupt vector: Interrupt No.Interrupt Handler 0clock 1disk 2tty 3dev 4soft 5other

Operating Systems 6 K. Salah Typical interrupt handling sequence  Interrupt initiated by: I/O device signaling CPU, exceptional condition arising, execution of special instruction, etc.  CPU suspends execution of current instruction stream and saves the state of the interrupted process (on hardware stack).  State typically refers to contents of registers: PC, PSW, SP, general-purpose registers.  The cause of the interrupt is determined (and the unit no. of the interrupt, if applicable) and the interrupt vector is consulted in order to transfer control to the appropriate interrupt handler.  Interrupt handler performs whatever processing is necessary to deal with the interrupt.  Previous CPU state is restored (popped) from system stack, and CPU returns control to interrupted task.

Operating Systems 7 K. Salah EXAMPLE: Servicing a Timer Interrupt Timer device is used in CPU scheduling to make sure control is returned to system every so often (e.g., 1/60 sec.) Typically, timer has a single register that can be loaded with an integer indicating a particular time delay (# of ticks). Once loaded, timer counts down and when 0 is reached, an interrupt is generated. Interrupt handler might do the following: –update time-of-day information –signal any processes that are "asleep" and awaiting this alarm –call the CPU scheduler Control returns to user mode, possibly to a different process than the one executing when the interrupt occurred.

Operating Systems 8 K. Salah EXAMPLE: Servicing a Disk Interrupt When disk controller completes previous transfer, it generates an interrupt. Interrupt handler changes the state of a process that was waiting for just-completed transfer from wait-state to ready-state. It also examines queue of I/O requests to obtain next request. I/O is initiated on next request. CPU scheduler called. Control returned to user mode.

Operating Systems 9 K. Salah Priority Interrupts Some fast devices (e.g. disk, timer) must be serviced with stringent real-time constraints. Other, slower devices (e.g. TTY) need not be serviced as quickly. Failure to service fast devices soon enough may result in lost interrupts. The priority interrupt mechanism allows the interrupt handler of a slow device to be interrupted by a faster device, while blocking out interrupts from slower devices during execution of interrupt handler of a fast device. Machine Errors ClockHigher priority Disk Network Devices TerminalsLower Priority Software interrupts Typical Interrupt Levels

Operating Systems 10 K. Salah Priority Interrupt Mechanism How it works: –CPU status register (PSW) contains bits specifying processor priority (or execution) level. –Each device has an associated device priority level. A device may cause an interrupt only when its priority level is higher than the current processor priority level. –Interrupt handler for a device executes at processor priority equal to device priority. –Effect: An interrupt handler can only be interrupted by devices of higher priority.

Operating Systems 11 K. Salah System Calls Provide "direct access" to operating system services (e.g., file system, I/O routines, memory allocate & free routines) by user programs. System calls execute instructions that control the resources of the computer system, e.g., I/O instructions for devices. We want such privileged instructions to be executed only by a system routine, under the control of the OS! As we will see, system calls are special, and in fact, are treated as a special case of interrupts. Programs that make system calls were traditionally called "system programs" and were traditionally implemented in assembly language.

Operating Systems 12 K. Salah System Call Scenario (cont.) User program File system memory Operating System User program is confined! I/O devices

Operating Systems 13 K. Salah API vs. System Calls Mostly accessed by programs via a high-level Application Program Interface (API) rather than direct system call use Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based systems (including virtually all versions of UNIX, Linux, and Mac OS X), and Java API for the Java virtual machine (JVM) Why use APIs rather than system calls?

Operating Systems 14 K. Salah Example of Standard API Consider the ReadFile() function in the Win32 API—a function for reading from a file A description of the parameters passed to ReadFile() –HANDLE file—the file to be read –LPVOID buffer—a buffer where the data will be read into and written from –DWORD bytesToRead—the number of bytes to be read into the buffer –LPDWORD bytesRead—the number of bytes read during the last read –LPOVERLAPPED ovl—indicates if overlapped I/O is being used

Operating Systems 15 K. Salah API – System Call – OS Relationship

Operating Systems 16 K. Salah Standard C Library Example C program invoking printf() library call, which calls write() system call

Operating Systems 17 K. Salah System Call Implementation Typically, a number associated with each system call –System-call interface maintains a table indexed according to these numbers The system call interface invokes intended system call in OS kernel and returns status of the system call and any return values The callers need know nothing about how the system call is implemented –Just needs to obey API and understand what OS will do as a result call –Most details of OS interface hidden from programmer by API  Managed by run-time support library (set of functions built into libraries included with compiler)

Operating Systems 18 K. Salah System Calls (cont.) Now, system calls can be made from high-level languages, such as C and Modula-2 (to a degree). Unix has about 32 system calls: read(), write(), open(), close(), fork(), … using trap instructions: –i = read(fd,80, buffer) push buffer push 80 push fd trap read pop i Each system call had a particular number. Instruction set has a special instruction for making system calls: SVC (IBM 360/370) trap (PDP 11) tw(PowerPC) - trap word tcc(Sparc) break(MIPS)

Operating Systems 19 K. Salah Further Reading Why use APIs rather than system calls?