Skip to content

Os Ctx Switch Soft Vs Hard

DodaTech 1 min read

In this tutorial, you'll learn about How to Fix Soft vs Hard IRQ Errors. We cover key concepts, practical examples, and best practices.

Fix soft vs hard irq errors when long-running interrupt handler (hard IRQ) disables all interrupts.

Quick Fix

Wrong

import os, time
# In kernel: interrupt handler that runs too long
# Disables all interrupts on that core during execution
# Simulated: holding spin_lock_irqsave for long time

Hard IRQ runs with interrupts disabled. Too long = missed interrupts, timer jitter, system unresponsive.

# Linux splits interrupt handling:
# 1. Hard IRQ: minimal, quick (ack, schedule softirq)
# 2. SoftIRQ/SoftIRQ daemon: heavy work, interrupts enabled
import os
# Check interrupt stats:
with open('/proc/interrupts') as f:
    headers=f.readline()
    for line in f:
        if 'timer' in line:
            print(f'Timer IRQ: {line.strip()}')
# Check softirq stats:
with open('/proc/softirqs') as f:
    for line in f:
        if 'TIMER' in line:
            print(f'SoftIRQ: {line.strip()}')
Hard IRQ minimal. Heavy work deferred to SoftIRQ (ksoftirqd).

Prevention

Keep hard IRQ handlers minimal. Use threaded IRQs or SoftIRQ for heavy work.

DodaTech Tools

Doda Browser's algorithm visualizer steps through DSA operations line by line. DodaZIP archives implementation patterns for team sharing. Durga Antivirus Pro detects memory corruption patterns in algorithm implementations.

FAQ

What is hard IRQ?

Interrupt request. Runs with interrupts disabled. Must be fast (~microseconds).

SoftIRQ?

Deferred interrupt handling. Runs with interrupts enabled. Scheduled after hard IRQ.

Threaded IRQ?

request_threaded_irq(). Handles heavy work in kernel thread. Interrupts enabled.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro