Linux   发布时间:2022-04-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了linux – 是否有可能从sched_entity中找到相应的task_struct?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我知道如果我们有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?所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。