Skip to content

Commit

Permalink
Update submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
liaocj committed Nov 21, 2024
1 parent 8ca7a0c commit 61f300c
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 33 deletions.
31 changes: 0 additions & 31 deletions linux/内核-驱动/中断/ksoftirqd.md

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
57 changes: 57 additions & 0 deletions linux/内核-驱动/中断/软中断--ksoftirqd.md
Original file line number Diff line number Diff line change
@@ -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();
}
```
10 changes: 10 additions & 0 deletions linux/内核-驱动/中断/软中断--wakeup_softirqd.md
Original file line number Diff line number Diff line change
@@ -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);
}
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 软中断进入接口
title: 软中断上下文切换接口
date: 2024-11-20 14:46:23
tags:
---
Expand Down

0 comments on commit 61f300c

Please sign in to comment.