【Linux 内核】实时调度类 ④ ( 实时运行队列 rt_rq 源码分析 | 实时运行队列 rt_rq 结构体字段分析 | active、rt_nr_running、curr、next 字段 )





一、实时运行队列 rt_rq 源码



【Linux 内核】实时调度类 ② ( 实时调度实体 sched_rt_entity 源码分析 | run_list、timeout、watchdog_stamp、time_slice 字段 ) 博客中 , 简单介绍了 在 linux-5.6.18\include\linux\sched.h 头文件中定义的 实时调度实体 sched_rt_entity 源码 ,

struct sched_rt_entity {
    
    
	struct list_head		run_list; 		// 用于将 " 实时调度实体 " 加入到 优先级队列 中的
	unsigned long			timeout; 		// 用于 设置 调度 超时时间
	unsigned long			watchdog_stamp;	// 用于 记录 jiffies 的值
	unsigned int			time_slice;		// 时间片
	unsigned short			on_rq;			
	unsigned short			on_list;

	struct sched_rt_entity		*back;		// 用于 由上到下 连接 " 实时调度实体 "
#ifdef CONFIG_RT_GROUP_SCHED
	struct sched_rt_entity		*parent;	// 指向 父类 " 实时调度实体 "
	/* rq on which this entity is (to be) queued: */
	struct rt_rq			*rt_rq;			// 表示 " 实时调度实体 " 所属的 " 实时运行队列 " 
	/* rq "owned" by this entity/group: */
	struct rt_rq			*my_q; // 表示 " 实时调度实体 " 所拥有的 " 实时运行队列 " , 用于管理 " 子任务 "
#endif
} __randomize_layout;

其中的 rt_rqmy_q 字段 , 分别表示一个 " 实时运行队列 " , 是 rt_rq 结构体类型的 ;

rt_rq 结构体 , 定义在 Linux 内核源码 linux-5.6.18\kernel\sched\sched.h 头文件中 ;

/* Real-Time classes' related field in a runqueue: */
struct rt_rq {
    
    
	struct rt_prio_array	active;
	unsigned int		rt_nr_running;
	unsigned int		rr_nr_running;
#if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED
	struct {
    
    
		int		curr; /* highest queued rt task prio */
#ifdef CONFIG_SMP
		int		next; /* next highest */
#endif
	} highest_prio;
#endif
#ifdef CONFIG_SMP
	unsigned long		rt_nr_migratory;
	unsigned long		rt_nr_total;
	int			overloaded;
	struct plist_head	pushable_tasks;

#endif /* CONFIG_SMP */
	int			rt_queued;

	int			rt_throttled;
	u64			rt_time;
	u64			rt_runtime;
	/* Nests inside the rq lock: */
	raw_spinlock_t		rt_runtime_lock;

#ifdef CONFIG_RT_GROUP_SCHED
	unsigned long		rt_nr_boosted;

	struct rq		*rq;
	struct task_group	*tg;
#endif
};

在这里插入图片描述





二、实时运行队列 rt_rq 结构体字段分析




1、active 字段


" 实时运行队列 " rt_rq 结构体中的 active 字段 , 表示 " 优先级队列 " ;

struct rt_prio_array	active;

2、rt_nr_running 字段


" 实时运行队列 " rt_rq 结构体中的 rt_nr_running 字段 , 表示在 " 实时运行队列 " 中 , 所有 活动的 任务数量 ;

unsigned int		rt_nr_running;

3、curr 字段


" 实时运行队列 " rt_rq 结构体中的 curr 字段 , 表示在 " 实时运行队列 " 中 , 所有 实时任务 中的 最高优先级 ;

int		curr; /* highest queued rt task prio */

4、next 字段


" 实时运行队列 " rt_rq 结构体中的 next 字段 , 表示在 " 实时运行队列 " 中 , 所有 实时任务 中的 第二高优先级 ; 如果前两个最高的优先级相同 , 则 currnext 字段值相等 ;

int		next; /* next highest */

猜你喜欢

转载自blog.csdn.net/han1202012/article/details/123882680
今日推荐