Linux 2.6.33的sched_fair.c中的run_node在哪里定义?

问题描述 投票:0回答:1

我正在阅读Robert Love's Book Linux Kernel Development

它使用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;

    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.c384394中。

run_node来自哪里?

我已经在here上复制了整个源库,但是我没有发现run_node的任何定义可以像这样使用它。

declaration结构中有一个sched_entity,但没有任何东西可以像这样使用它。

我无法理解事物的组织方式,这确实令人困惑。

发生了什么事?

c linux linux-kernel include
1个回答
1
投票

您看到的run_node不是变量,它是.run_node结构的sched_entity字段。

sched_entity是一个宏,基本上是rb_entry()的别名:

rb_entry()

container_of()宏用于获得结构的指针,给定一个指向已知字段(container_of()),结构类型(#define rb_entry(ptr, type, member) container_of(ptr, type, member) )和字段名称(container_of())的指针。在您的情况下,ptr是指向某些typemember字段的指针,因此left基本上用于获取指向适当的run_node的指针。

另请参见:struct sched_entity

© www.soinside.com 2019 - 2024. All rights reserved.