下半部目前包括软中断,tasklet,工作队列。
软中断:
- 编译器静态分配的;
- 不互相抢占;
- 只有中断处理程序可以抢占它;
- 相同类型软中断可以在不同的CPU上同时运行;
- 大部分软中断处理程序都通过采取单处理器数据或其他技巧来避免加锁。
tasklet:
建立在软中断之上;
可以动态生成;
root:/etc:# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 04:33 ? 00:00:00 init [5]
root 2 1 0 04:33 ? 00:00:00 [ksoftirqd/0] -----------------软中断,其包括分很多类型:
(enum
{
HI_SOFTIRQ=0,
TIMER_SOFTIRQ, --------- 定时器
NET_TX_SOFTIRQ,
NET_RX_SOFTIRQ, --------- 网络系统,对时间要求严格,所以直接使用软中断。
BLOCK_SOFTIRQ,
TASKLET_SOFTIRQ,
SCHED_SOFTIRQ,
#ifdef CONFIG_HIGH_RES_TIMERS
HRTIMER_SOFTIRQ,
#endif
RCU_SOFTIRQ, /* Preferable RCU should always be the last softirq */
};)
root 3 1 0 04:33 ? 00:00:00 [watchdog/0]
root 4 1 0 04:33 ? 00:00:00 [events/0] ------------- 工作队列
root 5 1 0 04:33 ? 00:00:00 [khelper]
root 6 1 0 04:33 ? 00:00:00 [kthread]
root 35 6 0 04:33 ? 00:00:00 [kblockd/0]
root 49 6 0 04:33 ? 00:00:00 [pdflush]
root 50 6 0 04:33 ? 00:00:00 [pdflush]
root 51 6 0 04:33 ? 00:00:00 [kswapd0]
root 52 6 0 04:33 ? 00:00:00 [aio/0]
root 169 1 0 04:33 ? 00:00:00 [mtdblockd]
root 192 6 0 04:33 ? 00:00:00 [kjournald]
root 216 6 0 04:33 ? 00:00:00 [kjournald]
root 219 6 0 04:33 ? 00:00:00 [kjournald]
asmlinkage void __init start_kernel(void)
{
init_IRQ();
init_timers();
hrtimers_init();
softirq_init();
rest_init(); --------- 其中创建了initd和kthreadd两个内核线程,且kthreadd处于休眠状态。
}
1、
static __init int spawn_ksoftirqd(void)
{
void *cpu = (void *)(long)smp_processor_id();
int err = cpu_callback(&cpu_nfb, CPU_UP_PREPARE, cpu); --- 此时创建并阻塞内核线程ksoftirqd/0,ksoftirqd/1等