CS591 (Spring 2001) The Linux Kernel: Signals & Interrupts.

Slides:



Advertisements
Similar presentations
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.
Advertisements

I/O Unit.
Unit 4 Chapter-1 Multitasking. The Task State Segment.
Chapter 6 Limited Direct Execution
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
X86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT
1 CE6105 Linux 作業系統 Linux Operating System 許 富 皓.
CS Lecture 17 Outline Named pipes Signals Lecture 17
Operating Systems Course Hebrew University Spring 2007 Signals & User Thread.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Threads and Scheduling 6.
Linux Operating System
Linux Operating System
CS Lecture 16 Outline Inter-process Communication (IPC) – Pipes – Signals Lecture 161CS Operating Systems 1.
Introduction to Interrupts
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
CSc 352 Signal Handling in Unix Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
UNIT 2 Memory Management Unit and Segment Description and Paging
Intel IA32 OS Support -Refresh
UNIX Signals Bach 7.2 Operating Systems Course The Hebrew University Spring 2010.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
COMP201 Computer Systems Exceptions and Interrupts.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
80386DX.
Multitasking Mr. Mahendra B. Salunke Asst. Prof. Dept. of Computer Engg., STES SITS, Narhe, Pune-41 STES Sinhgad Institute of Tech. & Science Dept. of.
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
Exec Function calls Used to begin a processes execution. Accomplished by overwriting process imaged of caller with that of called. Several flavors, use.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
NT Kernel CS Spring Overview Interrupts and Exceptions: Trap Handler Interrupt Request Levels and IRT DPC’s, and APC’s System Service Dispatching.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
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.
Virtual 8086 Mode  The supports execution of one or more 8086, 8088, 80186, or programs in an protected-mode environment.  An 8086.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
UNIX Signals * POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm * Interval Timers * POSIX.1b Timers *
4300 Lines Added 1800 Lines Removed 1500 Lines Modified PER DAY DURING SUSE Lab.
EFLAG Register of The The only new flag bit is the AC alignment check, used to indicate that the microprocessor has accessed a word at an odd.
Microprocessor system architectures – IA32 tasks Jakub Yaghob.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Segment Descriptor Segments are areas of memory defined by a programmer and can be a code, data or stack segment. In segments need not be all the.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Page Replacement Implementation Issues Text: –Tanenbaum ch. 4.7.
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.
Information Security - 2. Task Switching Every process has an associated Task State Segment, whose starting point is stored in the Task register. A task.
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.
Homework / Exam Return and Review Exam #1 Reading Machine Projects
Interrupts and exceptions
Chapter 2: Computer-System Structures
MICROPROCESSOR BASED SYSTEM DESIGN
Microprocessor and Assembly Language
Operating Systems Engineering
Microprocessor Systems Design I
Anton Burtsev February, 2017
Protection of System Resources
Scheduler activations
Computer Architecture
Interrupts In 8085 and 8086.
x86 segmentation, page tables, and interrupts
System Segment Descriptor
Architectural Support for OS
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
CSE 451: Operating Systems Winter 2007 Module 2 Architectural Support for Operating Systems Brian Bershad 562 Allen Center 1.
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Architectural Support for OS
Chapter 2: Computer-System Structures
Chapter 2: Computer-System Structures
Presentation transcript:

CS591 (Spring 2001) The Linux Kernel: Signals & Interrupts

CS591 (Spring 2001) Signals n Introduced in UNIX systems to simplify IPC. n Used by the kernel to notify processes of system events. n A signal is a short message sent to a process, or group of processes, containing the number identifying the signal. n No data is delivered with traditional signals. n POSIX.4 defines i/f for queueing & ordering RT signals w/ arguments.

CS591 (Spring 2001) Example Signals n Linux supports 31 non-real-time signals. n POSIX standard defines a range of values for RT signals: SIGRTMIN 32 … SIGRTMAX (_NSIG-1) in

CS591 (Spring 2001) Signal Transmission n Signal sending: n Kernel updates descriptor of destination process. n Signal receiving: n Kernel forces target process to “handle” signal. n Pending signals are sent but not yet received. n Up to one pending signal per type for each process, except for POSIX.4 signals. n Subsequent signals are discarded. n Signals can be blocked, i.e., prevented from being received.

CS591 (Spring 2001) Signal-Related Data Structures sigset_t stores array of signals sent to a process. The process descriptor ( struct task_struct in ) has several fields for tracking sent, blocked and pending signals. struct sigaction { void (*sa_handler)();/* handler address, or SIG_IGN, or SIG_DFL */ sigset_t sa_mask; /* blocked signal list */ int sa_flags;/* options e.g., SA_RESTART */ }

CS591 (Spring 2001) Sending Signals A signal is sent due to occurrence of corresponding event (see kernel/signal.c). e.g., send_sig_info(int sig, struct siginfo *info, struct task_struct *t); sig is signal number. info is either: n address of RT signal structure. n 0, if user mode process is signal sender. n 1, if kernel is signal sender. e.g., kill_proc_info(int sig, struct siginfo *info, pid_t pid);

CS591 (Spring 2001) Receiving Signals n Before process p resumes execution in user mode, kernel checks for pending non-blocked signals for p. Done in entry.S by call to ret_from_intr(), which is invoked after handling an interrupt or exception. do_signal() repeatedly invokes dequeue_signal() until no more non-blocked pending signals are left. n If the signal is not ignored, or the default action is not performed, the signal must be caught.

CS591 (Spring 2001) Catching Signals handle_signal() is invoked by do_signal() to execute the process’s registered signal handler. n Signal handlers reside (& run) in user mode code segments. handle_signal() runs in kernel mode. n Process first executes signal handler in user mode before resuming “normal” execution. n Note: Signal handlers can issue system calls. n Makes signal mechanism complicated. n Where do we stack state info while crossing kernel-user boundary?

CS591 (Spring 2001) Re-execution of System Calls n “Slow” syscalls e.g. blocking read/write, put processes into waiting state: TASK_(UN)INTERRUPTIBLE. A task in state TASK_INTERRUPTIBLE will be changed to the TASK_RUNNING state by a signal. TASK_RUNNING means a process can be scheduled. n If executed, its signal handler will be run before completion of “slow” syscall. n The syscall does not complete by default. If SA_RESTART flag set, syscall is restarted after signal handler finishes.

CS591 (Spring 2001) Real-Time Signals Real-Time signals are queued as a list of signal_queue elements: A process’s descriptor has a sigqueue field that points to the first member of the RT signal queue. send_sig_info() enqueues RT signals in a signal_queue. dequeue_signal() removes the RT signal. struct signal_queue { struct signal_queue *next; siginfo_t info; /* See asm-*/siginfo.h */ }

CS591 (Spring 2001) RT Signal Parameters siginfo_t contains a member for RT signals. The argument to RT signals is a sigval_t type: n Extensions? n Explicit scheduling of signals and corresponding processes. typedef union sigval { int sigval_int; void *sival_ptr; } sigval_t;

CS591 (Spring 2001) Signal Handling System Calls n int sigaction(int sig, const struct sigaction *act, struct sigaction *oact); Replaces the old signal() function. n Used to bind a handler to a signal. n For RT signals, the handler’s prototype is of form: n void (*sa_sigaction)(int, siginfo_t *, void *); n See Steven’s “Advanced Programming in the UNIX Environment” for more…

CS591 (Spring 2001) Interrupts n Interrupts are events that alter sequence of instructions executed by a processor. n Maskable interrupts: Sent to INTR pin of x86 processor. Disabled by clearing IF flag of eflags register. n Non-maskable interrupts: Sent to NMI pin of x86 processor. Not disabled by clearing IF flag. n Exceptions: n Can be caused by faults, traps, programmed exceptions (e.g., syscalls) & hardware failures.

CS591 (Spring 2001) Interrupt & Exception Vectors n bit vectors on x86 (0..255): n Identify each interrupt or exception. n Vectors: n for exceptions & non-maskable interrupts. n for interrupts caused by IRQs. n for “software interrupts”. n Linux uses vector 128 (0x80) for system calls.

CS591 (Spring 2001) IRQs & Interrupts n Hardware device controllers that issue interrupt requests, do so on an IRQ (Interrupt ReQuest) line. n IRQ lines connect to input pins of interrupt controller (e.g., 8259A PIC). n Interrupt controller repeatedly: n Monitors IRQ lines for raised signals. n Converts signal to vector & stores it in an I/O port for CPU to access via data bus. n Sends signal to INTR pin of CPU. n Clears INTR line upon receipt of ack from CPU on designated I/O port.

CS591 (Spring 2001) Example Exceptions

CS591 (Spring 2001) Interrupt Descriptor Table n A system Interrupt Descriptor Table (IDT) maps each vector to an interrupt or exception handler. n IDT has up to byte descriptor entries. idtr register on x86 holds base address of IDT. n Linux uses two types of descriptors: n Interrupt gates & trap gates. n Gate descriptors identify address of interrupt / exception handlers Interrupt gates clear IF flag, trap gates don’t.

CS591 (Spring 2001) Interrupt Handling n CPU checks for interrupts after executing each instruction. n If interrupt occurred, control unit: n Determines vector i, corresponding to interrupt. Reads ith entry of IDT referenced by idtr. n IDT entry contains a segment selector, identifying a segment descriptor in the global descriptor table (GDT), that identifies a memory segment holding handler fn. n Checks interrupt was issued by authorized source.

CS591 (Spring 2001) Interrupt Handling …continued… n Control Unit then: n Checks for a change in privilege level. n If necessary, switches to new stack by: Loading ss & esp regs with values found in the task state segment (TSS) of current process. Saving old ss & esp values. Saves state on stack including eflags, cs & eip. Loads cs & eip w/ segment selector & offset fields of gate descriptor in ith entry of IDT. n Interrupt handler is then executed!

CS591 (Spring 2001) Protection Issues n A general protection exception occurs if: n Interrupt handler has lower privilege level than a program causing interrupt. n Applications attempt to access interrupt or trap gates. n What would it take to vector interrupts to user level? n Programs execute with a current privilege level (CPL). n e.g., If gate descriptor privilege level (DPL) is lower than CPL, a general protection fault occurs.

CS591 (Spring 2001) Gates, Gates but NOT Bill Gates! n Linux uses the following gate descriptors: n Interrupt gate: n DPL=0, so cannot be accessed by user mode progs. n System gate: n DPL=3, so can be accessed by user mode progs. n e.g., vector 128 accessed via syscall triggered by int 0x80. n Trap gate: n DPL=0. Trap gates are used for activating exception handlers.

CS591 (Spring 2001) Initializing IDT n Linux uses the following functions: n set_intr_gate(n, addr); n set_trap_gate(n,addr); n set_system_gate(n,addr); n Insert gate descriptor into nth entry of IDT. addr identifies offset in kernel’s code segment, which is base address of interrupt handler. n DPL value depends on which fn (above) is called. e.g., set_system_gate(0x80,&system_call);