ULK --- Chap 4: Tasklets (Note)

本文介绍了在I/O驱动程序中使用Tasklets的方法。Tasklets是实现可延迟功能的首选方式,它们基于HI_SOFTIRQ和TASKLET_SOFTIRQ两个软中断。文章详细解释了Tasklets的数据结构、状态标志及如何初始化、调度和禁用Tasklets。

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.

 

转载于:https://www.cnblogs.com/miaoyong/p/5014978.html

POST /gate1/custom/file/upload HTTP/1.1 Host: gzmh.zwfw.guizhou.gov.cn User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0 Accept: application/json, text/plain, */* Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 Accept-Encoding: gzip, deflate Authorization: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhbm9ueW1vdXMiLCJhdWQiOiIiLCJzZXJ2ZXIiOiJodHRwczovL2pjdGMuendmdy5ndWl6aG91Lmdvdi5jbi8iLCJyb2xlIjoiIiwic3RhdHVzIjoiMyIsImlzcyI6Imluc3B1ciIsImp0aSI6ImVmMTkzYTFkLTZkYTktNDkzZS1hMDFlLWI0NTVlOTE0MjViZiIsImlhdCI6MTc1MjgyNTk3NiwiZXhwIjoxNzUyODU1OTc2fQ.zqvcQ5kL148hFg6wQ07Yk90aKlE_MEueh-N6efSg5w3naIZk1WfLrDq0N33SaUTG10cfYqnqDUiqtZWe5igJdA Content-Type: multipart/form-data; boundary=----geckoformboundary6a3e09b9a5fb4126dca45a3ceeadda1d Content-Length: 717 Origin: https://jctc.zwfw.guizhou.gov.cn Referer: https://jctc.zwfw.guizhou.gov.cn/ Sec-Fetch-Dest: empty Sec-Fetch-Mode: cors Sec-Fetch-Site: same-site Te: trailers Connection: close ------geckoformboundary6a3e09b9a5fb4126dca45a3ceeadda1d Content-Disposition: form-data; name="uid" 58888 ------geckoformboundary6a3e09b9a5fb4126dca45a3ceeadda1d Content-Disposition: form-data; name="type" doc ------geckoformboundary6a3e09b9a5fb4126dca45a3ceeadda1d Content-Disposition: form-data; name="folder_name" /ect/../ ------geckoformboundary6a3e09b9a5fb4126dca45a3ceeadda1d Content-Disposition: form-data; name="file"; filename="123.txt" Content-Type: text/plain invalid_base64 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= BTjNhGQSBd0O8zjDtX9yr/RiTak+WXtecYFP1SrxpUx3uLK/KZqApdMt2KkfFmx/UK4vyboeDAauJA1NFm9osQ== ------geckoformboundary6a3e09b9a5fb4126dca45a3ceeadda1d-- 分析该请求包
07-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值