Linux network subsystem receiving packets soft interrupt

linux network subsystem packets when received and processed by the interrupt receiving processing for the soft packet.
Please refer to the specific process of receiving my other blog post

Here we analyze the deal to close at reception soft interrupt

Soft interrupt initialization message received

static int __init net_dev_init(void)
{
    ......
    open_softirq(NET_RX_SOFTIRQ, net_rx_action);
    ......
}

Message received soft interrupt handlers net_rx_action Comments:

static void  net_rx_action (struct softirq_action * H)
{
    / * made softnet_data local cpu of poll_list list * /
    struct the list_head * List = & __ get_cpu_var (softnet_data) .poll_list;
    / * Set the interrupt handler a maximum allowable execution time is two * of jiffies /
    unsigned Long time_limit of jiffies + = 2; 
    the number of packets / * set the interrupt receiving process is a function of a maximum * 300 /
    ; int Budget = netdev_budget
    time / off * cpu local interrupt, determines whether or not the following list is empty prevent hard preemption * /
    local_irq_disable ();

    / * wait processing loop processing napi on pool_list list * /
    the while (list_empty (List)!)
    {
        struct * n-napi_struct;
        Work int, weight;                                                                                                                                     
        / * If the processing packets exceeds the maximum processing time or the number of time exceeds a maximum allowed time to stop execution
          jumps to the softnet_break * /
        IF (Unlikely (Budget <= 0 || time_after (of jiffies, time_limit) ))
        {
            GOTO softnet_break;
        }
        / * local interrupt enable, the above list is empty determination has been completed, the following call NAPI
          polling function is executed * / case where the hardware interrupt open
        local_irq_enable ();                                                                                                                                     
        / * list acquired softnet_data pool_list a napi on,
           even now hard interrupt soft interrupt preemption, a napi will hang in to the end pool_list
           Pool_list soft interrupt only be removed from the head of a pool_list, so that the absence of a critical section * /
        n-LIST_ENTRY = (list-> Next, struct napi_struct, poll_list);

        / * record with weighe napi polling process allowed maximum packet number * /
        weight = N-> weight;
        / * number of a recording packet napi total work process * /
        work = 0;
  
        / * If the acquired state napi is scheduled, it performs a polling process of napi functions * /
        IF (test_bit (NAPI_STATE_SCHED, N- &> State))
        {
            Work =  N-> poll (n-, weight);
        }
        WARN_ON_ONCE (Work> weight);

        / * number of packets have been subtracted budget process * /
        budget - = Work ;

        / * disable local CPU interrupt, the following will not execute the finished NAPI linked to softnet_data
          operation of the tail, and there is a critical hardware interrupt area. And judges whether the while loop list
          is empty should prohibit hard preemption * /
        local_irq_disable ();
  
        / * If the number of packets napi polling process just processed is equal to the maximum number allowed,
          described no polling message processing portion to be treated completely * /
        IF (Unlikely (Work == weight))
        {
            / * If napi has been disabled, removed from the napi put the pool_list softnet_data * /
            IF (Unlikely (napi_disable_pending (n-)))
            {
                local_irq_enable ();
                napi_complete (n-);
                local_irq_disable ();
            }
            the else
            {
                / * otherwise , the trailing end of pool_list napi moved * /
                list_move_tail (N- &> poll_list, List);
            }
        }
    }
OUT:
    local_irq_enable ();
    return;
  
    / * If the treatment time expires, or the number of processed packets to the Maximum number of processing
      instructions as well as the packets need to have napi, scheduling software interrupt.
      Otherwise, indicating the soft interrupt packet processing requires processing on the part of the complete napi, no longer need to
      schedule a software interrupt * /
softnet_break:
    __get_cpu_var (netdev_rx_stat) .time_squeeze ++;
    __raise_softirq_irqoff (NET_RX_SOFTIRQ);
    GOTO OUT;
}

 
Published 64 original articles · won praise 171 · views 220 000 +

Guess you like

Origin blog.csdn.net/alpha_love/article/details/104580371