【问题标题】:CFS scheduler: how to know which task is assigned to a sched_entity?CFS 调度程序:如何知道哪个任务分配给了 sched_entity?
【发布时间】:2012-06-05 13:36:40
【问题描述】:

我在 sched_fair.c 里面,我想记录一些东西.. 但我需要知道哪个任务 (pid) 与我看到的每个 sched_entity 相关联.. 在我不知道的 struct sched_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
};

【问题讨论】:

    标签: linux-kernel scheduling kernel


    【解决方案1】:

    鉴于 sched_entity *se :

    struct task_struct *p = task_of(se);

    给你包含任务结构..

    【讨论】:

      【解决方案2】:
       /* include/linux/kernel.h */
              #define container_of(ptr, type, member) ({              \
                  void *__mptr = (void *)(ptr);                   \
                  BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
                           !__same_type(*(ptr), void),            \
                           "pointer type mismatch in container_of()");    \
                  ((type *)(__mptr - offsetof(type, member))); })
              
              /* kernel/sched/fair.c */
              static inline struct task_struct *task_of(struct sched_entity *se)
              {
                  return container_of(se, struct task_struct, se);
              }
      

      方便但危险

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-05
        • 2012-12-27
        • 2014-02-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-15
        相关资源
        最近更新 更多