Interrupt !!

Interrupt !!

Processors need to detect hardware activities. There are multiple solutions to detect hardware activities. For example, Let's consider polling.? In polling every repeated time, hardware status will get verified without knowing whether the device is active or ready. It is an overhead process to detect the hardware status.

The better solution is that hardware should provide the signal to the processor about activities to gain the attention of the processor when it really required. This mechanism is called an interrupt.?

The hardware generates interrupts asynchronously and helps to gain the attention of the CPU to process its handler.? An interrupt is produced by electronic signals from hardware devices and directed into input pins on an interrupt controller.?

1) After receiving the interrupt, the interrupt controller will send a signal to the processor.

2) Processor detects the singal and halts the current execution context.?

3) Processor will notify the operating system about the incoming interrupt to handle further.?

4) Operating system will call the interrupt handler or routines which further resolved the interrupt.?

5) Operating system notifies back about the Interrupt completion to resume the saved contexts

Different devices are associated with different interrupts. Each interrupt is identified by a unique number or value. This will operating system to distinguish interrupts and call the appropriate interrupt handler. These interrupt values are also called IRQ Lines ( Interrupt Request Lines).

  • Each IRQ line is assigned a numeric value. For example, on the classic PC, IRQ zero is the timer interrupt and IRQ one is the keyboard interrupt.
  • Some interrupts are dynamically assigned, such as interrupts associated with devices on the PCI bus. Other non-PC architectures have similar dynamic assignments for interrupt values.
  • The kernel knows that a specific interrupt is associated with a specific device. The hardware then issues interrupts to get the kernel's attention.

The kernel handles the interrupt with the following sequence of operations

  1. It saves the current register context of the executing process and creates a new context layer.
  2. It will determine the source or cause of the interrupt, identifying the type of interrupt and unit number of the interrupt.
  3. Received interrupt is associated with a number and that will be offset into a table commonly called "Interrupt Vector".
  4. "Interrupt Vector" contains the address of the interrupt handler for the corresponding interrupt number.
  5. Then kernel invokes the interrupt handler.
  6. Interrupt handler completes its work and returns. Then kernel restores the previous context and starts the execution.

The interrupt handler is also called an "Interrupt Service Routine" (ISR). In Linux, interrupt handlers are normal C functions, which match a specific prototype and thus enable the kernel to pass the handler information in a standard way. What differentiates interrupt handlers from other kernel functions is that the kernel invokes them in response to interrupts and that they run in a special context called interrupt context. This special context is occasionally called atomic context because code executing in this context is unable to block.

Registration of Interrupt and Handler:

Devices come with the device driver. If the device?uses the interrupt, then it will get register the interrupt handler. Drivers can register an interrupt handler and enable a given interrupt line for handling with the function request_irq(), which is declared in <linux/interrupt.h>.

int request_irq(unsigned int irq
? ? ? ? ? ? ? ? irq_handler_t handler,
? ? ? ? ? ? ? ? unsigned long flags,
? ? ? ? ? ? ? ? const char *name,
? ? ? ? ? ? ? ? void *dev),        

  1. IRQ Number - Interrupt number to allocate.
  2. Handler - Function pointer of the handler to be invoked.
  3. Flag - Flag helps to identify the activities stage or criteria of interrupts.

  • ????IRQF_DISABLED - this flag instructs the kernel to disable all interrupts when executing this interrupt handler.
  • ????IRQF_SHARED - This flag specifies that the interrupt line can be shared among multiple interrupt handlers. Each handler registered on a given line must specify this flag; otherwise, only one handler can exist per line.

4. name of the device associated with the interrupt.

5. used for shared interrupt lines

Continue.....

要查看或添加评论,请登录

Shrikant Badiger的更多文章

  • NVMe Over TCP

    NVMe Over TCP

    NVMe over TCP is enhanced feature of NVMe over Fabrics. It used the standard network stack(Ethernet) without any…

    1 条评论
  • Bazel Build for C++ Software Application

    Bazel Build for C++ Software Application

    Bazel Tool is developed by google to automate the build process. Now It's an open source and it can be used by anyone.

  • C++ Class Layout

    C++ Class Layout

    Class Layout: Only non-static data members will contribute to the size of the class object. If we have static and…

    1 条评论
  • High-performance Computing in C++ : Open Muti Processing(OpenMP)

    High-performance Computing in C++ : Open Muti Processing(OpenMP)

    Open Multi-Processing: Let's consider the parallelization approaches, basically, we can think of imperative…

  • High-performance Computing in C++

    High-performance Computing in C++

    Single Instruction Multiple Data (SIMD) Multiple core CPUs and Multithreading: Declarative(OpenMP), imperative…

  • vSocket Interface - Guest to Host Communication

    vSocket Interface - Guest to Host Communication

    vSocket: VMware vSocket provides a very similar API to the Unix Socker interface for communication. vSocket library is…

  • Custom Memory Management in C++

    Custom Memory Management in C++

    Memory Management: Process in which memory allocation and de-allocation to the variable in running program and handle…

  • Pointers in C

    Pointers in C

    Pointers in C: Pointers are fundamental parts of C Programming. Pointers provide the lots of power and flexibility in C…

  • CMake and Useful Info

    CMake and Useful Info

    CMake is an open-source tool to build, test, and package software applications. CMake provides control over the…

    1 条评论
  • PXE: Preboot Execution Environment

    PXE: Preboot Execution Environment

    PXE: Preboot Execution Environment. Technology helps computers to boot up remotely through a network interface.

社区洞察

其他会员也浏览了