linux – 是否有可能从sched_entity中找到相应的task_struct?

linux – 是否有可能从sched_entity中找到相应的task_struct?,第1张

概述我知道如果我们有task_struct,我们可以得到包含的sched_entity,因为它是任务结构中的一个字段.但是我们可以在给定shed_entity的情况下获得指向task_struct的指针吗?以下是sched_entity结构: struct sched_entity { struct load_weight load; /* for load-balancing 我知道如果我们有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中,那么这是安全的,所以要小心……)

总结

以上是内存溢出为你收集整理的linux – 是否有可能从sched_entity中找到相应的task_struct?全部内容,希望文章能够帮你解决linux – 是否有可能从sched_entity中找到相应的task_struct?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/yw/1025048.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存