Tasklets is the preferred-implement deferrable functions in I/O drivers. As already explained,
Tasklets is built on top of the Softirqs named Hi_softirq and TASKLET_SOFTIRQ. Several tasklets
May is associated with the same SOFTIRQ and each tasklet carrying its own function. There is no difference
Between the Softirqs, excpet that DO_SOFTIRQ () executes HI_SOFTIRQ ' s tasklets before Tasklet_so
Ftirq ' s tasklets.
Tasklets and high-priority tasklets is stored in the Tasklet_vec and tasklet_hi_vec arrays, Respectivel Y.
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
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 so may used by the Tasklet function
The State 0f field of the Tasklet descriptor includes the flags:
tasklet_state_sched: When set, this indicates then the Tasklets is pending (have been scheduled for execution);
It also means that the Tasklet description are inserted in one of the lists of the Tasklet_vec and Tasklet_hi_vec arrays.
tasklet_state_run: When set, this includes then the tasklet is being executed; On a uniprocessor system this flag
Is isn't 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 have to is 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 is 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 does return until an already running Insta nCE
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, Accordi Ng
To the require of the tasklet. The functions is very similar, each of the them performs the following
Actions
1. Checks the tasklet_state_sched flag; If it is set, returns (the Tasklet have 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 Simil Ar to
RAISE_SOFTIRQ (), except that's assumes that local interrupts be alreay disabled).
5. Invokes Local_irq_restore to restore the state of the IF flag.
Ulk---Chap 4:tasklets (Note)