我在sched_fair.c里面,我想记录一些事情..但是我需要知道哪个任务(pid)与我看到的每个sched_entity相关联。在结构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
};发布于 2012-05-31 22:07:18
给定sched_entity *se:
结构task_struct *p = task_of(se);
为您提供包含任务结构..
发布于 2021-08-24 07:52:43
/* 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);
}这很方便,但也很危险
https://stackoverflow.com/questions/10831175
复制相似问题