zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    服务管理--systemctl命令
    dd if=/dev/zero of=的含义是什么?Linux 下的dd命令使用详解
    QML与Qt C++ 交互机制探讨与总结
    sync命令
    linux 下shell中if的“-e,-d,-f”是什么意思
    POJ 1936 All in All(模拟)
    POJ 1088 滑雪(记忆化搜索)
    POJ 3280 Cheapest Palindrome(DP 回文变形)
    POJ 3181 Dollar Dayz(高精度 动态规划)
    HDU 1114 Piggy-Bank(完全背包)
  • 原文地址:https://www.cnblogs.com/miaoyong/p/5014978.html
Copyright © 2011-2022 走看看