linux – 是否有可能从sched_entity中找到相应的task_struct?
发布时间:2020-12-14 00:52:18 所属栏目:Linux 来源:网络整理
导读:我知道如果我们有task_struct,我们可以得到包含的sched_entity,因为它是任务结构中的一个字段.但是我们可以在给定shed_entity的情况下获得指向task_struct的指针吗?以下是sched_entity结构: struct sched_entity { struct load_weight load; /* for load-b
我知道如果我们有task_struct,我们可以得到包含的sched_entity,因为它是任务结构中的一个字段.但是我们可以在给定shed_entity的情况下获得指向task_struct的指针吗?以下是sched_entity结构:
struct sched_entity { struct load_weight load; /* for load-balancing */ struct rb_node run_node; struct list_head group_node; unsigned int on_rq; u64 exec_start; u64 sum_exec_runtime; u64 vruntime; u64 prev_sum_exec_runtime; u64 nr_migrations; #ifdef CONFIG_SCHEDSTATS struct sched_statistics statistics; #endif #ifdef CONFIG_FAIR_GROUP_SCHED struct sched_entity *parent; /* rq on which this entity is (to be) queued: */ struct cfs_rq *cfs_rq; /* rq "owned" by this entity/group: */ struct cfs_rq *my_q; #endif }; 似乎没有地方可以获得task_struct.我的最终目标是使用此shed_entity获取包含任务的任务group_leader的sched_entity:> 解决方法
Linux内核代码提供了一种标准方法来获取指向结构中包含的元素的指针,并获取指向包含结构的指针:
container_of 宏,它在整个内核中广泛使用.
在这种情况下,如果你有一个struct sched_entity * foo,你可以得到封闭的task_struct: struct task_struct *task = container_of(foo,struct task_struct,se); (显然,如果您确定原始struct sched_entity *指针指向struct sched_entity,它位于struct task_struct中,那么这是安全的,所以要小心……) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |