[Linux kernel] real-time scheduling class ④ (real-time run queue rt_rq source code analysis | real-time run queue rt_rq structure field analysis | active, rt_nr_running, curr, next fields)





1. Real-time running queue rt_rq source code



In [Linux Kernel] Real-time Scheduling Class ② (Real-time scheduling entity sched_rt_entity source code analysis | run_list, timeout, watchdog_stamp, time_slice fields) blog, briefly introduced linux-5.6.18\include\linux\sched.hthe real-time scheduling entity sched_rt_entity source code defined in the header file,

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;

The rt_rqand my_qfields, which respectively represent a "real-time running queue", are of rt_rqstructure type;

rt_rqStructure, defined in the Linux kernel source linux-5.6.18\kernel\sched\sched.hheader file;

/* 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
};

insert image description here





Second, the real-time run queue rt_rq structure field analysis




1. Active field


A field in the "real-time run queue" structurert_rq , representing a "priority queue";active

struct rt_prio_array	active;

2. rt_nr_running field


A field in the "Real -time Run Queue" structurert_rq , indicating the number of all active tasks in the "Real-time Run Queue" ;rt_nr_running

unsigned int		rt_nr_running;

3. curr field


The field in the "Real -time Run Queue" structurert_rq represents the highest priority among all real-time tasks in the "Real-time Run Queue" ;curr

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

4. next field


The field in the "Real -time Run Queue" structurert_rq represents the second highest priority among all real-time tasks in the " Real-time Run Queue" ; if the first two highest priorities are the same, the value of the field is equal to;nextcurrnext

int		next; /* next highest */

Guess you like

Origin blog.csdn.net/han1202012/article/details/123882680