1.教材学习及与chatgpt的对话
https://chat.openai.com/share/9199ce74-bef5-4e82-b301-3f44a6d07e2b
2.实验楼
task_struct结构
task_struct
用于表示每个进程或线程的状态和相关信息。它包含了大量的字段,用于跟踪和管理进程的各种属性,如进程ID、父进程ID、调度信息、信号处理、资源限制、文件描述符表、内存管理信息等等。
struct task_struct {
volatile long state; /*表示进程的当前状态,可能是未运行-1可运行0或已停止(>0)*/
void *stack;
atomic_t usage; /* usage:一个原子计数器,用于跟踪进程的使用计数 */
unsigned int flags; /* 存储与进程相关的标志,这些标志可以包括进程的特定属性或状态信息 */
unsigned int ptrace; /*与进程跟踪相关的字段,用于跟踪进程的父进程或调试器*/
#ifdef CONFIG_SMP
struct llist_node wake_entry;
int on_cpu; /*在多处理器系统(SMP)中,表示进程当前正在哪个CPU上运行*/
struct task_struct *last_wakee;
unsigned long wakee_flips;
unsigned long wakee_flip_decay_ts;
int wake_cpu;
#endif
int on_rq;
int prio, static_prio, normal_prio; /*与进程调度相关的字段,包括进程的优先级信息*/
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;
/*se、rt、dl:与调度相关的实体,包括普通、实时和截止(deadline)调度的信息*?
#ifdef CONFIG_PREEMPT_NOTIFIERS
/*struct preempt_notifier的列表: */
struct hlist_head preempt_notifiers;
#endif
#ifdef CONFIG_BLK_DEV_IO_TRACE
unsigned int btrace_seq;
#endif
unsigned int policy;
/*调度策略,表示进程使用的调度策略,例如普通(SCHED_NORMAL)、先进先出(SCHED_FIFO)等。*/
int nr_cpus_allowed;
cpumask_t cpus_allowed;
#ifdef CONFIG_PREEMPT_RCU
int rcu_read_lock_nesting;
union rcu_special rcu_read_unlock_special;
struct list_head rcu_node_entry;
#endif /* #ifdef CONFIG_PREEMPT_RCU */
#ifdef CONFIG_TREE_PREEMPT_RCU
struct rcu_node *rcu_blocked_node;
#endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
#ifdef CONFIG_TASKS_RCU
unsigned long rcu_tasks_nvcsw;
bool rcu_tasks_holdout;
struct list_head rcu_tasks_holdout_list;
int rcu_tasks_idle_cpu;
#endif /* #ifdef CONFIG_TASKS_RCU */
#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
struct sched_info sched_info;
#endif
struct list_head tasks;
#ifdef CONFIG_SMP
struct plist_node pushable_tasks;
struct rb_node pushable_dl_tasks;
#endif
struct mm_struct *mm, *active_mm;
/*mm、active_mm:内存管理相关的字段,包括进程的内存描述符。mm指向当前进程的内存描述符,active_mm指向进程上下文切换时的备用内存描述符*/
#ifdef CONFIG_COMPAT_BRK
unsigned brk_randomized:1;
#endif
/* 每个线程的VMA缓存*/
u32 vmacache_seqnum;
struct vm_area_struct *vmacache[VMACACHE_SIZE];
#if defined(SPLIT_RSS_COUNTING)
struct task_rss_stat rss_stat;
#endif
/* 任务状态 */
int exit_state;
int exit_code, exit_signal;
int pdeath_signal; /* 当父进程死亡时发送的信号