From 15628b32ba13ef359e1cdb93c2c4bf5b98bb4c8a Mon Sep 17 00:00:00 2001 From: ma_yulong Date: Fri, 27 Sep 2024 11:12:17 +0800 Subject: [PATCH] modify for frameRTG Signed-off-by: ma_yulong --- fs/proc/base.c | 3 +++ include/linux/sched.h | 6 ++++++ include/linux/sched/cpufreq.h | 1 + include/trace/events/rtg.h | 3 ++- init/Kconfig | 1 + kernel/sched/core.c | 5 +++++ kernel/sched/cpufreq_schedutil.c | 4 ++++ kernel/sched/fair.c | 8 +++++++- kernel/sched/rt.c | 2 +- kernel/sched/rtg/frame_rtg.h | 1 + kernel/sched/rtg/rtg.c | 13 +++++++++---- kernel/sched/rtg/rtg_ctrl.h | 1 + kernel/sched/sched.h | 4 ++++ 13 files changed, 45 insertions(+), 7 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 4ce5bcf38e42..efe96fe53147 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -107,6 +107,9 @@ #include #include #include +#ifdef CONFIG_SCHED_RTG +#include +#endif #include "internal.h" #include "fd.h" diff --git a/include/linux/sched.h b/include/linux/sched.h index b5e8ea71b57f..621115fb74f5 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -300,6 +300,12 @@ enum task_event { IRQ_UPDATE = 5, }; +/* Note: this need to be in sync with migrate_type_names array */ +enum migrate_types { + GROUP_TO_RQ, + RQ_TO_GROUP, +}; + #ifdef CONFIG_CPU_ISOLATION_OPT extern int sched_isolate_count(const cpumask_t *mask, bool include_offline); extern int sched_isolate_cpu(int cpu); diff --git a/include/linux/sched/cpufreq.h b/include/linux/sched/cpufreq.h index ee97c8e891c4..4d5600506a61 100644 --- a/include/linux/sched/cpufreq.h +++ b/include/linux/sched/cpufreq.h @@ -11,6 +11,7 @@ #define SCHED_CPUFREQ_IOWAIT (1U << 0) #define SCHED_CPUFREQ_WALT (1U << 1) #define SCHED_CPUFREQ_CONTINUE (1U << 2) +#define SCHED_CPUFREQ_FORCE_UPDATE (1U << 3) #ifdef CONFIG_CPU_FREQ struct cpufreq_policy; diff --git a/include/trace/events/rtg.h b/include/trace/events/rtg.h index b885e328de12..e447301300c3 100755 --- a/include/trace/events/rtg.h +++ b/include/trace/events/rtg.h @@ -8,6 +8,7 @@ #include #include #include +#include struct rq; @@ -65,7 +66,7 @@ TRACE_EVENT(sched_rtg_task_each, __entry->prio = task->prio; __assign_bitmask(allowed, cpumask_bits(&task->cpus_mask), num_possible_cpus()); __entry->cpu = task_cpu(task); - __entry->state = task->state; + __entry->state = task->__state; __entry->on_rq = task->on_rq; __entry->on_cpu = task->on_cpu; ), diff --git a/init/Kconfig b/init/Kconfig index aba34750256f..f67b31dac990 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -476,6 +476,7 @@ source "kernel/irq/Kconfig" source "kernel/time/Kconfig" source "kernel/bpf/Kconfig" source "kernel/Kconfig.preempt" +source "kernel/sched/rtg/Kconfig" menu "CPU/Task time and stats accounting" diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 1cd69897346a..b0e7289bc9c2 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -10744,6 +10744,7 @@ void __init sched_init(void) zalloc_cpumask_var_node(&rq->scratch_mask, GFP_KERNEL, cpu_to_node(i)); } + BUG_ON(alloc_related_thread_groups()); set_load_weight(&init_task, false); /* @@ -10769,6 +10770,10 @@ void __init sched_init(void) init_idle(current, smp_processor_id()); init_new_task_load(current); +#ifdef CONIG_QOS_CTRL + init_task_qos(current); +#endif + calc_load_update = jiffies + LOAD_FREQ; #ifdef CONFIG_SMP diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 927b86130390..84df61ab95c1 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -346,6 +346,9 @@ static void sugov_update_single_freq(struct update_util_data *hook, u64 time, unsigned int cached_freq = sg_policy->cached_raw_freq; unsigned long max_cap; unsigned int next_f; +#ifdef CONFIG_SCHED_RTG + bool force_update = false; +#endif #ifdef CONFIG_SCHED_RTG unsigned long irq_flag; @@ -469,6 +472,7 @@ sugov_update_shared(struct update_util_data *hook, u64 time, unsigned int flags) unsigned int next_f; #ifdef CONFIG_SCHED_RTG unsigned long irq_flag; + bool force_update = false; #endif #ifdef CONFIG_SCHED_RTG diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 8d6c84e89452..ebc86fdbeaf6 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -52,11 +52,15 @@ #include #include +#ifdef CONFIG_SCHED_RTG +#include +#endif #include "sched.h" #include "stats.h" #include "autogroup.h" #include "walt.h" +#include "rtg/rtg.h" #ifdef CONFIG_SCHED_WALT static void walt_fixup_sched_stats_fair(struct rq *rq, struct task_struct *p, @@ -8979,7 +8983,9 @@ enum migration_type { #define LBF_DST_PINNED 0x04 #define LBF_SOME_PINNED 0x08 #define LBF_ACTIVE_LB 0x10 - +#ifdef CONFIG_SCHED_RTG +#define LBF_IGNORE_PREFERRED_CLUSTER_TASKS 0x200 +#endif struct lb_env { struct sched_domain *sd; diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 3f281c4ed821..b26fb5c4bb27 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -1958,7 +1958,7 @@ static int find_cas_cpu(struct sched_domain *sd, } /* active LB or big_task favor cpus with more capacity */ - if (task->state == TASK_RUNNING || boosted) { + if (task->__state == TASK_RUNNING || boosted) { if (capacity_orig_of(cpu) > capacity_orig_of(cpumask_any(rtg_target))) { sg_target = sg; diff --git a/kernel/sched/rtg/frame_rtg.h b/kernel/sched/rtg/frame_rtg.h index 01f23d27413a..6bb25fa20721 100755 --- a/kernel/sched/rtg/frame_rtg.h +++ b/kernel/sched/rtg/frame_rtg.h @@ -12,6 +12,7 @@ #include #include #include +#include #define MULTI_FRAME_ID (DEFAULT_CGROUP_COLOC_ID + 1) #define MULTI_FRAME_NUM (MAX_NUM_CGROUP_COLOC_ID - DEFAULT_CGROUP_COLOC_ID - 1) diff --git a/kernel/sched/rtg/rtg.c b/kernel/sched/rtg/rtg.c index 168c6c3378b3..be95c1e816d5 100755 --- a/kernel/sched/rtg/rtg.c +++ b/kernel/sched/rtg/rtg.c @@ -6,6 +6,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include #undef CREATE_TRACE_POINTS @@ -722,7 +723,7 @@ int find_rtg_cpu(struct task_struct *p) if (is_reserved(i)) continue; - if (idle_cpu(i) || (i == task_cpu(p) && p->state == TASK_RUNNING)) { + if (idle_cpu(i) || (i == task_cpu(p) && p->__state == TASK_RUNNING)) { trace_find_rtg_cpu(p, preferred_cpus, "prefer_idle", i); return i; } @@ -738,7 +739,7 @@ int find_rtg_cpu(struct task_struct *p) continue; /* take the Active LB CPU as idle_backup_cpu */ - if (idle_cpu(i) || (i == task_cpu(p) && p->state == TASK_RUNNING)) { + if (idle_cpu(i) || (i == task_cpu(p) && p->__state == TASK_RUNNING)) { /* find the idle_backup_cpu with max capacity */ if (idle_backup_cpu == -1 || capacity_orig_of(i) > capacity_orig_of(idle_backup_cpu)) @@ -813,7 +814,7 @@ static inline bool valid_normalized_util(struct related_thread_group *grp) if (grp->nr_running != 0) { list_for_each_entry(p, &grp->tasks, grp_list) { get_task_struct(p); - if (p->state == TASK_RUNNING) + if (p->__state == TASK_RUNNING) cpumask_set_cpu(task_cpu(p), &rtg_cpus); trace_sched_rtg_task_each(grp->id, grp->nr_running, p); put_task_struct(p); @@ -1081,6 +1082,10 @@ static int __init create_default_coloc_group(void) unsigned long flags; grp = lookup_related_thread_group(DEFAULT_CGROUP_COLOC_ID); + if (!grp) { + pr_err("create_default_coloc_group fail\n"); + return -ENODEV; + } write_lock_irqsave(&related_thread_group_lock, flags); list_add(&grp->list, &active_related_thread_groups); write_unlock_irqrestore(&related_thread_group_lock, flags); @@ -1135,7 +1140,7 @@ static void print_rtg_info(struct seq_file *file, static char rtg_task_state_to_char(const struct task_struct *tsk) { static const char state_char[] = "RSDTtXZPI"; - unsigned int tsk_state = READ_ONCE(tsk->state); + unsigned int tsk_state = READ_ONCE(tsk->__state); unsigned int state = (tsk_state | tsk->exit_state) & TASK_REPORT; BUILD_BUG_ON_NOT_POWER_OF_2(TASK_REPORT_MAX); diff --git a/kernel/sched/rtg/rtg_ctrl.h b/kernel/sched/rtg/rtg_ctrl.h index 6fe3d9d399d9..5a5a4e5dd3b7 100755 --- a/kernel/sched/rtg/rtg_ctrl.h +++ b/kernel/sched/rtg/rtg_ctrl.h @@ -11,6 +11,7 @@ #include #include #include +#include #include "frame_rtg.h" diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 97b574c917db..5f15743fd815 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -84,6 +84,10 @@ # include #endif +#ifdef CONFIG_SCHED_RTG +#include +#endif + #ifdef CONFIG_PARAVIRT # include # include -- Gitee