From 61f300cdc845267aabcb4f52524c9b9ba711b0b4 Mon Sep 17 00:00:00 2001 From: liaocj Date: Thu, 21 Nov 2024 12:01:11 +0800 Subject: [PATCH] Update submodules --- .../\344\270\255\346\226\255/ksoftirqd.md" | 31 ---------- ...\347\241\254\344\270\255\346\226\255--.md" | 0 ...\344\270\255\346\226\255--__do_softirq.md" | 0 ...4\270\255\346\226\255--__raise_softirq.md" | 2 +- ...257\344\270\255\346\226\255--ksoftirqd.md" | 57 +++++++++++++++++++ ...344\270\255\346\226\255--net_rx_action.md" | 0 ...4\270\255\346\226\255--wakeup_softirqd.md" | 10 ++++ ...07\346\215\242\346\216\245\345\217\243.md" | 2 +- ...77\347\224\250\345\216\237\345\210\231.md" | 0 9 files changed, 69 insertions(+), 33 deletions(-) delete mode 100755 "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/ksoftirqd.md" rename "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/wakeup_softirqd.md" => "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\347\241\254\344\270\255\346\226\255--.md" (100%) rename "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/__do_softirq.md" => "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--__do_softirq.md" (100%) rename "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/__raise_softirq.md" => "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--__raise_softirq.md" (92%) create mode 100755 "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--ksoftirqd.md" rename "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/net_rx_action.md" => "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--net_rx_action.md" (100%) create mode 100755 "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--wakeup_softirqd.md" rename "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255\350\277\233\345\205\245\346\216\245\345\217\243.md" => "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--\344\270\212\344\270\213\346\226\207\345\210\207\346\215\242\346\216\245\345\217\243.md" (91%) rename "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255\344\275\277\347\224\250\345\216\237\345\210\231.md" => "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--\344\275\277\347\224\250\345\216\237\345\210\231.md" (100%) diff --git "a/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/ksoftirqd.md" "b/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/ksoftirqd.md" deleted file mode 100755 index 55895c7..0000000 --- "a/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/ksoftirqd.md" +++ /dev/null @@ -1,31 +0,0 @@ ---- -title: ksoftirqd 分析 -date: 2024-11-20 14:46:23 -tags: ---- - -```c -static struct smp_hotplug_thread softirq_threads = { - .store = &ksoftirqd, - .thread_should_run = ksoftirqd_should_run, - .thread_fn = run_ksoftirqd, - .thread_comm = "ksoftirqd/%u", -}; - - -static void run_ksoftirqd(unsigned int cpu) -{ - ksoftirqd_run_begin(); // 关闭cpu 中断响应 - if (local_softirq_pending()) { - /* - * We can safely run softirq on inline stack, as we are not deep - * in the task stack here. - */ - __do_softirq(); - ksoftirqd_run_end(); - cond_resched(); - return; - } - ksoftirqd_run_end(); // 开启cpu 中断响应 -} -``` \ No newline at end of file diff --git "a/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/wakeup_softirqd.md" "b/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\347\241\254\344\270\255\346\226\255--.md" similarity index 100% rename from "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/wakeup_softirqd.md" rename to "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\347\241\254\344\270\255\346\226\255--.md" diff --git "a/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/__do_softirq.md" "b/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--__do_softirq.md" similarity index 100% rename from "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/__do_softirq.md" rename to "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--__do_softirq.md" diff --git "a/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/__raise_softirq.md" "b/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--__raise_softirq.md" similarity index 92% rename from "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/__raise_softirq.md" rename to "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--__raise_softirq.md" index 1cbcec5..74c7446 100755 --- "a/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/__raise_softirq.md" +++ "b/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--__raise_softirq.md" @@ -8,7 +8,7 @@ tags: ```c #ifndef local_softirq_pending_ref -#define local_softirq_pending_ref irq_stat.__softirq_pending +#define local_softirq_pending_ref irq_stat.__softirq_pending //软中断挂起位图,每bit代表一种软中断 #endif #define local_softirq_pending() (__this_cpu_read(local_softirq_pending_ref)) diff --git "a/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--ksoftirqd.md" "b/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--ksoftirqd.md" new file mode 100755 index 0000000..70fba79 --- /dev/null +++ "b/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--ksoftirqd.md" @@ -0,0 +1,57 @@ +--- +title: ksoftirqd 分析 +date: 2024-11-20 14:46:23 +tags: +--- + +# ksoftirqd 结构 +```c +static struct smp_hotplug_thread softirq_threads = { + .store = &ksoftirqd, + .thread_should_run = ksoftirqd_should_run, + .thread_fn = run_ksoftirqd, + .thread_comm = "ksoftirqd/%u", +}; + +static void run_ksoftirqd(unsigned int cpu) +{ + ksoftirqd_run_begin(); // 关闭cpu 中断响应 + if (local_softirq_pending()) { + /* + * We can safely run softirq on inline stack, as we are not deep + * in the task stack here. + */ + __do_softirq(); + ksoftirqd_run_end(); + cond_resched(); + return; + } + ksoftirqd_run_end(); // 开启cpu 中断响应 +} +``` + +# ksoftirqd的调度 +内核本身不会主动周期性的调度softirqd,一般是通过驱动模块或者第三方事件触发: +内核中有三个地方调用wakeup_softirqd唤醒ksoftirqd内核线程: +1. 在__do_softirq函数中 +2. 在raise_softirq_irqoff函数中 +3. 在invoke_softirq函数中 + +```c +static inline void __irq_exit_rcu(void) +{ +#ifndef __ARCH_IRQ_EXIT_IRQS_DISABLED + local_irq_disable(); // 保证硬中断退出时的原子性 +#else + lockdep_assert_irqs_disabled(); +#endif + account_hardirq_exit(current); + // 退出硬中断上下文 + preempt_count_sub(HARDIRQ_OFFSET); + // 避免了在软中断环境下的硬中断断,导致的softirqd被多次调度,也就是说如果硬中断发生在当前cpu 的软中断环境下那么该硬中断在退出时不会触发软中断 + if (!in_interrupt() && local_softirq_pending()) + invoke_softirq(); + + tick_irq_exit(); +} +``` \ No newline at end of file diff --git "a/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/net_rx_action.md" "b/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--net_rx_action.md" similarity index 100% rename from "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/net_rx_action.md" rename to "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--net_rx_action.md" diff --git "a/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--wakeup_softirqd.md" "b/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--wakeup_softirqd.md" new file mode 100755 index 0000000..772a00f --- /dev/null +++ "b/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--wakeup_softirqd.md" @@ -0,0 +1,10 @@ +```c +static void wakeup_softirqd(void) +{ + /* Interrupts are disabled: no need to stop preemption */ + struct task_struct *tsk = __this_cpu_read(ksoftirqd); + + if (tsk) + wake_up_process(tsk); +} +``` \ No newline at end of file diff --git "a/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255\350\277\233\345\205\245\346\216\245\345\217\243.md" "b/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--\344\270\212\344\270\213\346\226\207\345\210\207\346\215\242\346\216\245\345\217\243.md" similarity index 91% rename from "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255\350\277\233\345\205\245\346\216\245\345\217\243.md" rename to "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--\344\270\212\344\270\213\346\226\207\345\210\207\346\215\242\346\216\245\345\217\243.md" index c0da1c5..70ffbd1 100755 --- "a/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255\350\277\233\345\205\245\346\216\245\345\217\243.md" +++ "b/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--\344\270\212\344\270\213\346\226\207\345\210\207\346\215\242\346\216\245\345\217\243.md" @@ -1,5 +1,5 @@ --- -title: 软中断进入接口 +title: 软中断上下文切换接口 date: 2024-11-20 14:46:23 tags: --- diff --git "a/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255\344\275\277\347\224\250\345\216\237\345\210\231.md" "b/linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--\344\275\277\347\224\250\345\216\237\345\210\231.md" similarity index 100% rename from "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255\344\275\277\347\224\250\345\216\237\345\210\231.md" rename to "linux/\345\206\205\346\240\270-\351\251\261\345\212\250/\344\270\255\346\226\255/\350\275\257\344\270\255\346\226\255--\344\275\277\347\224\250\345\216\237\345\210\231.md"