1. 程式人生 > >Linux kernel 軟中斷機制之觸發軟中斷執行

Linux kernel 軟中斷機制之觸發軟中斷執行

在前面介紹中,我們知道如何對軟中斷的簡單初始化,軟中斷需要觸發,然後軟中斷處理函式才能被執行:
核心提供__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;