NT Kernel CS 470 -- Spring 2002. Overview Interrupts and Exceptions: Trap Handler Interrupt Request Levels and IRT DPC’s, and APC’s System Service Dispatching.

Slides:



Advertisements
Similar presentations
计算机系 信息处理实验室 Lecture 3 System Mechanisms (1)
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.
The Kernel Abstraction. Challenge: Protection How do we execute code with restricted privileges? – Either because the code is buggy or if it might be.
Input-output and Communication Prof. Sin-Min Lee Department of Computer Science.
Process Description and Control
Architectural Support for Operating Systems. Announcements Most office hours are finalized Assignments up every Wednesday, due next week CS 415 section.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
OS Spring’03 Introduction Operating Systems Spring 2003.
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.
1 I/O Management in Representative Operating Systems.
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
Process Description and Control A process is sometimes called a task, it is a program in execution.
OS Spring’04 Introduction Operating Systems Spring 2004.
CSE 451: Operating Systems Winter 2010 Module 15 I/O Mark Zbikowski Gary Kimura.
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
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.
Protection and the Kernel: Mode, Space, and Context.
Traps and Faults. Review: Mode and Space data user mode kernel mode A B C “kernel space”
Windows NT and Real-Time? Reading: “Inside Microsoft Windows 2000”, (Solomon, Russinovich, Microsoft Programming Series) “Real-Time Systems and Microsoft.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
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.
Windows 2000 System Mechanisms Computing Department, Lancaster University, UK.
CE Operating Systems Lecture 11 Windows – Object manager and process management.
Device Drivers CPU I/O Interface Device Driver DEVICECONTROL OPERATIONSDATA TRANSFER OPERATIONS Disk Seek to Sector, Track, Cyl. Seek Home Position.
Processes and Process Control 1. Processes and Process Control 2. Definitions of a Process 3. Systems state vs. Process State 4. A 2 State Process Model.
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.
4P13 Week 2 & 3 Talking Points 1. Kernel Processes 2.
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.
System Components ● There are three main protected modules of the System  The Hardware Abstraction Layer ● A virtual machine to configure all devices.
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.
1/9/ :46 1 Priority Model Real-time class Idle Above Normal Normal Below Normal Lowest Highest 31 Time-critical Dynamic classes.
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.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS3: Concurrency 3.3. Advanced Windows Synchronization.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Managing Processors Jeff Chase Duke University. The story so far: protected CPU mode user mode kernel mode kernel “top half” kernel “bottom half” (interrupt.
Introduction to Operating Systems Concepts
Introduction to Operating Systems
Chapter 13: I/O Systems Modified by Dr. Neerja Mhaskar for CS 3SH3.
Interrupts and signals
Operating Systems CMPSC 473
CS 6560: Operating Systems Design
Day 08 Processes.
Day 09 Processes.
Structure of Processes
Chapter 3: Windows7 Part 2.
Processor Fundamentals
I/O Systems I/O Hardware Application I/O Interface
Chapter 3: Windows7 Part 2.
Operating System Concepts
Direct Memory Access Disk and Network transfers: awkward timing:
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Process Description and Control
3.3. Advanced Windows Synchronization
CSE 451: Operating Systems Spring 2008 Module 15 I/O
Architectural Support for OS
CSE 451: Operating Systems Spring 2007 Module 15 I/O
Process Description and Control
Operating Systems Lecture 3.
Process Description and Control
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Architectural Support for OS
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
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:

NT Kernel CS Spring 2002

Overview Interrupts and Exceptions: Trap Handler Interrupt Request Levels and IRT DPC’s, and APC’s System Service Dispatching Exception Dispatching Dispatcher Objects Example: Reading a file

Interrupts vs Exceptions An interrupt is an asynchronous event, one that occurs at a time unrelated to what the processor is executing: I/O device interrupts, clocks, timers, etc. They usually can be enabled or disabled. An exception is a synchronous event, one that results from the execution of an instruction: memory access violations, debugger instructions, divide-by-zero, etc.

Interrupt & Exception Handling Wide variety of hardware supported The kernel provides a uniform interface by transferring control to the trap handler. The trap handler fills TrapFrame field in _KTHREAD with the execution state of the thread and transfers control to an appropriate kernel or executive module for handling the condition.

Interrupt & Exception Dispatching Interrupt Dispatcher System Service Dispatcher Interrupt Service Routines System Services Exception Dispatcher Exception Handlers VM Manager Pager Interrupt System Service Call Hard/Software Exceptions Virtual Address Exceptions Trap Handler

Interrupt Request Levels Each processor runs at a particular interrupt request level (IRQL) Threads running in kernel mode can change their current processor’s IRQL. Each type of interrupt is associated with a particular IRQL. Only interrupts at IRQL greater than that of a processor are enabled for that processor.

NT Defined IRQL’s High Level Power Level Interprocessor Interrupt Level Clock Levels Device Levels n to 1 Dispatch/DPC Level APC Level Low Level Machine check or bus error Power failure (not used) Work request from another processor Clock, kernel profiler I/O Device levels Thread dispatching & DPC’s Asynchronous proc. calls Normal Thread Execution IRQLTypes of Interrupts

Interrupt Dispatch Table One IDT per processor One entry for each IRQL An entry is a list of interrupt objects which were connected by device drivers When an interrupt occurs, it is mapped to an IRQL and so to an entry in the table. Each interrupt object specifies an ISR to handle the interrupt. So several devices can interrupt at the same level.

Software Interrupt Uses To initiate thread dispatching: For synchronization, kernel runs at DPC level; it requests a dispatch interrupt which will not be serviced until it lowers IRQL. Handle timer expiration Asynchronously execute a procedure in the context of a particular thread. For example, asynchronous I/O is done this way.

Deferred Procedure Calls Handlers can issue deferred procedure calls for non-time critical operations. Timers and the clock interrupt are handled this way. These are DPC objects which are ly queued per processor, and a DPC interrupt is requested. When IRQL below DPC level, they are executed.

Asynchronous Procedure Calls APC objects are queued on a per thread queue and an APC level interrupt is requested. Executes only in a specified thread. Kernel mode APC’s require no permission, but user mode APC’s execute only if the target thread has declared itself to be alertable (using e.g. WaitForSingleObjectEx or SleepEx) Asynchronous I/O uses this method.

KTHREAD Dispatcher Header User & kernel times System service table Thread scheduling info Trap frame Synchronization info Pending APC list Object Wait List TEB Thread Local storage Kernel stack info

System Service Dispatching Uses SYSCALL or INT 0x2e to trap to kernel mode. _KTHREAD SystemTable field specifies up to four System Service Dispatch Tables, 1K entries per table Arguments are copied to kernel mode stack to protect them. Flexible: expansion or modification by changing table entries.

Exception Dispatching Save trap frame and exception record LPC to debugger port Check Frame based handlers LPC to debugger port LPC to exception port (monitored by environment subsystem -- e.g. POSIX signals sent this way) Kernel Default handler -- terminates process -- DrWtsn32.exe

Exception Types ACCESS_VIOLATION DATATYPE_MISALIGNMENT BREAKPOINT SINGLE_STEP ARRAY_BOUNDS_EXCEEDED FLT_DENORMAL_OPERAND FLT_DIVIDE_BY_ZERO FLT_INEXACT_RESULT FLT_INVALID_OPERATION FLT_OVERFLOW FLT_STACK_CHECK FLT_UNDERFLOW INT_DIVIDE_BY_ZERO INT_OVERFLOW PRIV_INSTRUCTION IN_PAGE_ERROR ILLEGAL_INSTRUCTION NONCONTINUABLE_EXCEPTION STACK_OVERFLOW INVALID_DISPOSITION GUARD_PAGE INVALID_HANDLE

Example: Read.c void main(void) { HANDLE hFile; char buffer[256]; DWORD numRead; if ((hFile = CreateFile(“foo.bar”,...) !=INVALID_HANDLE_VALUE) { if(!ReadFile(hFile, buffer, 256, &numRead, NULL)){...} }}

Tracking the Read (1 of 2) ReadFile called from main NtReadFile called from ReadFile Trap handler: System Service Dispatch Table  I/O Manager  Device Driver Device Driver: queues read job Interrupt  Trap handler: IDT  Device Driver ISR: Queue DPC

Tracking the Read (2 of 2) IRQL drops DPC starts disk read Interrupt  Trap handler: IDT  Device Driver ISR  ISR queues DPC IRQL drops  DPC checks status, etc. DPC queues Kernel APC IRQL drops, Thread runs  APC runs,copies data to user buffer NtRead returns, ReadFile returns.