Linux 2.6.33的sched_fair.c中定义的run_节点在哪里?
我正在读书 它使用2.6.33内核进行演示 我一直在浏览源代码的某些部分,但找不到很多东西的初始定义。很多东西只是被使用,比如“魔法”,我没有找到它的定义 一个例子:Linux 2.6.33的sched_fair.c中定义的run_节点在哪里?,c,linux,linux-kernel,include,C,Linux,Linux Kernel,Include,我正在读书 它使用2.6.33内核进行演示 我一直在浏览源代码的某些部分,但找不到很多东西的初始定义。很多东西只是被使用,比如“魔法”,我没有找到它的定义 一个例子: static struct sched_entity *__pick_next_entity(struct cfs_rq *cfs_rq) { struct rb_node *left = cfs_rq->rb_leftmost; if (!left) return NULL; r
static struct sched_entity *__pick_next_entity(struct cfs_rq *cfs_rq)
{
struct rb_node *left = cfs_rq->rb_leftmost;
if (!left)
return NULL;
return rb_entry(left, struct sched_entity, run_node);
}
static struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq)
{
struct rb_node *last = rb_last(&cfs_rq->tasks_timeline);
if (!last)
return NULL;
return rb_entry(last, struct sched_entity, run_node);
}
这在2.6.33内核的kernel/sched_fair.c
行384
和394
中
run\u节点从哪里来
我已经对整个源代码库进行了grep,并且我还没有找到任何允许它这样使用的run\u node
的定义
在sched_entity
结构中有一个属性,但是在它之外没有任何东西允许这样使用它
我无法理解事物是如何组织的,它真的令人困惑
发生了什么?您看到的run\u节点
不是变量,而是结构的.run\u节点
字段
是一个宏,基本上是以下对象的别名:
container\u of()
宏用于在给定指向已知字段(ptr
)、结构类型(type
)和字段名(member
)的指针的情况下,获取指向结构的指针。在您的例子中,left
是指向某些struct sched\u实体
的run\u节点
字段的指针,因此container\u of()
基本上用于获取指向相应sched\u实体的指针
另见:
#define rb_entry(ptr, type, member) container_of(ptr, type, member)