Kernel: 4.12.6

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

 static int __init net_dev_init(void)
{
int i, rc = -ENOMEM; BUG_ON(!dev_boot_phase); //初始化统计信息的proc文件
if (dev_proc_init())
goto out; //初始化kobject
if (netdev_kobject_init())
goto out; //初始化协议类型链表
INIT_LIST_HEAD(&ptype_all); //初始化协议类型hash表
for (i = ; i < PTYPE_HASH_SIZE; i++)
INIT_LIST_HEAD(&ptype_base[i]); //初始化offload列表
INIT_LIST_HEAD(&offload_base); //注册网络命名空间子系统
if (register_pernet_subsys(&netdev_net_ops))
goto out; /*
* Initialise the packet receive queues.
*/
//初始化数据包接收队列
for_each_possible_cpu(i) {
struct work_struct *flush = per_cpu_ptr(&flush_works, i);
struct softnet_data *sd = &per_cpu(softnet_data, i); //初始化清理backlog队列
INIT_WORK(flush, flush_backlog); //初始化非napi接口层的缓存队列
skb_queue_head_init(&sd->input_pkt_queue); //初始化数据包处理队列
skb_queue_head_init(&sd->process_queue); //初始化网络设备轮询队列
INIT_LIST_HEAD(&sd->poll_list); //初始化输出队列尾部
sd->output_queue_tailp = &sd->output_queue; //若支持RPS
#ifdef CONFIG_RPS
sd->csd.func = rps_trigger_softirq;
sd->csd.info = sd;
sd->cpu = i;
#endif //支持非napi虚拟设备的回调和配额设置
sd->backlog.poll = process_backlog;
sd->backlog.weight = weight_p;
} dev_boot_phase = ; /* The loopback device is special if any other network devices
* is present in a network namespace the loopback device must
* be present. Since we now dynamically allocate and free the
* loopback device ensure this invariant is maintained by
* keeping the loopback device as the first device on the
* list of network devices. Ensuring the loopback devices
* is the first device that appears and the last network device
* that disappears.
*/
//注册回环设备
if (register_pernet_device(&loopback_net_ops))
goto out; if (register_pernet_device(&default_device_ops))
goto out; //注册发送软中断
open_softirq(NET_TX_SOFTIRQ, net_tx_action); //注册接收软中断
open_softirq(NET_RX_SOFTIRQ, net_rx_action); //注册响应cpu状态变化的回调
rc = cpuhp_setup_state_nocalls(CPUHP_NET_DEV_DEAD, "net/dev:dead",
NULL, dev_cpu_dead);
WARN_ON(rc < ); //注册响应网络状态变化的回调
dst_subsys_init();
rc = ;
out:
return rc;
}

最新文章

  1. foreach
  2. JS数组键值,数组合并,
  3. Probit回归模型
  4. C# delegate &amp; event
  5. Java数组的复制
  6. bootstrap注意事项(一)
  7. Calendar.getInstance()获取当天指定点上的时间[转载]
  8. 【转】FIO使用指南
  9. 【Spring系列】Spring mvc整合druid
  10. 工作流程,编程,调试,性能:Unity游戏开发者应该学习的20个改进技巧
  11. Android进阶(九)APP编程感想
  12. Visual Studio Code快速删除空行及几个常用快捷键总结
  13. UDP单播,广播,多播
  14. vue的js文件中获取vue实例
  15. egg 官方文档之:框架扩展(Application、Context、Request、Response、Helper的访问方式及扩展)
  16. Data Consistency Primer
  17. python--面向对象(02)
  18. RabbitMq入门与基本使用
  19. n皇后问题(分析)
  20. IE浏览器报Promise未定义

热门文章

  1. Dubbo和Spring Cloud开发框架对比
  2. RT-thread内核之空闲线程
  3. BZOJ 1930 吃豆豆(费用流)
  4. BZOJ 1227 虔诚的墓主人(离散化+树状数组)
  5. 【刷题】UOJ #79 一般图最大匹配
  6. [NOIP2017]逛公园 最短路图 拓扑序DP
  7. BZOJ4566:[HAOI2016]找相同字符——题解
  8. 洛谷3805:【模板】manacher算法——题解
  9. 从零开始学Linux系统(四)之Vi/Vim操作指令
  10. React高阶组件总结