【发布时间】:2013-08-04 13:07:34
【问题描述】:
我想知道每个进程的下一个和上一个进程,它的状态是“TASK_RUNNING”。 在较旧的内核中,有一个 run_list 结构作为 task_struct 的成员。我怎样才能在内核 3 中做这样的事情?例如跟踪正在运行的进程列表,但我不知道内核 3 中将哪个结构定义为此类列表。
【问题讨论】:
标签: process linux-kernel scheduling
我想知道每个进程的下一个和上一个进程,它的状态是“TASK_RUNNING”。 在较旧的内核中,有一个 run_list 结构作为 task_struct 的成员。我怎样才能在内核 3 中做这样的事情?例如跟踪正在运行的进程列表,但我不知道内核 3 中将哪个结构定义为此类列表。
【问题讨论】:
标签: process linux-kernel scheduling
在较新的内核中,Linux 不会维护所有正在运行的进程的列表。相反,CFS 使用 sched_entity 的红黑树来存储有关正在运行的进程的信息。
task_struct 包含 sched_entity 类型的成员 se。计划实体包含struct rb_node 类型的成员run_node。这就是你要找的。p>
rbtree接口请咨询include/linux/rbtree.h。要从sched_entity 中提取task_struct,您可以使用container_of(your_se, struct task_struct, se);(请参阅kernel/sched/fair.c 中的task_of())。
【讨论】:
rb tree作为正在运行的进程列表?
INTERRUPTABLE) ,它没有sched_entity?或者它有 sched_entity 但为空。
task_struct 中,因此它在任何情况下都存在。如果任务没有运行,sched_entity 不会在 rbtree 中链接。所以,你不能遍历它。
kernel/sched/fair.c 中看到了cfs_rq (runqueue)。它们包含sched_entities 中的sched_entities just ordered by priorities? and there's only one rbtree`,划分为多个运行队列?