4、等待队列 ●1inux使用等待队列来组织TASK RUNNING状态之外的进程 ·进程的等待状态 ★TASK_INTERRUPTIBLE和 TASK UNINTERRUPTIBLE ·进程状态提供的信息满足不了快速检索的需要 ·处于等待状态的进程根据等待的原因分成很多类, 每一类对应一个特定的事件。 ·内核使用等待队列来分类组织 。等待队列在内核中有很多用途,尤其是对中断处理、 进程同步和定时用处很大 。等待队列使得进程可以在事件的条件等待,并且当等 待的条件为奠时,由内核唤醒它们 1口+4四1是4P在刀0C 陈香兰(x1 anchenoustc,edu,en)(升界数应Linuxs掉作系统分行Chapter 0过在管理 Decenber23,201420/95
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4、等待队列 linux使用等待队列来组织TASK_RUNNING状态之外的进程 ▶ 进程的等待状态 ⋆ TASK_INTERRUPTIBLE和 ⋆ TASK_UNINTERRUPTIBLE ▶ 进程状态提供的信息满足不了快速检索的需要 ▶ 处于等待状态的进程根据等待的原因分成很多类, 每一类对应一个特定的事件。 ▶ 内核使用等待队列来分类组织 等待队列在内核中有很多用途,尤其是对中断处理、 进程同步和定时用处很大 等待队列使得进程可以在事件的条件等待,并且当等 待的条件为真时,由内核唤醒它们 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9 进程管理 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) December 23, 2014 20 / 95
4、等待队列 ·等待队列由循环链表实现 等待队列头节点,参见include/1inux/wait.h struct_wait_queue_head spinlock_t lock: struct list_head tasklist; } typedef struct_wait_queue_head wait_queue_head_t; 等待节点,参见include/1inux/wait.h typedef struct_wait_queue wait_queue_t; struct_wait_queue{ unsigned int flags: #define WQ_FLAG_EXCLUSIVE Ox01 void◆private; wait_queue_func_t func; struct list_head task_list: }: 4口4四1是14P刀00 陈香兰(x1 anchenoustc,edu.cm)(计异丸应Lnux掉作系统分折Chapter 9注任管理 Decenber23,201420/95
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4、等待队列 等待队列由循环链表实现 . 等待队列头节点,参见include/linux/wait.h . . struct __wait_queue_head { spinlock_t lock; struct list_head task_list; }; typedef struct __wait_queue_head wait_queue_head_t; . 等待节点,参见include/linux/wait.h . . typedef struct __wait_queue wait_queue_t; ... struct __wait_queue { unsigned int flags; #define WQ_FLAG_EXCLUSIVE 0x01 void *private; wait_queue_func_t func; struct list_head task_list; }; 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9 进程管理 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) December 23, 2014 20 / 95
4、等待队列 ●在等待队列上内核实现了一些操作函数,参见kernel/wait.c ,加入等待队列 ★add wait_queue add_wait_queue_exclusive 从等待队列删除 ★remove_wait_queue static inline void_add_wait_queue(wait_queue_head_t head,wait_queue_t *new){ 1ist_add(&new->task_list,&head->task_list); Used for wake-one threads: ◆/ static inline void_add_wait_queue_tail(wait_queue_head_t "head,wait_queue_t "new){ list_add_tail(&new->task_list,&head->task_list); static inline void_remove_wait_queue(wait_queue_head_t head,wait_queue_t old){ list_del(&old->task_list); 陈香兰(x1 anchenoustc,edu,cn)(升界丸应Linux:操作系统分行Chapter 9注在管理 Decenber 23.2014 20/95
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4、等待队列 在等待队列上内核实现了一些操作函数,参见kernel/wait.c ▶ 加入等待队列 ⋆ add_wait_queue ⋆ add_wait_queue_exclusive ▶ 从等待队列删除 ⋆ remove_wait_queue . . static inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new) { list_add(&new->task_list, &head->task_list); } /* * Used for wake-one threads: */ static inline void __add_wait_queue_tail(wait_queue_head_t *head, wait_queue_t *new) { list_add_tail(&new->task_list, &head->task_list); } static inline void __remove_wait_queue(wait_queue_head_t *head, wait_queue_t *old) { list_del(&old->task_list); } 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9 进程管理 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) December 23, 2014 20 / 95
Outline ○进程描逑符 o Linux的进程描速待:task struct 。进程的栈和thread info最据结拘 。进程相关的几个住表 ●proc文件系统简介 进租的等待和唤醒 进程切提 。进程上下文 a上下文切换 ●进程的创建和则南 。进程的创建 o Linux的进程创建 。内核线程及其创建 。进程树及其开焰 。近程的终止和刷 进调度 。进程的分美 aLix中的调度菜略和调度算法 o Linux-2.6.26中的调度相关数据结均和代码 0Ln山x2.6.26中的优先级及其设置 小结和作 4口4四1是14P刀00 东奇兰(x1 anchenoustc,ed加,cn)(计异款应Linux操作系统分折Chapter 9注任管理 Decenber23,201421/95
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Outline . 1. 进程描述符 Linux的进程描述符:task_struct 进程的栈和thread_info数据结构 进程相关的几个链表 proc文件系统简介 .2 进程的等待和唤醒 .3 进程切换 进程上下文 上下文切换 4. 进程的创建和删除 进程的创建 Linux的进程创建 内核线程及其创建 进程树及其开始 进程的终止和删除 5. 进程调度 进程的分类 Linux中的调度策略和调度算法 Linux-2.6.26中的调度相关数据结构和代码 Linux2.6.26中的优先级及其设置 .6 小结和作业 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9 进程管理 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) December 23, 2014 21 / 95
proc文件系统简介 ●阅读Documentation/filesystems/proc.txt o The proc file system acts as an interface to internal data structures in the kernel.It can be used to obtain information about the system and O to change certain kernel parameters at runtime (sysct1). CHAPTER 1:COLLECTING SYSTEM INFORMATION 1.1 Process-Specific Subdirectories 1.2 Kernel data 1.3 IDE devices in /proc/ide CHAPTER 2:MODIFYING SYSTEM PARAMETERS 1口4四1是42在刀0C 陈香兰(xlanchenoustc,edu,cn)(升界丸应L1nux操作系统分折Chapter 0连在管理. Decenber23,201422/95
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . proc文件系统简介 阅读Documentation/filesystems/proc.txt The proc file system acts as an interface to internal data structures in the kernel. It can be used 1. to obtain information about the system and 2. to change certain kernel parameters at runtime (sysctl). CHAPTER 1: COLLECTING SYSTEM INFORMATION ▶ 1.1 Process-Specific Subdirectories ▶ 1.2 Kernel data ▶ 1.3 IDE devices in /proc/ide ▶ ... CHAPTER 2: MODIFYING SYSTEM PARAMETERS ▶ ... 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9 进程管理 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) December 23, 2014 22 / 95