• net_dev_init


    Kernel: 4.12.6

    网络设备初始化,主要包括初始化softnet_data,注册收发包软中断等;

     1 static int __init net_dev_init(void)
     2 {
     3     int i, rc = -ENOMEM;
     4 
     5     BUG_ON(!dev_boot_phase);
     6 
     7     //初始化统计信息的proc文件
     8     if (dev_proc_init())
     9         goto out;
    10 
    11     //初始化kobject
    12     if (netdev_kobject_init())
    13         goto out;
    14 
    15     //初始化协议类型链表
    16     INIT_LIST_HEAD(&ptype_all);
    17 
    18     //初始化协议类型hash表
    19     for (i = 0; i < PTYPE_HASH_SIZE; i++)
    20         INIT_LIST_HEAD(&ptype_base[i]);
    21 
    22     //初始化offload列表
    23     INIT_LIST_HEAD(&offload_base);
    24 
    25     //注册网络命名空间子系统
    26     if (register_pernet_subsys(&netdev_net_ops))
    27         goto out;
    28 
    29     /*
    30      *    Initialise the packet receive queues.
    31      */
    32     //初始化数据包接收队列
    33     for_each_possible_cpu(i) {
    34         struct work_struct *flush = per_cpu_ptr(&flush_works, i);
    35         struct softnet_data *sd = &per_cpu(softnet_data, i);
    36 
    37         //初始化清理backlog队列
    38         INIT_WORK(flush, flush_backlog);
    39 
    40         //初始化非napi接口层的缓存队列
    41         skb_queue_head_init(&sd->input_pkt_queue);
    42 
    43         //初始化数据包处理队列        
    44         skb_queue_head_init(&sd->process_queue);
    45 
    46         //初始化网络设备轮询队列
    47         INIT_LIST_HEAD(&sd->poll_list);
    48 
    49         //初始化输出队列尾部
    50         sd->output_queue_tailp = &sd->output_queue;
    51 
    52         //若支持RPS
    53 #ifdef CONFIG_RPS
    54         sd->csd.func = rps_trigger_softirq;
    55         sd->csd.info = sd;
    56         sd->cpu = i;
    57 #endif
    58 
    59         //支持非napi虚拟设备的回调和配额设置
    60         sd->backlog.poll = process_backlog;
    61         sd->backlog.weight = weight_p;
    62     }
    63 
    64     dev_boot_phase = 0;
    65 
    66     /* The loopback device is special if any other network devices
    67      * is present in a network namespace the loopback device must
    68      * be present. Since we now dynamically allocate and free the
    69      * loopback device ensure this invariant is maintained by
    70      * keeping the loopback device as the first device on the
    71      * list of network devices.  Ensuring the loopback devices
    72      * is the first device that appears and the last network device
    73      * that disappears.
    74      */
    75     //注册回环设备
    76     if (register_pernet_device(&loopback_net_ops))
    77         goto out;
    78 
    79     if (register_pernet_device(&default_device_ops))
    80         goto out;
    81 
    82     //注册发送软中断
    83     open_softirq(NET_TX_SOFTIRQ, net_tx_action);
    84 
    85     //注册接收软中断
    86     open_softirq(NET_RX_SOFTIRQ, net_rx_action);
    87 
    88     //注册响应cpu状态变化的回调
    89     rc = cpuhp_setup_state_nocalls(CPUHP_NET_DEV_DEAD, "net/dev:dead",
    90                        NULL, dev_cpu_dead);
    91     WARN_ON(rc < 0);
    92 
    93     //注册响应网络状态变化的回调
    94     dst_subsys_init();
    95     rc = 0;
    96 out:
    97     return rc;
    98 }
  • 相关阅读:
    关于OPC的研究1]c# opc client源码调试和学习笔记
    分治算法
    递归算法
    Linux 课程笔记 Nginx深入应用实践
    Linux课程笔记 Nginx介绍
    Linux课程笔记 Apache补充
    Linux课程笔记 Apache服务Forbidden 403故障分析
    Linux课程笔记 Apache的优化
    Linux课程笔记 Apache常用模块的介绍
    Linux课程笔记 Apache的介绍与安装
  • 原文地址:https://www.cnblogs.com/wanpengcoder/p/7414201.html
Copyright © 2020-2023  润新知