码迷,mamicode.com
首页 > 其他好文 > 详细

LKD: Chapter 8 Bottom Halves and Deferring Work

时间:2015-12-24 00:26:25      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:

  In 2.6.x, there are 3 mechanisms for implementing a bottom half: softirqs, tasklets and work queues. Here‘s the comparison:

技术分享

Softirqs:

  Softirqs are statically allocated at compile time. It is represented by the softirq_action structure, which is defined in <linux/interrupt.h>:

struct softirq_action {
    void (*action)(struct softirq_action *);
}

   A 32-entry array of this structure is declared in kernel/softirq.c:

static struct softirq_action softirq_vec[NR_SOFTIRQS];

  But in the current kernel, only nine exist:(as we will discuss later, tasklets are built off softirqs)

技术分享

  The prototype of a softirq handler looks like

void softirq_handler(struct softirq_action *)

  A softirq never preempts another softirq. The only event that can preempt a softirq is an interrupt handler.

Executing Softirqs:

  A registered softirq must be marked before it will execute. This is called raising the softirq.

  Softirq execution occurs in __do_softirq(), which is invoked by do_softirq(). If there are pending softirqs, __do_softirq() loops over each one, invoking its handler. Let‘s look at a simplified variant of the important part of __do_softirq():

u32 pending;

pending = local_softirq_pending();
if (pending) {
    struct softirq_action *h;

    /* reset the pending bitmask */
    set_softirq_pending(0);

    h = softirq_vec;
    do {
        if (pending & 1)
            h->action(h);
        h++;
        pending >>= 1;
    } while (pending);
}

Using Softirqs:

  Softirqs are reserved for the most timing-critical and important bottom-half processing on the system.  Currently, only two subsystems - networking and block devices - directly use softirqs.

  Registering Your Handler:

  The softirq handler is registered at run-time via open_softirq():

/* in net/core/dev.c */
/* two parameters: the sfotirq‘s index and its handler function */
open_softirq(NET_TX_SOFTIRQ, net_tx_action);

  Raising Your Softirq:

  To mark it pending, call raise_softirq():    

raise_softirq(NET_TX_SOFTIRQ);

  Then it is run at the next invocation of do_softirq().

LKD: Chapter 8 Bottom Halves and Deferring Work

标签:

原文地址:http://www.cnblogs.com/justforfun12/p/5071664.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!