linux学习之workqueue(Linux学习之workqueue).docVIP

  • 122
  • 0
  • 约1.08万字
  • 约 14页
  • 2017-08-20 发布于河南
  • 举报

linux学习之workqueue(Linux学习之workqueue).doc

linux学习之workqueue(Linux学习之workqueue)

linux学习之workqueue(Linux学习之workqueue) 文件路径:内核/内核/ C队列。 include/linux/h队列。 入口函数:init_workqueues() -创建每个CPU的workqueue -创建每个workqueue的调度员create_worker() -创建系统开机后一系列默认的workqueue。 如默认使用的schedule_work()即使用system_wq这个workqueue。 调用 create_worker() -为调度员工人分配内存 -根据on_unbound_cpu标志位确定采用依赖CPU的kthread_create_on_node() 还是不依赖CPU的kthread_create()来创建worker_thread, ~ 依赖CPU,则再绑定一下。 调用 worker_thread() -通过转到woke_up做死循环,确保该螺纹一直运行。无任务时转至空载(空闲)状态。 -通过need_more_worker()函数来确定当前是否有高优先级任务需要新开螺纹来执行。 -通过manage_workers()进行检查,调整创建工人时必须的两个条件, need_to_create_worker为真和may_start_working为假。 -执行核心process_one_work()。 PS,根据标志位优先执行高优先级任务所开辟的线程,也通过process_one_work()。 调用 process_one_work() -通过work_func_t F =工作-功能;取得用户驱动设置的处理函数 -如果全局的gcwq有高优先级的工作需要执行,唤醒执行。 -使用F(工作);来执行调用点的处理函数。即用户驱动的处理函数在这里将被执行。 -最后进行一些清理标记位,释放资源,删除工作的工作。 结束 H的队列。 create_workqueue()以及create_singlethread_workqueue()采用的是宏定义,调用宏alloc_workqueue()。 实际实现函数为__alloc_workqueue_key()函数。在__alloc_workqueue_key()中,主要就是分配内存,初始 化列表,初始化工人,创建工作者线程等工作。 CWQ: a global queue for a CPU The structure of struct work_struct {} for the user directly The structure of struct worker {} working thread used, mainly is used to manage the work to join in the queue, Determines whether a new thread needs to be opened, tasks in the execution queue, and so on, determining which thread worker_struct will execute by that thread. Struct global_cwq {} each CPU has a gcwq, mainly to complete the work queue except for emergency task memory recovery, And tasks in the CPU offline process, all tasks outside of these two tasks. These two tasks are extremely high priority and extremely urgent tasks, and they will be implemented directly by worker to avoid being managed. The work queue struct cpu_workqueue_struct {} on specific CPU Struct wq_flusher {} flush empties structure, is not important. Struct workqueue_struct {} the work queue structure, directly from the work_struct structure, if it is more than CPU, Work_struct is formed by cpu_workqueue_struct, and then the workqueue_struct is co

文档评论(0)

1亿VIP精品文档

相关文档