Interrupt handling routines are architecture-dependent. The way interrupts are managed and processed can vary significantly between different computer architectures. Interrupt handling routines can be different between RISC-V and Armv8.

Understanding interrupt handling routines is crucial when dealing with real-time operating systems (RTOS) and the Linux kernel. Since RTOS and Linux kernel rely heavily on interrupt handling to efficiently manage and respond to events in a timely manner.

Here's a general outline of how interrupt handling might be implemented in Linux kernel based on RISC-V architecture:


[1] When interrupt is triggered from peripheral like device signals interrupt, interrupt handling routine is performed to handle interrupt request. Based on RISC-V architecture, 'handle_exception' is exception handler.

arch/riscv/kernel/entry.S
SYM_CODE_START(handle_exception)
...
la ra, ret_from_exception

/*
 * MSB of cause differentiates between
 * interrupts and exceptions
 */
bge s4, zero, 1f

/* Handle interrupts */
tail do_irq

[2] The call do_irq() function is made inside handle_exception as above.

do_irq() -> handle_riscv_irq() -> riscv_intc_irq() -> generic_handle_domain_irq()

[3] If IRQ is considered to be inter-processor interrupt, sbi_ipi_handle() is called.
Where sbi_ipi_handle() is set to chained handler in arch/riscv/kernel/sbi-ipi.c
 
[4] If IRQ is triggered from peripheral device(like sensor, touch, etc), plic_handle_irq() is called.
Where plic_handle_irq() is set to chained handler in drivers/irqchip/irq-sifive-plic.c.

[5] It is known that timer interrupt is handled in RISC-V in different ways. If timer IRQ is triggered, handle_percpu_devid_irq () is called.

The subroutine of [3],[4][5] will call the corresponding interrupt handler to take care of interrupt handling.

          <idle>-0       [000] d.h..   643.355357: irq_handler_entry: irq=16 name=virtio2
          <idle>-0       [000] d.h..   643.355397: <stack trace>
 => trace_event_raw_event_irq_handler_entry+0x96/0xf6
 => __traceiter_irq_handler_entry+0x2e/0x44
 => __handle_irq_event_percpu+0x13a/0x196
 => handle_irq_event+0x78/0xd2
 => handle_fasteoi_irq+0xa8/0x236
 => generic_handle_domain_irq+0x28/0x36
 => plic_handle_irq+0x86/0xfe
 => generic_handle_domain_irq+0x28/0x36
 => riscv_intc_irq+0x34/0x4c
 => do_irq+0x56/0x8e
 => ret_from_exception+0x0/0x64
 => default_idle_call+0x3a/0xd0
 => do_idle+0x214/0x23e
 => cpu_startup_entry+0x2e/0x30
 => kernel_init+0x0/0x168
 => arch_post_acpi_subsys_init+0x0/0x28
 => console_on_rootfs+0x0/0x70

'RISC-V' 카테고리의 다른 글

[RISC-V] system call return (s mode -> u mode)  (0) 2024.02.29
[RISC-V]: Interrupt handling - code walkthrough  (0) 2024.01.29

+ Recent posts