diff --git a/task3/Readme.md b/task3/Readme.md new file mode 100644 index 0000000..f8fb28b --- /dev/null +++ b/task3/Readme.md @@ -0,0 +1 @@ +Ожидается, что исходники ядра лежат в dev/linux-6.7.4/ diff --git a/task3/patch b/task3/patch new file mode 100644 index 0000000..3a1f3ea --- /dev/null +++ b/task3/patch @@ -0,0 +1,84 @@ +diff --git a/dev/linux-6.7.4/fs/proc/base.c b/dev/linux-6.7.4/fs/proc/base.c +index dd31e3b..3f1b03e 100644 +--- a/dev/linux-6.7.4/fs/proc/base.c ++++ b/dev/linux-6.7.4/fs/proc/base.c +@@ -488,6 +488,17 @@ static int proc_pid_schedstat(struct seq_file *m, struct pid_namespace *ns, + } + #endif + ++static int proc_pid_sched_counter(struct seq_file *m, struct pid_namespace *ns, ++ struct pid *pid, struct task_struct *task) ++{ ++ if (unlikely(!sched_info_on())) ++ seq_puts(m, "0\n"); ++ else ++ seq_printf(m, "%d\n", atomic_read(&task->sched_counter)); ++ ++ return 0; ++} ++ + #ifdef CONFIG_LATENCYTOP + static int lstats_show_proc(struct seq_file *m, void *v) + { +@@ -3293,6 +3304,7 @@ static const struct pid_entry tgid_base_stuff[] = { + REG("smaps_rollup", S_IRUGO, proc_pid_smaps_rollup_operations), + REG("pagemap", S_IRUSR, proc_pagemap_operations), + #endif ++ ONE("sched_counter", S_IRUGO, proc_pid_sched_counter), + #ifdef CONFIG_SECURITY + DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations), + #endif +@@ -3642,6 +3654,7 @@ static const struct pid_entry tid_base_stuff[] = { + REG("smaps_rollup", S_IRUGO, proc_pid_smaps_rollup_operations), + REG("pagemap", S_IRUSR, proc_pagemap_operations), + #endif ++ ONE("sched_counter", S_IRUGO, proc_pid_sched_counter), + #ifdef CONFIG_SECURITY + DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations), + #endif +diff --git a/dev/linux-6.7.4/include/linux/sched.h b/dev/linux-6.7.4/include/linux/sched.h +index 292c316..f6e71ab 100644 +--- a/dev/linux-6.7.4/include/linux/sched.h ++++ b/dev/linux-6.7.4/include/linux/sched.h +@@ -751,6 +751,9 @@ struct task_struct { + */ + struct thread_info thread_info; + #endif ++ /* Task 3 field */ ++ atomic_t sched_counter; ++ + unsigned int __state; + + /* saved state for "spinlock sleepers" */ +@@ -1385,6 +1388,7 @@ struct task_struct { + #endif + + #ifdef CONFIG_FUNCTION_GRAPH_TRACER ++ + /* Index of current stored address in ret_stack: */ + int curr_ret_stack; + int curr_ret_depth; +diff --git a/dev/linux-6.7.4/init/init_task.c b/dev/linux-6.7.4/init/init_task.c +index 5727d42..67a83ec 100644 +--- a/dev/linux-6.7.4/init/init_task.c ++++ b/dev/linux-6.7.4/init/init_task.c +@@ -71,6 +71,7 @@ struct task_struct init_task + .thread_info = INIT_THREAD_INFO(init_task), + .stack_refcount = REFCOUNT_INIT(1), + #endif ++ .sched_counter = ATOMIC_INIT(0), + .__state = 0, + .stack = init_stack, + .usage = REFCOUNT_INIT(2), +diff --git a/dev/linux-6.7.4/kernel/sched/core.c b/dev/linux-6.7.4/kernel/sched/core.c +index a708d22..1d7d4d7 100644 +--- a/dev/linux-6.7.4/kernel/sched/core.c ++++ b/dev/linux-6.7.4/kernel/sched/core.c +@@ -6650,6 +6650,7 @@ static void __sched notrace __schedule(unsigned int sched_mode) + } + + next = pick_next_task(rq, prev, &rf); ++ atomic_inc(&next->sched_counter); + clear_tsk_need_resched(prev); + clear_preempt_need_resched(); + #ifdef CONFIG_SCHED_DEBUG