在前面介绍中,我们知道如何对软中断的简单初始化,软中断需要触发,然后软中断处理函数才能被执行:
内核提供__raise_softirq_irqoff()类函数对指定的软中设置标志位。与此相关的函数还有:
raise_softirq_irqoff()local中断已经关闭,对软中设置标识位,并且在非中断上下文,唤醒软中处理的内核线程softirqd。
raise_softirq() 在此函数中关闭local中断,之后对软中断标识位设置。
__raise_softirq_irqoff() local中断已经关闭,对指定软中断设置标志位。
这里需要关注一下对标识位的存储,从当前内核实现来看,这个是与体系结构相关,如果体系没有实现,则采用一个默认的实现
即在前面的irq_stat中定义成员,即使用__softirq_pending来跟踪设置的softirq标识。
通用定义如下:
include/asm-generic/hardirq.h
typedef struct { unsigned int __softirq_pending; } ____cacheline_aligned irq_cpustat_t;
arch/x86/include/asm/hardirq.h
typedef struct { unsigned int __softirq_pending; unsigned int __nmi_count; /* arch dependent */ #ifdef CONFIG_X86_LOCAL_APIC unsigned int apic_timer_irqs; /* arch dependent */ unsigned int irq_spurious_count; unsigned int icr_read_retry_count; #endif #ifdef CONFIG_HAVE_KVM unsigned int kvm_posted_intr_ipis; unsigned int kvm_posted_intr_wakeup_ipis; #endif unsigned int x86_platform_ipis; /* arch dependent */ unsigned int apic_perf_irqs; unsigned int apic_irq_work_irqs; #ifdef CONFIG_SMP unsigned int irq_resched_count; unsigned int irq_call_count; unsigned int irq_tlb_count; #endif #ifdef CONFIG_X86_THERMAL_VECTOR unsigned int irq_thermal_count; #endif #ifdef CONFIG_X86_MCE_THRESHOLD unsigned int irq_threshold_count; #endif #ifdef CONFIG_X86_MCE_AMD unsigned int irq_deferred_error_count; #endif #if IS_ENABLED(CONFIG_HYPERV) || defined(CONFIG_XEN) unsigned int irq_hv_callback_count; #endif }irq_cpustat_t;
DECLARE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat);
arch/arm/include/asm/hardirq.h
typedef struct { unsigned int __softirq_pending; #ifdef CONFIG_SMP unsigned int ipi_irqs[NR_IPI]; #endif } irq_cpustat_t;
arch/arm64/include/asm/hardirq.h
typedef struct { unsigned int __softirq_pending; unsigned int ipi_irqs[NR_IPI]; } irq_cpustat_t;