Example: stock market

The Linux Kernel: Signals & Interrupts

CS591 (Spring 2001)The Linux kernel : Signals & InterruptsCS591 (Spring 2001)SignalsnIntroduced in UNIX systems to simplify by the kernel to notify processes of system signal is a short message sent to a process, or group of processes, containing the number identifying the data is delivered with traditional defines i/f for queueing& ordering RT Signals w/ arguments. CS591 (Spring 2001)Example SignalsnLinux supports 31 non-real-time Signals . nPOSIX standard defines a range of values for RT Signals :nSIGRTMIN 32 .. SIGRTMAX (_NSIG-1)in <asm-* ># signal NameDefault ActionComment1 SIGHUPA bortHangup terminal or process2 SIGINTA bortKeyboard interrupt (usually Ctrl-C).

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 …

Tags:

  Linux, Signal, Kernel, Interrupts, The linux kernel, Signals amp interrupts

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of The Linux Kernel: Signals & Interrupts

1 CS591 (Spring 2001)The Linux kernel : Signals & InterruptsCS591 (Spring 2001)SignalsnIntroduced in UNIX systems to simplify by the kernel to notify processes of system signal is a short message sent to a process, or group of processes, containing the number identifying the data is delivered with traditional defines i/f for queueing& ordering RT Signals w/ arguments. CS591 (Spring 2001)Example SignalsnLinux supports 31 non-real-time Signals . nPOSIX standard defines a range of values for RT Signals :nSIGRTMIN 32 .. SIGRTMAX (_NSIG-1)in <asm-* ># signal NameDefault ActionComment1 SIGHUPA bortHangup terminal or process2 SIGINTA bortKeyboard interrupt (usually Ctrl-C).

2 9 SIGKILLA bortForced process termination10 SIGUSR1 AbortProcess specific11 SIGSEGVDumpInvalid memory (Spring 2001) signal TransmissionnSignal sending:nKernel updates descriptor of destination receiving:nKernel forces target process to handle signalsare sent but not yet to one pending signal per type for each process, except for Signals are can be blocked, , prevented from being (Spring 2001) signal -Related Data Structures nsigset_tstores array of Signals sent to a process descriptor (structtask_structin < >) has several fields for tracking sent, blocked and pending sigaction{void (*sa_handler)();/* handler address, or SIG_IGN, or SIG_DFL */sigset_tsa_mask; /* blocked signal list */int sa_flags.}

3 /* options , SA_RESTART */}CS591 (Spring 2001)Sending SignalsnA signal is sent due to occurrence of corresponding event (see ). , send_sig_info(intsig, structsiginfo*info, structtask_struct*t);nsigis signal either:naddress of RT signal , if user mode process is signal , if kernel is signal , kill_proc_info(int sig,struct siginfo*info, pid_t pid);CS591 (Spring 2001)Receiving SignalsnBefore process presumes execution in user mode, kernel checks for pending non-blocked Signals for in call to ret_from_intr(), which is invoked after handling an interrupt or ()repeatedly invokes dequeue_signal()until no more non-blocked pending Signals are the signal is not ignored, or the default action is not performed, the signal must be (Spring 2001)Catching Signalsnhandle_signal()is invoked by do_signal()to execute the process s registered signal handlers reside (& run)

4 In user mode code ()runs in kernel first executes signal handler in user mode before resuming normal : signal handlers can issue system signal mechanism do we stack state info while crossing kernel -user boundary?CS591 (Spring 2001)Re-execution of System Callsn Slow syscalls blocking read/write, put processes into waiting state:nTASK_(UN)INTERRUPTIBLE. nA task in state TASK_INTERRUPTIBLE will be changed to the TASK_RUNNING state by a means a process can be scheduled. nIf executed, its signal handler will be run before completionof slow syscall does not complete by SA_RESTART flag set, syscall is restarted after signal handler (Spring 2001)Real-Time SignalsnReal-Time Signals are queuedas a list of signal_queueelements:nA process s descriptor has a sigqueuefield that points to the first member of the RT signal ()enqueues RT Signals in a ()removes the RT {structsignal_queue *next;siginfo_t info.}

5 /* See asm-* */}CS591 (Spring 2001)RT signal Parametersnsiginfo_tcontains a member for RT Signals . nThe argument to RT Signals is a sigval_ttype:nExtensions?nExplicit scheduling of Signals and corresponding {int sigval_int;void *sival_ptr;}sigval_t;CS591 (Spring 2001) signal Handling System Callsnint sigaction(int sig, conststruct sigaction*act,struct sigaction*oact);nReplaces the old signal () to bind a handler to a RT Signals , the handler s prototype is of form:nvoid (*sa_sigaction)(int, siginfo_t *, void *);nSee Steven s Advanced Programming in the UNIX Environment for (Spring 2001)InterruptsnInterrupts are events that alter sequence of instructions executed by a Interrupts :nSent to INTRpin of x86 processor.

6 Disabled by clearing IFflag of eflags Interrupts :nSent to NMIpin of x86 processor. Not disabled by clearing :nCan be caused by faults, traps, programmed exceptions ( , syscalls) & hardware (Spring 2001)Interrupt & Exception Vectorsn256 8-bit vectors on x86 ( ):nIdentify each interrupt or for exceptions & non-maskable for Interrupts caused by for software Interrupts .nLinux uses vector 128 (0x80) for system (Spring 2001)IRQs & InterruptsnHardware device controllers that issue interrupt requests, do soon an IRQ (Interrupt ReQuest) lines connect to input pins of interrupt controller( , 8259A PIC).

7 NInterrupt controller repeatedly:nMonitors IRQ lines for raised signal to vector & stores it in an I/O port for CPU to access via data signal to INTR pin of INTR line upon receipt of ackfrom CPU on designated I/O (Spring 2001)Example Exceptions#ExceptionException HandlerSignal0 Divide Errordivide_error()SIGFPE1 Debugdebug() Opcodeinvalip_op() Faultpage_fault() (Spring 2001)Interrupt Descriptor TablenA system Interrupt Descriptor Table(IDT) maps each vector to an interrupt or exception has up to 256 8-byte descriptor on x86 holds base address of uses two types of descriptors:nInterrupt gates& trap descriptors identify address of interrupt / exception handlersnInterrupt gates clear IFflag, trap gates don (Spring 2001)Interrupt HandlingnCPU checks for Interrupts after executing each interrupt occurred, control unit.

8 NDetermines vector i, corresponding to ithentry of IDT referenced by entry contains a segment selector, identifying a segment descriptorin the global descriptor table(GDT), that identifies a memory segment holding handler interrupt was issued by authorized (Spring 2001)Interrupt Handling .. Unit then:nChecks for a change in privilege necessary, switches to new stack by:nLoading ss& espregs with values found in the task state segment(TSS) of current old ss& state on stack including eflags, cs& cs&eipw/ segment selector & offset fields of gate descriptor in ithentry of IDT.

9 NInterrupt handler is then executed!CS591 (Spring 2001)Protection IssuesnA general protection exceptionoccurs if:nInterrupt handler has lower privilege level than a program causing attempt to access interrupt or trap would it take to vector Interrupts to user level?nPrograms execute with a current privilege level (CPL). , If gate descriptor privilege level (DPL) is lower than CPL, a general protection fault (Spring 2001)Gates, Gates but NOT Bill Gates!nLinux uses the following gate descriptors:nInterrupt gate:nDPL=0, so cannot be accessed by user mode gate:nDPL=3, so can be accessed by user mode progs.

10 , vector 128 accessed via syscall triggered gate:nDPL=0. Trap gates are used for activating exception (Spring 2001)Initializing IDTnLinux uses the following functions:nset_intr_gate(n,addr);nset_tr ap_gate(n,addr);nset_system_gate(n,addr) ;nInsert gate descriptor into nthentry of offset in kernel s code segment, which is base address of interrupt value depends on which fn (above) is , set_system_gate(0x80,&system_call).


Related search queries