Interrupts and Exceptions 國立中正大學 資訊工程研究所 羅習五 老師. Interrupt & Exceptions Interrupts – maskable & nonmaskable interrupt Exceptions – Processor-detected.

Slides:



Advertisements
Similar presentations
Tutorial 3 - Linux Interrupt Handling -
Advertisements

CSCI 4717/5717 Computer Architecture
Chapter 6 Limited Direct Execution
CS591 (Spring 2001) The Linux Kernel: Signals & Interrupts.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
1 CE6105 Linux 作業系統 Linux Operating System 許 富 皓.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Linux Operating System
Linux Operating System
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.
Introduction to Interrupts
Computer System Laboratory
1 Computer System Overview Chapter 1 Review of basic hardware concepts.
Intel IA32 OS Support -Refresh
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
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.
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
Chapter 3 Process Description and Control
1 Zhao Xia Chapter 2 Process , thread, and scheduling Chapter 2 Process , thread, and scheduling —— kernel services.
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.
Windows 2000 System Mechanisms Computing Department, Lancaster University, UK.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
NT Kernel CS Spring Overview Interrupts and Exceptions: Trap Handler Interrupt Request Levels and IRT DPC’s, and APC’s System Service Dispatching.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Lab 13 Department of Computer Science and Information Engineering National Taiwan University Lab13 – Interrupt + Timer 2014/12/23 1 /16.
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.
CS 6560 Operating System Design Lecture 5: System Calls Interrupts.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Preemptive Context Switching
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
What is a Process ? A program in execution.
Lecture 5 Rootkits Hoglund/Butler (Chapters 1-3).
Operating Systems Unit 2: – Process Context switch Interrupt Interprocess communication – Thread Thread models Operating Systems.
Interrupt-Driven I/O There are different types of interrupts –Hardware Generated by the 8259 PIC – signals the CPU to suspend execution of the current.
BIOS and DOS Interrupts Basic Input /Outpu System Disk Operating System.
Ch 6. Interrupts and Interrupt Handlers. Overview (1) A primary responsibility of the kernel is managing the hardware connected to the machine  The kernel.
Interrupts and Interrupt Handling David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Chapter 6 Limited Direct Execution Chien-Chung Shen CIS/UD
Lecture 7 Interrupt ,Trap and System Call
WORKING OF SCHEDULER IN OS
Introduction to Operating Systems Concepts
Computer System Structures Interrupts
CS 3214 Computer Systems Lecture 9 Godmar Back.
Linux Kernel Development - Robert Love
Interrupts and exceptions
Process concept.
MICROPROCESSOR BASED SYSTEM DESIGN
Microprocessor and Assembly Language
Interfacing with Hardware
Microprocessor Systems Design I
Anton Burtsev February, 2017
Discussions on hw5 Objectives:
Protection of System Resources
Interrupts In 8085 and 8086.
Interrupts and Interrupt Handling
Structure of Processes
Discussions on hw5 Objectives:
Computer System Overview
Top Half / Bottom Half Processing
CNET 315 Microprocessor & Assembly Language
Computer System Overview
Interrupts and Interrupt Handling
Interrupts and System Calls
Presentation transcript:

Interrupts and Exceptions 國立中正大學 資訊工程研究所 羅習五 老師

Interrupt & Exceptions Interrupts – maskable & nonmaskable interrupt Exceptions – Processor-detected exceptions Faults Traps Aborts – Programmed exceptions software interrupt int, int3, into and bound sysenter, syscall, sysexit, sysreturn

IRQ & interrupts PIC – I/O programmable interrupt controller – Each IRQ line can be selectively disabled. APIC – I/O advanced programmable interrupt controller – designed for SMP (SMT/CMP) systems static distribution dynamic distribution

Exceptions For some exceptions, CPU push an error code in the kernel mode stack. The kernel provides a dedicated handler for each exception type.

Interrupt descriptor table (IDT) Interrupt gate Trap gate idtr idtr: interrupt descriptor table register

Gate descriptors' format Interrupt gate Trap gate

The invocation of an interrupt handler

# cd /usr/src/kernels/ shiwulo # ftp oss.sgi.com ftp> cd /www/projects/kdb/download/ ftp> cd v4.4 ftp> get kdb-v XX-common-Y.bz2 ftp> get kdb-v xx-i386-Y.bz2 ftp> bye # bzip2 -d *.bz2 # patch -p1 < kdb-v XX-common-Y # patch -p1 < kdb-v xx-i386-Y # cp /usr/src/kernels/ fc8-x86/.config./.config # make menuconfige # cd /usr/src/kernels/ shiwulo # ftp oss.sgi.com ftp> cd /www/projects/kdb/download/ ftp> cd v4.4 ftp> get kdb-v XX-common-Y.bz2 ftp> get kdb-v xx-i386-Y.bz2 ftp> bye # bzip2 -d *.bz2 # patch -p1 < kdb-v XX-common-Y # patch -p1 < kdb-v xx-i386-Y # cp /usr/src/kernels/ fc8-x86/.config./.config # make menuconfige kdb usr src kernels shiwulo fc8-x86

# make -j8 # make modules # make modules_install # make install # vim /boot/grub/grub.conf default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title Fedora ( shiwulo a) root (hd0,0) kernel /vmlinuz shiwulo a ro root=LABEL=/ rhgb quiet vga=0x305 kdb console=ttyS0,38400 console=tty0 initrd /initrd shiwulo a.img title Fedora ( fc8) root (hd0,0) kernel /vmlinuz fc8 ro root=LABEL=/ rhgb quiet initrd /initrd fc8.img title Fedora ( fc8) root (hd0,0) kernel /vmlinuz fc8 ro root=LABEL=/ rhgb quiet initrd /initrd fc8.img # make -j8 # make modules # make modules_install # make install # vim /boot/grub/grub.conf default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title Fedora ( shiwulo a) root (hd0,0) kernel /vmlinuz shiwulo a ro root=LABEL=/ rhgb quiet vga=0x305 kdb console=ttyS0,38400 console=tty0 initrd /initrd shiwulo a.img title Fedora ( fc8) root (hd0,0) kernel /vmlinuz fc8 ro root=LABEL=/ rhgb quiet initrd /initrd fc8.img title Fedora ( fc8) root (hd0,0) kernel /vmlinuz fc8 ro root=LABEL=/ rhgb quiet initrd /initrd fc8.img make kernel

/** Pressing the PAUSE key on the keyboard **/ Entering kdb (current=0xffff81011bc98000, pid 0) on processor 2 due to Keyboard Entry [2]kdb> help Command Usage Description md Display Memory Contents, also mdWcN, e.g. md8c1 mdr Display Raw Memory mdp Display Physical Memory idt [ ] Display IDT... [2]kdb> idt 0 0x0000 intgate segment=0x0010 off=0xffffffff8100d110 (divide_error) dpl=0 0x0001 intgate segment=0x0010 off=0xffffffff81285d50 (debug) dpl=0 ist=4 0x0002 intgate segment=0x0010 off=0xffffffff81285ea0 (nmi) dpl=0 ist=3 0x0003 intgate segment=0x0010 off=0xffffffff81285f30 (int3) dpl=3 ist=4 0x0004 intgate segment=0x0010 off=0xffffffff8100cf70 (overflow) dpl=3 0x0005 intgate segment=0x0010 off=0xffffffff8100cf80 (bounds) dpl=0 0x0006 intgate segment=0x0010 off=0xffffffff8100cf90 (invalid_op) dpl=0 0x0007 intgate segment=0x0010 off=0xffffffff8100cf60 (device_not_available) dpl=0 /** Pressing the PAUSE key on the keyboard **/ Entering kdb (current=0xffff81011bc98000, pid 0) on processor 2 due to Keyboard Entry [2]kdb> help Command Usage Description md Display Memory Contents, also mdWcN, e.g. md8c1 mdr Display Raw Memory mdp Display Physical Memory idt [ ] Display IDT... [2]kdb> idt 0 0x0000 intgate segment=0x0010 off=0xffffffff8100d110 (divide_error) dpl=0 0x0001 intgate segment=0x0010 off=0xffffffff81285d50 (debug) dpl=0 ist=4 0x0002 intgate segment=0x0010 off=0xffffffff81285ea0 (nmi) dpl=0 ist=3 0x0003 intgate segment=0x0010 off=0xffffffff81285f30 (int3) dpl=3 ist=4 0x0004 intgate segment=0x0010 off=0xffffffff8100cf70 (overflow) dpl=3 0x0005 intgate segment=0x0010 off=0xffffffff8100cf80 (bounds) dpl=0 0x0006 intgate segment=0x0010 off=0xffffffff8100cf90 (invalid_op) dpl=0 0x0007 intgate segment=0x0010 off=0xffffffff8100cf60 (device_not_available) dpl=0 kdb

/** Pressing the PAUSE key on the keyboard **/ Entering kdb (current=0xffff81011bc98000, pid 0) on processor 2 due to Keyboard Entry [2]kdb> bp 0xffffffff8100d110 [2]kdb> go # less test.c #include int i; void main() { int a=10; int b = 0; printf("%d", a/b); } # gcc test.c #./a.out 0xffffffff8100d110 divide_error: int3 Entering kdb (current=0xffff8100b918a000, pid 22706) on processor 1 due to 0xffffffff8100d110 [2] kdb> /** Pressing the PAUSE key on the keyboard **/ Entering kdb (current=0xffff81011bc98000, pid 0) on processor 2 due to Keyboard Entry [2]kdb> bp 0xffffffff8100d110 [2]kdb> go # less test.c #include int i; void main() { int a=10; int b = 0; printf("%d", a/b); } # gcc test.c #./a.out 0xffffffff8100d110 divide_error: int3 Entering kdb (current=0xffff8100b918a000, pid 22706) on processor 1 due to 0xffffffff8100d110 [2] kdb> kdb

Task State Segment

Stack layouts K U K U

When an interrupt handler is executed, the processor automatically stores the value of some registers in the stack of the current task. The difference between calling a handler through a trap gate or an interrupt gate is that in the last case interrupts are automatically

Nested execution of exception & interrupt handlers ISR1 ISR2 ISR3 ISR2 ISR1 scheduler task1 task2 k-ξ

Linux implementations Interrupt gate – all Linux interrupt handlers – DPL = 0 System gate – int3, into, bound, int $0x80 – DPL = 3 Trap gate – most Linux exception handlers – DPL = 0 sysenter, sysexit, syscall, sysret

The Linux structure krnl usr H/W sys. call interrupt softirq/ tasklet work- queue interrupt CTX process CTX exception

Exception handling 1.Save the contents of most registers in the Kernel Mode stack (this part is coded in assembly language). 2.Handle the exception by means of a high-level C function. 3.Exit from the handler by means of the ret_from_exception( ) function.

Exception handling

Interrupt handling I/O interrupts Timer interrupts Inter-processor interrupts (IPI)

The Linux structure krnl usr H/W sys. call interrupt softirq/ tasklet work- queue interrupt CTX process CTX exception Top-halfTop-half

BSD user process bottom half of kernel deferrable functions Interrupt The top half of the kernel provides services to processes in response to system call or traps. This software can be thought of as a library of routines shared by all processes. The bottom half of the kernel comprises routines that are invoked to handle hardware interrupt.

top & bottom halves the processing of interrupts is split into two parts, or halves. – The interrupt handler is the top half. – Work that can be performed later is deferred until the bottom half. In this chapter, we look at the top half; in the next chapter, we study the bottom.

IRQ handler Drivers can register an interrupt handler and enable a given interrupt line for handling with the function request_irq()

IRQ handler “irq” specifies the interrupt number to allocate. “handler” is a function pointer to the actual interrupt handler that services this interrupt “name” is an ASCII text representation of the device associated with the interrupt. “dev” is used as an ID for shared interrupt lines.

IRQ handler Flags IRQF_DISABLED—When set, this flag instructs the kernel to disable all interrupts when executing this interrupt handler IRQF_SAMPLE_RANDOM—This flag specifies that interrupts generated by this device should contribute to the kernel entropy pool

IRQ handler IRQF_SHARED—This flag specifies that the interrupt line can be shared among multiple interrupt handlers.

Freeing an Interrupt Handler When a driver unloads, we need to unregister the interrupt handler If the interrupt line is not shared, this function removes the handler and disables the line. If the interrupt line is shared, the handler identified via dev is removed only.

Reentrancy and Interrupt Handlers Interrupt handlers in Linux need not be reentrant. – When a given interrupt handler is executing, the corresponding interrupt line is masked out on all processors

Shared Handlers The interrupt handler must be capable of distinguishing whether its device actually generated an interrupt. This requires both hardware support and associated logic in the interrupt handler.

Interrupt Context When executing an interrupt handler, the kernel is in interrupt context. Interrupt context, on the other hand, is not associated with a process. – The current macro is not relevant Interrupt context is time-critical – Busy looping is possible, but discouraged.

The path that an interrupt takes

ret_from_intr() Written in assembly If a reschedule is pending, and the kernel is returning to user-space, schedule() is called If the kernel is returning to kernel-space schedule() is called only if the preempt_count is zero. After schedule() returns, or if there is no work pending, the kernel resumes whatever was interrupted.

Disabling and Enabling Interrupts The reason to control the interrupt system is to provide synchronization. – provides protection against concurrent access from a possible interrupt handler.

Global IRQ disabling? were deprecated during 2.5 because the performance issues.