ULK --- Chap 4: Tasklets (Note)

Tasklets are the preferred way to implement deferrable functions in I/O drivers. As already explained,

tasklets are built on top of two softirqs named HI_SOFTIRQ and TASKLET_SOFTIRQ. Several tasklets

may be associated with the same softirq, each tasklet carrying its own function. There is no difference

between the two softirqs, excpet that do_softirq() executes HI_SOFTIRQ‘s tasklets before TASKLET_SO

FTIRQ‘s tasklets.

Tasklets and high-priority tasklets are stored in the tasklet_vec and tasklet_hi_vec arrays, respectively.

Both of them include NR_CPUS elements of type tasklet_head, and each element consists of a pointer to a

list of tasklet descriptors. The tasklet descriptor is a data structure of type tasklet_struct, whose fields are

shown in following table:

field name              Description

next                 Point to next descriptor in the list

state                  Status of the tasklet

count                  Lock counter

func                  Pointer to the tasklet function

data                  An unsigned long integer that may be used by the tasklet function

The state 0f field of the tasklet descriptor includes two flags:

TASKLET_STATE_SCHED: when set, this indicates that the tasklets is pending (has been scheduled for execution);

it also means that the tasklet description is inserted in one of the lists of the tasklet_vec and tasklet_hi_vec arrays.

TASKLET_STATE_RUN: when set, this includes that the tasklet is being executed; on a uniprocessor system this flag

is not used because there is no need to check whether a specific tasklet is running.

Let‘s suppose you‘re writing a device driver and you want to use a tasklet: what has to be done? First of all, you should

allocate a new tasklet_struct data structure and initialize it by invoking tasklet_init(); this function receives as its parameters

the address of the tasklet descriptor, the address of your tasklet function, and its optional integer argument.

The tasklet may be selectively disabled by invoking either tasklet_disable_nosync() or tasklet_disable(). Both functions

increase the count field of the tasklet descriptor, but the latter function does not return until an already running instance

of the tasklet function has terminated. To enable the tasklet, use tasklet_enable().

To active the tasklet, you should invoke either the tasklet_schedule() function or tasklet_hi_schedule() function, according

to the priority that you require for the tasklet. The two functions are very similar, each of them performs the following

actions:

1. Checks the TASKLET_STATE_SCHED flag; if it is set, returns (the tasklet has already been scheduled).

2. Invokes local_irq_save to save the state of the IF flag and to disable local interrupts.

3. Adds the tasklet descriptor at the beginning of the list pointed to by the tasklet_vec[n] or tasklet_hi_vec[n], where n

denotes the logical number of the local CPU.

4. Invokes raise_softirq_irqoff() to activate either the TASKLET_SOFTIRQ or the HI_SOFTIRQ softirq (this function is similar to

raise_softirq(), except that is assumes that local interrupts are alreay disabled).

5. Invokes local_irq_restore to restore the state of the IF flag.

时间: 2024-10-05 03:02:02

ULK --- Chap 4: Tasklets (Note)的相关文章

ULK --- Chap 4: Softirqs and Tasklets (Note)

We mentioned earlier in the section "Interrupt Handling" that several tasks among those executed by the kernel are not critical: they can be deferred for along period of time, if necessary. Remember that the interrupt service routines of an inte

ULK --- Chap 4: Interrupts and Exceptions (Note)

The Intel documentation classifies interrupts and exceptions as follows: 1. Interrupts: Maskable interrupts: All Interrupt ReQuests (IRQs) issued by I/O devices give rise to maksable interrupts. A maskable interrupt can be in two states: maksed or un

ULK --- Chap 4: Interrupts and Exceptions

An interrupt is usually defined as an event that alters the sequence of instructions executed by a processor. Such events correspond to electrical signals generated by hardware circuits both inside and outside chip. Interrupts are often divided into

383.判断一个字符串是否能够包含另外一个字符串 Ransom Note

Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; otherwise, it will return false. Each letter in the

thinking in java ----reading note (1)

# thinking in java 4th# reading note# victor# 2016.02.10 chapter 1 对象入门 1.1 抽象的进步    (1) 所有东西都是对象.    (2) 程序是一大堆对象的组合,对象间通过消息联系.    (3) 通过封装现有对象,可制作出新型对象.    (4) 每个对象都有一种类型(某个类的实例).    (5) 同一类的所有对象都能接受相同的消息.    1.2 对象的接口 & 1.3 实现方法的隐藏     接口规定了可对一个特定

三星note手机上html5画面模糊解决方案

最近测试发现,html5游戏在三星note手机上初次加载都会模糊,刷新之后就不模糊了,不知道是什么原因,本人对底层的东西也不熟,后来问了个同事,找到个解决方案,现记录一下. <meta name="viewport" content="width=device-width,target-densitydpi=device-dpi,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no&

Kali linux learning note

from:http://blog.sina.com.cn/s/blog_40983e5e0101dhz0.html 因为kali linux基于debian 7,当然要把这台Acer 4736z原有的debian 7删掉装kali啦,哈哈,这下不必为了BT5装虚拟机了,对于本子里60G的SSD来说还是好事一桩.要把kali当做桌面使用,就必须给kali添加一些软件,修改一些设置才好用,下面记录一下备忘,随时更新. 安装方法,官方文档,硬盘安装Kali Linux 把apt源设为官方提供的国内镜像

PPP验证(PAP和CHAP)

PPP协议:点对点协议,是一种点到点方式的链路层协议,它是在SLIP协议的基础上发展起来的. PPP的主要组成及其作用如下: 1:链路控制协议(LCP):主要用于管理PPP数据链路,包括进行链路层参数的协商,建立,拆除和监控数据链路等. 2:网络控制协议(NCP):主要用于协商所承载的网络层协议的类型及其属性,协商在该数据链路上所传输的数据包的格式与类型,配置哇甘咯层协议等. 3:验证协议PAP和CHAP:主要用来验证PPP对端设备的身份合法性,在一定程度上保证链路的安全性. PPP验证: 一:

Beginning Scala study note(8) Scala Type System

1. Unified Type System Scala has a unified type system, enclosed by the type Any at the top of the hierarchy and the type Nothing at the bottom of the hierarchy. All Scala types inherit from Any. # Using Any, Book extends AnyRef, and x is an Int that