SoftIRQ 软中断

版权声明:本文全部是胡说八道,如果你喜欢,可随意转载 https://blog.csdn.net/robinsongsog/article/details/82561915

    软中断是Linux 内核很早引入的机制,最早可以追溯到Linux

2.3 开发期间,软中断是预留给系统中对时间要求最为严格

和最重要的下半部使用的,而且目前驱动中只有块设备和

网络子系统使用了软中断。系统静态定义了苦干种软件中断

类型,并且Linux内核开发者不希望用户再扩充软中断类型,

如有需要,建议使用tasklet 机制。已经定义好的软件中断

类型如下:

/* PLEASE, avoid to allocate new softirqs, if you need not _really_ high
   frequency threaded job scheduling. For almost all the purposes
   tasklets are more than enough. F.e. all serial device BHs et
   al. should be converted to tasklets, not to softirqs.
 */

enum
{
	HI_SOFTIRQ=0,
	TIMER_SOFTIRQ,
	NET_TX_SOFTIRQ,
	NET_RX_SOFTIRQ,
	BLOCK_SOFTIRQ,
	IRQ_POLL_SOFTIRQ,
	TASKLET_SOFTIRQ,
	SCHED_SOFTIRQ,
	HRTIMER_SOFTIRQ, /* Unused, but kept as tools rely on the
			    numbering. Sigh! */
	RCU_SOFTIRQ,    /* Preferable RCU should always be the last softirq */

	NR_SOFTIRQS
};

通过枚举类型来静态声明软中断,并且每一种软中断都使用索引来表示

一种相对的优先级,索引号越小,软中断优先级越高,并在一轮软中断处

理中得到优先支执行。其中:

扫描二维码关注公众号,回复: 3104947 查看本文章

HI_SOFTIRQ, 优先级为0, 是最高优先级的软中断类型。

TIMER_SOFTIRQ, 优先级为1, Timer 定时器的软中断。

NET_TX_SOFTIRQ, 优先级为2, 发送网络数据包的软中断。

NET_RX_SOFTIRQ, 优先级为3, 接收网络数据包的软中断。

tasklet

tasklet 是利用软中断实现的一种下半部机制,本质是是软件中断的一个变

种,运行在软件中断上下文中。 tasklet 由tasklet_struct 数据结构描述:

/* Tasklets --- multithreaded analogue of BHs.

   Main feature differing them of generic softirqs: tasklet
   is running only on one CPU simultaneously.

   Main feature differing them of BHs: different tasklets
   may be run simultaneously on different CPUs.

   Properties:
   * If tasklet_schedule() is called, then tasklet is guaranteed
     to be executed on some cpu at least once after this.
   * If the tasklet is already scheduled, but its execution is still not
     started, it will be executed only once.
   * If this tasklet is already running on another CPU (or schedule is called
     from tasklet itself), it is rescheduled for later.
   * Tasklet is strictly serialized wrt itself, but not
     wrt another tasklets. If client needs some intertask synchronization,
     he makes it with spinlocks.
 */

struct tasklet_struct
{
	struct tasklet_struct *next;
	unsigned long state;
	atomic_t count;
	void (*func)(unsigned long);
	unsigned long data;
};

猜你喜欢

转载自blog.csdn.net/robinsongsog/article/details/82561915