struct task_struct

struct task_struct{
#ifdef CONFIG_THREAD_INFO_IN_TASK
	/*
	 * For reasons of header soup (see current_thread_info()), this
	 * must be the first element of task_struct.
	 */
	struct thread_info		thread_info;
#endif
	/* -1 unrunnable不可运行, 0 runnable可运行, >0 stopped已经停止: */
	/* 进程状态TASK_RUNNING、TASK_INTERRUPTIBLE、TASK_UNINTERRUPTIBLE、TASK_STOPPED、TASK_TRACED */
	volatile long			state;

	/*
	 * This begins the randomizable portion of task_struct. Only
	 * scheduling-critical items should be added above here.
	 */
	randomized_struct_fields_start

	/* 进程内核栈。Linux内核通过thread_union联合体来表示进程的内核栈,其中THREAD_SIZE宏的大小为8192.通过
	alloc_thread_info函数分配它的内核栈,通过free_thread_info函数释放所分配的内核栈 */
	void				*stack;
	
	/*进程描述符的使用计数,被置为2时,表示进程描述符正在被使用而且其相应的进程处于活动状态 */
	atomic_t			usage;
	/
	/* Per task flags (PF_*), defined further below: */
	/* 进程标志。进程当前的标志状态,但不是运行状态,用于内核识别进程当前的状态,以备下一步操作PF_FORKNOEXEC、PF_SUPERPRIV、PF_DUMPCORE */
	unsigned int			flags;
	unsigned int			ptrace;

#ifdef CONFIG_SMP
	struct llist_node		wake_entry;
	/* 在SMP上帮助实现无加锁的进程切换 */
	int				on_cpu;
#ifdef CONFIG_THREAD_INFO_IN_TASK
	/* Current CPU: */
	unsigned int			cpu;
#endif
	unsigned int			wakee_flips;
	unsigned long			wakee_flip_decay_ts;
	struct task_struct		*last_wakee;

	/*
	 * recent_used_cpu is initially set as the last CPU used by a task
	 * that wakes affine another task. Waker/wakee relationships can
	 * push tasks around a CPU where each wakeup moves to the next one.
	 * Tracking a recently used CPU allows a quick search for a recently
	 * used CPU that may be idle.
	 */
	int				recent_used_cpu;
	int				wake_cpu;
#endif
	int				on_rq;

	/* 表示动态优先级,根据static_prio和交互性奖罚算出 */
	int				prio;
	/* 进程的静态优先级,在进程创建时确定,范围从-20到19,值越小,优先级越高 */
	int				static_prio;
	/* 该优先级取决于静态优先级和调度策略 */
	int				normal_prio;
	/* 用于保存实时优先级,范围是0到MAX_RT_PRIO-1(即99) */
	unsigned int			rt_priority;

	/* 调度类 */
	const struct sched_class	*sched_class;
	
	/* 普通进程的调用实体,每个进程都有其中之一的实体 */
	struct sched_entity		se;
	
	/* 实时进程的调用实体,每个进程都有其中之一的实体 */
	struct sched_rt_entity		rt;
#ifdef CONFIG_CGROUP_SCHED
	struct task_group		*sched_task_group;
#endif
	struct sched_dl_entity		dl;

#ifdef CONFIG_PREEMPT_NOTIFIERS
	/* List of struct preempt_notifier: */
	/* preempt_notifiers结构体链表 */
	struct hlist_head		preempt_notifiers;
#endif

#ifdef CONFIG_BLK_DEV_IO_TRACE
	/* blktrace是一个针对Linux内核中块设备IO层的跟踪工具   */
	unsigned int			btrace_seq;
#endif

	unsigned int			policy;
	int				nr_cpus_allowed;
	cpumask_t			cpus_allowed;

/* RCU同步原语 */
#ifdef CONFIG_PREEMPT_RCU
	int				rcu_read_lock_nesting;
	union rcu_special		rcu_read_unlock_special;
	struct list_head		rcu_node_entry;
	struct rcu_node			*rcu_blocked_node;
#endif /* #ifdef CONFIG_PREEMPT_RCU */

#ifdef CONFIG_TASKS_RCU
	unsigned long			rcu_tasks_nvcsw;
	u8				rcu_tasks_holdout;
	u8				rcu_tasks_idx;
	int				rcu_tasks_idle_cpu;
	struct list_head		rcu_tasks_holdout_list;
#endif /* #ifdef CONFIG_TASKS_RCU */

	/* 用于调度器统计进程的运行信息 */
	struct sched_info		sched_info;

	/* 用于构建进程链表 */
	struct list_head		tasks;
#ifdef CONFIG_SMP
	struct plist_node		pushable_tasks;
	struct rb_node			pushable_dl_tasks;
#endif

	/* 进程所拥有的用户空间内存描述符,内核线程无的mm为NULL */
	struct mm_struct		*mm;

	/* 指向进程运行时所使用的内存描述符,对于普通进程而言,这两个指针变量的值相同。但是内核线程kernel thread
	是没有进程地址空间的,所以内核线程的tsk->mm域是空NULL。但是内核必须知道用户空间包含了什么,因此它的active_mm
	成员被初始化为前一个运行进程的active_mm值*/
	struct mm_struct		*active_mm;

	/* Per-thread vma caching: */
	struct vmacache			vmacache;

#ifdef SPLIT_RSS_COUNTING
	struct task_rss_stat		rss_stat;
#endif
	int				exit_state;

	/* 用于设置进程的终止代号,这个值要么是_exit()或exit_group()系统调用参数(正常终止),要么是由内核提供的一个错误代号(异常终止) */
	int				exit_code;

	/* 被设置为-
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值